// JavaScript Document
/* used to open image in a new window*/
function openIT(u,W,H, sc) {
		var x = (screen.width - W) / 2;
		var y = (screen.height - H) / 2;
		//window.moveBy(left, top);
		window.open(u, '',"width="+W+",height="+H+",scrollbars="+(sc ? "yes" : "no")+", left="+250+",top="+200);
}
function PopImage(img, caption)
{
	caption = escape(caption);
	openIT('pop_gl.htm?img='+img+"&caption="+caption,500,600);
}
function HideDivSMSChat(){
	window.parent.document.getElementById("aAddMsg").href='javascript:alert("Coming Soon")';
	}

/*function HideDivSMSChat(){
window.parent.document.getElementById("divSMSChat").style.display='none';

}*/

function ChangeMarqueeDirection(dir){
	//alert(document.getElementById("SMSMarquee"));
	document.getElementById("SMSMarquee").direction=dir;
}
		
function SubmitLogin(btn) {
	 // process only the Enter key 
	if (event.keyCode == 13) {
		 // cancel the default submit 
		 event.returnValue=false; 
		 event.cancel = true; 
		 // submit the form by programmatically clicking the specified button 
		 document.getElementById(btn).click();
	} 
}

function LoggedInAlert(){
alert("This account is already logged in")
}

//validate login
function CheckLogin(username, password){
	if (Trim(document.getElementById(username).value)=="" || Trim(document.getElementById(password).value)=="")
	 {
		 alert("Please enter your Username and your Password");
		 return false;
	}
	else
	{
	   return true;
	}
}

//validate Email
function IsValidEmail(txt){
    var stremail="";
	if(txt.value !=""){ 
		var goodEmail = txt.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (goodEmail){
		    return true;
		} else {
			stremail="- The Email address is not valid\n";
			return stremail;
		}
	}
}

//subscription plans
function CheckSubSelection(Count){
var radiochecked=false;
Count=Count+2
//alert(Count)
	for (i=2;i<Count;i++){
		//alert(i)
		//alert(document.getElementById("dgSubscription__ctl" + i + "_rdSubScription"))
	   if (document.getElementById("dgSubscription__ctl" + i + "_rdSubScription").checked==true) {
               radiochecked=true;
              }    
      }   
    
    if (radiochecked==false){
    alert("Please choose a plan");
    return false;
    }
      
}

 //subscription selection 
function ChangeSubSelection(Count, Index){
		Index=Index+2
		for (i=2;i<Count+2;i++){
		//alert(document.getElementById("dgSubscription__ctl" + i + "_rdSubScription"))
		document.getElementById("dgSubscription__ctl" + i + "_rdSubScription").checked=false;       
        document.getElementById("dgSubscription__ctl" + Index + "_rdSubScription").checked=true;
        }
}
//validate ForgotPassword form
function validateforgot()
{
	if (Trim(document.Form1.txtEmail.value)==""){
		alert("Please enter your email");
		return false;
	}
	else{
		var strvalmail=IsValidEmail(document.Form1.txtEmail);
	    if (strvalmail.length>0){
			alert("Please enter a valid email address");
			return false;
	     }
	     else
			return true;
		}
}
//validate sms chat
function ValidateSMS(){
	if (Trim(document.Form1.txtMessage.value)==""){
		alert("Please fill you message");
		return false;
		}
	else
	return true;
		

}
	
