	var hostname="http://www.sivajitv.com/";
	 var html="";

	 function openYouTube()
	 {
	 	window.open('http://www.youtube.com/signup?next=my_account',
 		'open_window',
 		'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent,left=0, top=0')				
	 }
	
	 function checkImageFormat(imageName)
	 {
	 	var mess="Please  upload [jpg,gif,png,tif&bmp] format images only ";
	 	imgArray= new Array("JPEG","JPG","jpg","jpeg","GIF","gif","PNG","png","TIFF","TIF","tif","tiff","bmp","BMP")
	  	var imageType=imageName.split('.');	  
	 	for(i=0;i<imgArray.length;i++)
	 	{		 		
	 		if(imageType[1]==imgArray[i])
	 		{
	 			mess="";
	 			break;
	 		}
	 	}
	 	return mess;
	 }
	 
	  function checkFileFormat(fileName)
	  {
	 	var mess="Please  upload [doc,txt,rtf] format  only ";
	 	fileArray= new Array("doc","rtf","txt");
	  	var fileType=fileName.split('.');	  
	 	for(i=0;i<fileArray.length;i++)
	 	{				 		
	 		if(fileType[1]==fileArray[i])
	 		{
	 			mess="";
	 			break;
	 		}
	 	}	 	
	 	return mess;
	 }
	 
	 function getXmlHttpRequestObject() {
       if (window.XMLHttpRequest) {
           return new XMLHttpRequest();
       } else if (window.ActiveXObject) {
           isIE = true;
           return new ActiveXObject("Microsoft.XMLHTTP");
       }
  	 }
	
	var mystagesReq = getXmlHttpRequestObject();
	
	function changeSubItemType(typeId)
	{
		if (mystagesReq.readyState == 4 || mystagesReq.readyState == 0) 
		{
			//var id = document.getElementById("itemTypeId").value;	
			if(typeId!=0)
			{							
				mystagesReq.open("GET", 'http://www.sivajitv.com/servlet/MyStagesSubItem?id='+typeId, true);
				mystagesReq.onreadystatechange = handleChangeSubItemType; 			
				mystagesReq.send(null);				
			}
		}		
	}
	
	function handleChangeSubItemType()
	{
		 if (mystagesReq.readyState == 4) 
		 {
		 	 if (mystagesReq.status == 200) 
		 	 {		 	 		
 				html=setSubType(mystagesReq.responseXML); 		
 			 }
		 }
	}
	
	function setSubType(responseXML)
	{
		var subTypes = responseXML.getElementsByTagName("subTypes")[0];		
		html="<select  name=\"itemSubTypeId\" id=\"itemSubTypeId\" >";									
       	if (subTypes.childNodes.length > 0)
       	{          
     		for (loop = 0; loop < subTypes.childNodes.length; loop++) 
     		{
           		var subType = subTypes.childNodes[loop];
           		var id = subType.getElementsByTagName("id")[0];
           		var typeName = subType.getElementsByTagName("typeName")[0];
           		html+="<option value="+id .childNodes[0].nodeValue+">"+typeName .childNodes[0].nodeValue+"</option>";           		
         	}
         	html+="</select>";
       		//alert("html="+html);     
       	
         	document.getElementById("subType").innerHTML = html;         	
         }            
	}	
	
	function updateRating(id,type)
	{	
		if (mystagesReq.readyState == 4 || mystagesReq.readyState == 0) 
		{
			mystagesReq.open("GET", 'http://www.sivajitv.com/servlet/MyStagesRating?id='+id+"&type="+type, true);
			mystagesReq.onreadystatechange = function(){
			 	if (mystagesReq.readyState == 4) 
			 	{
					setRating(mystagesReq.responseXML);
			 	}
			}; 			
			mystagesReq.send(null);			
		}			
	}
	
	function setRating(responseXML)
	{
		var rate = responseXML.getElementsByTagName("rating")[0];
		mess=rate.getElementsByTagName("message")[0].childNodes[0].nodeValue;
		//alert(mess);
		if(mess=="success")
		{
			document.getElementById("up").innerHTML= rate.getElementsByTagName("thumbsup")[0].childNodes[0].nodeValue;
			document.getElementById("down").innerHTML=rate.getElementsByTagName("thumbsdown")[0].childNodes[0].nodeValue;					
			document.getElementById("result").innerHTML = "<div style=\"color:red;\" class=\"lastweekbackcolor\"><b>&nbsp;&nbsp;&nbsp;Rated Successfully</b></ div>";					
		}		
		else
		{
			document.getElementById("result").innerHTML = "<div style=\"color:red;\" class=\"lastweekbackcolor\"><b>&nbsp;&nbsp;&nbsp;Rated Failure</b></ div>";					
		}
		document.getElementById("result").style.display="inline";
	}	
	
	function changeLanguage()
    {   		
    	var theForm = this.document.UserForm;	
    	var lang=theForm.language.value;  
    		
    	var tamil="<li><label class=\"labels\"><span class=\"redcolor\"></span></label><div class=\"redcolor\">";
			tamil+="<font style=\"color:red\">If your article is in Tamil, please make sure it is typed in ";
			tamil+="Unicode Font.</font></div></li>";
    		tamil+="<li><label class=\"labels\">Title<span class=\"redcolor\">*</span></label>";
			tamil+="<span><input type=\"text\" name=\"itemTitle\" id=\"itemTitle\" size=\"32\" onKeyPress=\"javascript:convertThis(event)\"/></span></li>";
			tamil+="<div class=\"clr\"></div>";
			tamil+="<li><label class=\"labels\">Submit Text<span class=\"redcolor\">*</span></label>";									
			tamil+='<span><textarea name="description" id="description" class="textarea_abt_me1" style="_width:250px" onKeyPress="javascript:convertThis(event)"></textarea></<span></li>';
			tamil+="<div class=\"clr\"></div><li><label class=\"labels\">Upload file</label><span><input type=\"file\" id=\"uploadFile\" name=\"uploadFile\" size=\"35\"/></span><br />";
			tamil+="<span class=\"redcolor\" style=\"padding-left:110px\">Upload .doc, .txt or .pdf file.</span></li>"
			tamil+="<div class=\"clr\"></div><li><label class=\"labels\">About The Talent<span class=\"redcolor\">*</span></label>";
			tamil+="<span><textarea name=\"aboutTalent\"  id=\"aboutTalent\" class=\"textarea_abt_me\" style=\"_width:250px\"  onKeyPress=\"javascript:convertThis(event)\"></textarea></span></li>";
			tamil+="<div class=\"clr\"></div>";
			
		var english="<li><label class=\"labels\">Title<span class=\"redcolor\">*</span></label>";
			english+="<span><input type=\"text\" name=\"itemTitle\" id=\"itemTitle\" size=\"32\" /></span></li>";
			english+="<div class=\"clr\"></div>";
			english+="<li><label class=\"labels\">Submit Text<span class=\"redcolor\">*</span></label>";									
			english+='<span><textarea name="description" id="description" style="_width:250px" class="textarea_abt_me1" ></textarea></<span></li>';
			english+="<div class=\"clr\"></div><li><label class=\"labels\">Upload file</label><span><input type=\"file\" id=\"uploadFile\" name=\"uploadFile\" size=\"35\"/></span><br />";
			english+="<span class=\"redcolor\" style=\"padding-left:110px\">Upload .doc, .txt or .pdf file.</span></li>";
			english+="<div class=\"clr\"></div><li><label class=\"labels\">About The Talent<span class=\"redcolor\">*</span></label>";
			english+="<span><textarea name=\"aboutTalent\" id=\"aboutTalent\" class=\"textarea_abt_me\" style=\"_width:250px\"></textarea></span></li>";
			english+="<div class=\"clr\"></div>";
			
    	if(lang==2)
    	{
    		document.getElementById("english").innerHTML=tamil;    					
    	}
    	else
    	{
    		document.getElementById("english").innerHTML=english;  
    	}    	
    }
   var mystagesText = getXmlHttpRequestObject();
   function changeTalentType() 
   {
   		var id = document.getElementById("itemTypeId").value;
   	
   		if(id==1)	
   		{   		
	   		changeSubItemType(id);	   			
	   		setTimeout('changeVideoTalent()',1000);
	   	}
	   	else if(id==2)
	   	{
	   		//changeSubItemType(id);	 
	   		//setTimeout('changeTextTalent()',1000);  	
	   		mystagesText.open("GET", 'servlet/MyStagesSubItem?id='+id, true);
			mystagesText.onreadystatechange =handleChangeTextTalent;		
			mystagesText.send(null);	   	
	   	}   		
   }
      
    function handleChangeTextTalent()
	{
		 if (mystagesText.readyState == 4) 
		 {
		 	 if (mystagesText.status == 200) 
		 	 {	
 				changeTextTalent(mystagesText.responseXML);		
 			 }
		 }
	}
	
   function changeVideoTalent() 
   {   		   		
   		document.getElementById('videoTalent').innerHTML="";
  	 	var p=document.getElementById('videoTalent');
  	 	var ulholder = document.createElement('ul');
   			   		
   		var vTalent="<li><label class=\"labels\">Category<span class=\"redcolor\">*</span></label><span id=\"subType\">";
   		vTalent+=html+"</span></li><div class=\"clr\"></div>";
   		vTalent+="<li><label class=\"labels\">Title<span class=\"redcolor\">*</span></label>";
		vTalent+="<span><input type=\"text\" id=\"itemTitle\" name=\"itemTitle\"  size=32px;\" /></span></li>";
		vTalent+="<div class=\"clr\"></div>";
		vTalent+="<li><label class=\"labels\">About The Video</label>"
		vTalent+="<span><textarea class=\"textarea_abt_me\" style=\"_width:250px\" name=\"description\" id=\"description\"></textarea></span></li></div>";
		vTalent+="<div class=\"clr\"></div><li><label class=\"labels\">YouTube URL<span class=\"redcolor\">*</span></label>"
		vTalent+="<span><input id=\"link\" type=\"text\" name=\"link\" size=\"32\" /></span>";
		vTalent+="<br /><span class=\"redcolor\" style=\"padding-left:110px\">";
		vTalent+="<a href=\"javascript:openYouTube();\">How To Upload Video In YouTube</a></span></li>";
		vTalent+="<div style=\"border:#000 0px solid;  margin-left:auto;\">";
		vTalent+="<b>Note: Your talent will be approved ONLY if your submission in YouTube STRICTLY ";
		vTalent+="follows the below format in the \"YouTube title\" - <br/>";
		vTalent+="YouTube Title Format: \"SIVAJI TV MY STAGE Your Name Uploaded Date\"<br/>";
		vTalent+="Example: \"SIVAJI TV MY STAGE Kumar 10 May 09\"</b><br/>";
		vTalent+=" If you have more than one video talent uploaded in YouTube, name them as follows -";
		vTalent+=" YouTube Title Format: \"SIVAJI TV MY STAGE Your Name UploadDate Video 1/n \"<br/>";
		vTalent+=" Example: \"SIVAJI TV MY STAGE Kumar 10May09 Video 1/4, 2/4.......4/4 \"<br/>";
		vTalent+="Please note that only good quality videos will be accepted.<br/><br/></div>";
		vTalent+="<div class=\"clr\">";
		vTalent+="<div class=\"clr\"></div>";
		vTalent+="<li><label class=\"labels\">&nbsp;</label>";
		vTalent+="<span><input type=\"button\" Class=\"buttons\" value=\"Preview\" onclick=\"javscript:preview();\"/></span>&nbsp;";
		vTalent+="<span><input type=\"submit\" Class=\"buttons\"  value=\"Submit\"/></span></li>";
	 	//alert( vTalent);	 	
	 	ulholder.innerHTML= vTalent;  
	 	p.appendChild(ulholder);			
   }
    
     function changeTextTalent(responseXML) 
   	 {
   	 	document.getElementById('videoTalent').innerHTML="";   	 
   		var subTypes = responseXML.getElementsByTagName("subTypes")[0];		
		html="<select  name=\"itemSubTypeId\" id=\"itemSubTypeId\" >";									
       	if (subTypes.childNodes.length > 0)
       	{          
     		for (loop = 0; loop < subTypes.childNodes.length; loop++) 
     		{
           		var subType = subTypes.childNodes[loop];
           		var id = subType.getElementsByTagName("id")[0];
           		var typeName = subType.getElementsByTagName("typeName")[0];
           		html+="<option value="+id .childNodes[0].nodeValue+">"+typeName .childNodes[0].nodeValue+"</option>";           		
         	}
         	html+="</select>";                	
         }            
   		var p=document.getElementById('videoTalent');
  	 	var ulholder = document.createElement('ul');
  	 		
   		var vTalent="<li><label class=\"labels\">Category<span class=\"redcolor\">*</span></label><span>";
   		vTalent+=html+"</span></li><div class=\"clr\"></div>";
   		vTalent+=" <div class=\"clr\"></div><li><label class=\"labels\">Language<span class=\"redcolor\">*</span></label>";
		vTalent+="<span ><select   name=\"language\" id=\"language\" onChange=\"changeLanguage();\" \>";
		vTalent+="<option value=\"0\">Please Select Your Language</option>";
		vTalent+="<option value=\"1\">English</option><option value=\"2\">Tamil</option>";
  		vTalent+="</select></span></li>	";
   		vTalent+="<div id=\"english\"><li><label class=\"labels\">Title<span class=\"redcolor\">*</span></label>";
   		vTalent+="<span><input type=\"text\" name=\"itemTitle\" id=\"itemTitle\" size=32px;\"/></span></li>";
   		vTalent+="<div class=\"clr\"></div>";
   		vTalent+="<li><label class=\"labels\">Submit Text<span class=\"redcolor\">*</span></label>";									
		vTalent+='<span><textarea name="description" id="description" style="_width:250px" class="textarea_abt_me1" ></textarea></<span></li>';
		vTalent+="<div class=\"clr\"></div><li><label class=\"labels\">Upload file</label><span><input type=\"file\" id=\"uploadFile\" name=\"uploadFile\" size=\"35\"/></span><br />";
		vTalent+="<span class=\"redcolor\" style=\"padding-left:110px\">Upload .doc, .txt or .pdf file.</span></li>"
		vTalent+="<div class=\"clr\"></div><li><label class=\"labels\">About The Talent<span class=\"redcolor\">*</span></label><span><textarea name=\"aboutTalent\" id=\"aboutTalent\" class=\"textarea_abt_me\" style=\"_width:250px\"></textarea></span></li>";
		vTalent+="</div><div class=\"clr\"></div>";
		vTalent+="<li><label class=\"labels\">&nbsp;</label>";
	 	//vTalent+="<span><input type=\"button\" Class=\"buttons\" value=\"Preview\" onclick=\"javscript:preview();\"/></span>&nbsp;";
	 	vTalent+="<span><input type=\"submit\" Class=\"buttons\" value=\"Submit\"/></span></li>";
	 	//alert(html);	 	
	 	ulholder.innerHTML= vTalent;  
	 	p.appendChild(ulholder);	 			
  	 }    
    
    function  validateMystagesLoginDetails()
	{		
		var error="";		
		var theForm = this.document.UserForm;		
		var email=theForm.emailId.value;
		var pwd=theForm.password.value;
		
		if( email.length==0)
		{
			error+="Please enter a email address \n";
			document.getElementById("emailId").focus();
		}	
		if(email.length!=0)
		{
			 if (! isValidEmail(email)) {
      	 		error+="Please enter a valid email address \n"; 
      	 		document.getElementById("emailId").focus();    			  
    		 }
    		 else
    		 {
    			 document.getElementById("password").focus();
    		 }
    		 
		}		
		if(pwd.length==0)
		{
			error+="Please enter a password \n";
			
		}	
							
		if(error.length!=0)
		{
			alert(error);
			return false;
		}
		else
		{
			return true;
		}		
	}
	
 	 function validateMystagesAccountDetails()
	{		
		var error="";		
		var theForm = this.document.UserForm;		
		var email=theForm.emailId.value;
		var pwd=theForm.password.value;
		var fname=theForm.firstName.value;		
		var lname=theForm.lastName.value		
		var cntry=theForm.country.value;
		var state=theForm.state.value;
		var city=theForm.city.value;	
		if( email.length==0)
		{
			error+="Please enter your email address \n";
		}	
		if(email.length!=0)
		{
			 if (! isValidEmail(email)) {
      	 		error+="Please enter a valid email address \n";     			  
    		 }
		}		
		if(pwd.length==0||!isNaN(pwd))
		{
			error+="Please enter the password \n";
		}	
		if(fname.length==0 ||!isNaN(fname))
		{
			error+="Please enter your first name \n";
		}					
		if(lname.length==0||!isNaN(lname))
		{
			error+="Please enter your last name \n";
		}			
		if(city.length==0||!isNaN(city))
		{
			error+="Please enter your city \n";
		}
		if(state.length==0||!isNaN(state))
		{
			error+="Please enter your state \n";
		}	
		if(cntry.length==0)
		{
			error+="Please enter your country \n";
		}					
		if(error.length!=0)
		{
			alert(error);
			return false;
		}
		else
		{
			return true;
		}		
	}	
	
	function  validateMystagesPersonalDetails()
	{				
		var error="";		
		var theForm = this.document.UserForm;
		var age=theForm.age.value;	
		var addr=theForm.address.value;			
		var cityCode=theForm.cityCode.value;		
		var cntrycode=theForm.countryCode.value;
		var cntrycode1=theForm.countryCode1.value;
		var ph=theForm.phoneNo.value;
		var mob=theForm.mobileNo.value;
		var pho=theForm.photo.value;
		var about=theForm.aboutMe.value;	
		if(age.length==0)
		{
			error+="Please enter your Age \n";
		}			
		if(cntrycode.length==0  ||cntrycode1.length==0)
		{
			error+="Please enter your Country Code \n";
		}	
		if(cityCode.length==0)
		{
			error+="Please enter your City Code \n";
		}			
		if(ph.length==0)
		{
			error+="Please enter your Phone Number \n";
		}
		if(mob.length==0)
		{
			error+="Please enter your Mobile Number \n";
		}	
		if(ph.length!=0 ||cntrycode.length!=0 || cntrycode1.length!=0 || cityCode.length!=0 || mob.length!=0)
		{
			if(isNaN(ph) || isNaN(cntrycode)|| isNaN(cntrycode1)|| isNaN(cityCode)|| isNaN(mob))
			{
				error+="Special characters are not allowed in the Phone Number field\n";
			}
		}
		if(pho.length>2)
		{	
			var format= checkImageFormat(pho);			
			if(format.length!=0)
			{
				error+=format+"\n";
			}
		}						
		if(error.length!=0)
		{
			alert(error);
			return false;
		}
		else
		{
			return true;
		}		
	}
	
	function  validateYouTubeDetails()
	{			
		var error="";
		var theForm = this.document.UserForm;			
		var typeid=theForm.itemTypeId.value;

		var subid=document.getElementById('itemSubTypeId').value;
		 title=document.getElementById('itemTitle').value;	
		var desc=document.getElementById('description').value;
		if(subid==0)
		{
			error+="Please select Category \n";
		}
		if(title.length==0)
		{
			error+="Please enter a Title \n";
		}
		if(desc==0)
		{
			error+="Please enter a Description \n";
		}
		
		if(typeid==1)
		{	
			var url=document.getElementById('link').value;
			if(url.length<40)
			{
				error+="Please enter YouTube Url \n";
			}
		}
		else
		{		
			var abt=document.getElementById('aboutTalent').value;
			var upfile=document.getElementById('uploadFile').value;
			if(upfile.length>2)
			{				
				var format= checkFileFormat(upfile);
				if(format.length!=0)
				{
					error+=format+"\n";
				}				
			}
			if(abt.length==0)
			{
				error+="Please enter a Talent \n";
			}			
		}		
		if(error.length!=0)
		{
			alert(error);
			return false;
		}
		else
		{
			return true;
		}		
	}
	
	function showDiv(showid)
	{
		document.getElementById(showid).style.display="inline";
	}
	function hideDiv(hideid)
	{		  		   		
   		document.getElementById(hideid).style.display="none";		
	}
	
	function sendPassword()
	{	
		id=document.getElementById('forgetId').value;
		if(id.length!=0)
		{
			if (! isValidEmail(id))
			 {
      	 		alert("Please enter a valid email address ");     			  
    		 }
    		 else
    		 {
			    mystagesReq.open("GET", 'servlet/SendPassword?emailId='+id, true);
				mystagesReq.onreadystatechange = handleSendPassword; 			
				mystagesReq.send(null);				
			}
		}
		else
		{
			alert("Please enter your email Id");
		}
   	}
   	
	function handleSendPassword()
	{
		 if (mystagesReq.readyState == 4) 
		 {
		 	 if (mystagesReq.status == 200) 
		 	 {		 	 		
 				setSendPasswordMessage(mystagesReq.responseXML); 				
		     }
		 }
	}
	
	function setSendPasswordMessage(responseXML)
	{
		var mess= responseXML.getElementsByTagName("message")[0].childNodes[0].nodeValue;
		if(mess=="success")
		{
			success="<div align=\"left\" class=\"forms\" ><div class=\"selectedtalents_thanks\"><br><p>";
			success+="Your password will be sent to your email id. If you still have difficulties in signing in, kindly email mail@sivajitv.com";
			success+="<br><br>Thanks!<br><br>My Stage Admin</p>	</div></div>";
			hideDiv('forget');
			hideDiv('login');
			document.getElementById('forgotSuccess').innerHTML=success;			
		}
		else
		{
			alert("No account for this email id");			
		}
	}		
	
	
	/*  --   Mystaage forget Page  ---      */
	
	function mystage_forget_back()
	{
		hideDiv('forget');
		showDiv('login');
	}
	
	function myStageForgethtml() 
    {   
    	hideDiv('login');	
		showDiv('forget');		
    }