//validate prepaid cards
function ValidatePrepaidCards(SN, PIN){
	if (Trim(document.getElementById(SN).value)=="" || Trim(document.getElementById(PIN).value)=="")
	 {
		 alert("Please enter the Serial Number and the Pin Code");
		 return false;
	}
	else
	{
	   return true;
	}
	

}
//validate registration
function ValidateRegister()
{
	var msg="";
	var msg1="";
	if (Trim(document.Form1.txtUserName.value)=="")
		msg+="- User Name\n"
	if (Trim(document.Form1.txtPassword.value)=="")
		msg+="- Password\n"
	if (Trim(document.Form1.txtConfirm.value)=="")
		msg+="- Confirm Password\n"	
	if (Trim(document.Form1.txtPassword.value)!=Trim(document.Form1.txtConfirm.value))
	    msg1+="- New password and its confirmation do not match.\n"	
	if (Trim(document.Form1.txtFName.value)=="")
		msg+="- First Name\n"
	if (Trim(document.Form1.txtLName.value)=="")
		msg+="- Last Name\n"
		if (Trim(document.Form1.txtNickName.value)=="")
		msg+="- Nick Name\n"
	if (CheckGender()==false)
		msg+="- Gender\n"
	if (document.Form1.lstAge.selectedIndex==0)
		msg+="- Age Group\n"
	if (document.Form1.lstCountry.selectedIndex==0)
	   msg+="- Country\n"
	if (document.Form1.lstNationality.selectedIndex==0)
	   msg+="- Nationality\n"
	if (Trim(document.Form1.txtEmail.value)==""){
		msg+="- Email\n"
		}
    else{
		var strvalmail=IsValidEmail(document.Form1.txtEmail);
	    if (strvalmail.length>0)
	     msg1+=strvalmail
	    } 
	if (Trim(document.Form1.txtConfirmEmail.value)=="")
		msg+="- Confirm Email\n"
	if (Trim(document.Form1.txtEmail.value)!=Trim(document.Form1.txtConfirmEmail.value))
	    msg1="Email and its confirmation do not match.\n"	
	    	
	if (msg==""){
		if (msg1=="")
		   return true
        else
		{
			alert(msg1);
			return false;}
	}
	else{  
	   alert("The following fields are required,\n please be sure to fill them and try again:\n\n" + msg )
		return false;
		}
}
//edit profile
function ValidateEdit()
{
	var msg="";
	var msg1="";
	if (Trim(document.Form1.txtUserName.value)=="")
		msg+="- User Name\n"
	if (Trim(document.Form1.txtFName.value)=="")
		msg+="- First Name\n"
	if (Trim(document.Form1.txtLName.value)=="")
		msg+="- Last Name\n"
		if (Trim(document.Form1.txtNickName.value)=="")
		msg+="- Nick Name\n"
	if (CheckGender()==false)
		msg+="- Gender\n"
	if (document.Form1.lstAge.selectedIndex==0)
		msg+="- Age Group\n"
	if (document.Form1.lstCountry.selectedIndex==0)
	   msg+="- Country\n"
	if (document.Form1.lstNationality.selectedIndex==0)
	   msg+="- Nationality\n"
	if (Trim(document.Form1.txtEmail.value)==""){
		msg+="- Email\n"
		}
    else{
		var strvalmail=IsValidEmail(document.Form1.txtEmail);
	    if (strvalmail.length>0)
	     msg1+=strvalmail
	    } 
  	
	if (msg==""){
		if (msg1=="")
		   return true
        else
		{
			alert(msg1);
			return false;}
	}
	else{  
	   alert("The following fields are required,\n please be sure to fill them and try again:\n\n" + msg )
		return false;
		}
}
//validate gender radiobutton
function CheckGender(){
   var check=false;
   var i=0;
   
   for (i=0;i<document.Form1.rdGender.length;i++){
       if(document.Form1.rdGender[i].checked==true) 
       check=true
   } 
  
   if (check==false)
      return false;
   else
      return true;
}
//validate Poll
function Checkvote(btns, ItemsCount, lang)
{
	var i;
	var ItemChecked=false;
	i=0;
	for (i=0; i< ItemsCount;i++){
		if (document.getElementById(btns + "_" + i ).checked==true)
			ItemChecked=true
	}
	
	if (ItemChecked==true){
			return true;
	}
	else {
		alert("Please select an answer")
		return false;
	}
 }
 
 /*forum*/
function ValidateThread()
{   var msg="";
	if (Trim(document.Form1.txtTitle.value)=="")
		msg+="-Topic Title is required\n";
	if (Trim(document.Form1.txtDescription.value)=="")
		msg+="-Topic Description is required";	
	
	if (msg!="")
	    {alert(msg);
		return false;
		}
    else
		return true;
}

function ValidateSearch(){
	var msg="";
	if (Trim(document.getElementById("SearchForums1_txtKeyword").value)=="")
		msg+=" - Keyword is required\n";
    if (document.getElementById("SearchForums1_lstCategories").selectedIndex==0)
		msg+=" - Category is required";
	if (msg!="")
		{alert(msg);
		return false;
	}
	else
		return true;
}

function ValidatePost(){
	var msg="";
	if (Trim(document.getElementById("ControlForumPostDetails1_txtTitle").value)=="")
		msg+=" - Title is required\n";
    if (document.getElementById("radEditorContainerControlForumPostDetails1_RE").innerHTML=="")
		msg+=" - Message is required";
	if (msg!="")
		{alert(msg);
		return false;
	}
	else
		return true;
}
/* end forums*/
//vote
function ChangeVoteSelection(Count, Index){
		Index=Index
		Count=Count
		for (i=0;i<Count;i+=1){
		    if (!(document.getElementById("dlNominees__ctl" + i + "_rbtn1")==null))
                document.getElementById("dlNominees__ctl" + i + "_rbtn1").checked=false;   
		     else{
                if (!(document.getElementById("dlNominees__ctl" + i + "_rbtn2")==null))
                      document.getElementById("dlNominees__ctl" + i + "_rbtn2").checked=false;  
		     }
		  }
       /*  alert(document.getElementById("dlNominees__ctl" + Index + "_rbtn1"))
		 alert(document.getElementById("dlNominees__ctl" + Index + "_rbtn2"))*/
		if (!(document.getElementById("dlNominees__ctl" + Index + "_rbtn1")==null))
              document.getElementById("dlNominees__ctl" + Index + "_rbtn1").checked=true;
        else{
             if (!(document.getElementById("dlNominees__ctl" + Index + "_rbtn2")==null))
                   document.getElementById("dlNominees__ctl" + Index + "_rbtn2").checked=true;
		}
}

function CheckVoteSelection(Count){
	var radiochecked=false;
	for (i=0;i<Count;i++){
		if (!(document.getElementById("dlNominees__ctl" + i + "_rbtn1")==null)){
			//alert("dlNominees__ctl" + (i*2) + "_rbtn1")
	    	if (document.getElementById("dlNominees__ctl" + i + "_rbtn1").checked==true) {
            	radiochecked=true;
            }    
        }
       else{
		   if (!(document.getElementById("dlNominees__ctl" + i + "_rbtn2")==null)){
		   	//alert("dlNominees__ctl" + (i*2) + "_rbtn2")
       			if (document.getElementById("dlNominees__ctl" + i + "_rbtn2").checked==true) 
              		radiochecked=true;
           }	
       }
    }   
 if (radiochecked==false){
    alert("Please select an answer");
    return false;
    }
	else
	{return true;}
}
		
//Members area
function ValidateJoinMailing(){
	if (Trim(document.getElementById("ControlRightMenu1_ControlJoinMailing1_txtEmail").value)==""){
		alert("Please enter your email");
		return false;
	}
	else{
		var strvalmail=IsValidEmail(document.getElementById("ControlRightMenu1_ControlJoinMailing1_txtEmail"));
	    if (strvalmail.length>0){
			alert("Please enter a valid email address");
			return false;
	     }
	     else
			return true;
		}
	}
	
function CheckPassword(){
    if (Trim(document.Form1.txtOldpwd.value)=="" || Trim(document.Form1.txtNewPwd.value)=="" || Trim(document.Form1.txtConfirm.value)=="")
	{
		alert("The following fields are required:\n - Old Password \n - New Password \n - Confirm New Password");
	    return false;
	  }
	else{
		if (document.Form1.txtNewPwd.value!=document.Form1.txtConfirm.value){
			alert("New Password and Confirm New Password do not match");
			return false;
			}
		else{
			return true;
		}
	}
}
//Ecards

function PopPreview(EcardID){
	var FlashVars;
	var MemberPic;
	FlashVars=document.getElementById("txtFlashVars").value;
	MemberPic=document.getElementById("txtMemberPic").value;
	openIT('EcardPreview.aspx?ID=' + EcardID + "&FlashVars=" + FlashVars + "&MemberPic=" + MemberPic,730,630,true);
	}
	
function ValidateSendEcard(){
	var msg="";
	var msg1="";
	if (document.Form1.txtSenderName.value=="")
		msg+="- Sender Name is required\n";
	if (document.Form1.txtSenderEmail.value=="")
		msg+="- Sender Email is required\n";
	else{
		var strvalmail=IsValidEmail(document.Form1.txtSenderEmail);
	    if (strvalmail.length>0)
			msg1+="Please enter a valid Sender Email Address\n";
	}
	if (document.Form1.txtReceiverName.value=="")
		msg+="- Receiver Name is required\n";
	if (document.Form1.txtReceiverEmail.value=="")
		msg+="- Receiver Email is required\n";
	else{
		var strvalmail=IsValidEmail(document.Form1.txtReceiverEmail);
	    if (strvalmail.length>0)
			msg1+="Please enter a valid Receiver Email Address\n";
		}
	if (document.Form1.txtReceiverName2.value!="" && document.Form1.txtReceiverEmail2.value=="")
		msg+="- Receiver 2 Email is required\n";
	if (document.Form1.txtReceiverName2.value=="" && document.Form1.txtReceiverEmail2.value!="")
		msg+="- Receiver 2 Name is required\n";
	if (document.Form1.txtReceiverName3.value!="" && document.Form1.txtReceiverEmail3.value=="")
		msg+="- Receiver 3 Email is required\n";
	if (document.Form1.txtReceiverName3.value=="" && document.Form1.txtReceiverEmail3.value!="")
		msg+="- Receiver 3 Name is required\n";
	if (document.Form1.txtReceiverName4.value!="" && document.Form1.txtReceiverEmail4.value=="")
		msg+="- Receiver 4 Email is required\n";
	if (document.Form1.txtReceiverName4.value=="" && document.Form1.txtReceiverEmail4.value!="")
		msg+="- Receiver 4 Name is required\n";
	if (document.Form1.txtReceiverEmail2.value!=""){
		var strvalmail=IsValidEmail(document.Form1.txtReceiverEmail2);
	    if (strvalmail.length>0)
			msg1+="Please enter a valid Receiver 2 Email Address\n";
		}
	if (document.Form1.txtReceiverEmail3.value!=""){
		var strvalmail=IsValidEmail(document.Form1.txtReceiverEmail3);
	    if (strvalmail.length>0)
			msg1+="Please enter a valid Receiver 3 Email Address\n";
		}
	if (document.Form1.txtReceiverEmail4.value!=""){
		var strvalmail=IsValidEmail(document.Form1.txtReceiverEmail4);
	    if (strvalmail.length>0)
			msg1+="Please enter a valid Receiver 4 Email Address\n";
	}
		
	
	if (msg==""){
		if (msg1=="")
			return true;
		else{
			alert(msg1);
			return false;}
	}	
	else{
		alert(msg);
		return false;}

		
}

function ValidateCompetition(){
	var msg="";
	var msg1="";
	if (Trim(document.Form1.txtEmail1.value)=="")
		msg+="- Email1\n"
	if (Trim(document.Form1.txtEmail2.value)=="")
		msg+="- Email2\n"
	if (Trim(document.Form1.txtEmail3.value)=="")
		msg+="- Email3\n"
	if (Trim(document.Form1.txtEmail4.value)=="")
		msg+="- Email4\n"
	
	if (msg==""){
	    var strvalmail1=IsValidEmail(document.Form1.txtEmail1);
	    if (strvalmail1.length>0)
	    msg1 +="Email 1 is not a valid Email address\n"
	    var strvalmail2=IsValidEmail(document.Form1.txtEmail2);
	    if (strvalmail2.length>0)
	    msg1 +="Email 2 is not a valid Email address\n"
	    var strvalmail3=IsValidEmail(document.Form1.txtEmail3);
	    if (strvalmail3.length>0)
	    msg1 +="Email 3 is not a valid Email address\n"
	    var strvalmail4=IsValidEmail(document.Form1.txtEmail4);
	    if (strvalmail4.length>0)
	    msg1 +="Email 4 is not a valid Email address\n"
		if ((document.Form1.txtEmail1.value==document.Form1.txtEmail2.value) || (document.Form1.txtEmail1.value==document.Form1.txtEmail3.value) || (document.Form1.txtEmail1.value==document.Form1.txtEmail4.value) ||(document.Form1.txtEmail2.value==document.Form1.txtEmail3.value) || (document.Form1.txtEmail2.value==document.Form1.txtEmail4.value) || (document.Form1.txtEmail3.value==document.Form1.txtEmail4.value))
	    msg1 +="Please enter 4 distinct emails\n"
	}
	 if (msg==""){
		if (msg1=="")
		   return true
        else{
		 alert(msg1);
		 return false;}
	}
	else{  
	   alert("The following fields are required,\n please be sure to fill them and try again:\n" + msg )
		return false;
		}
	
}

 //TRIM Functions
function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function
