// JavaScript Document
function isDigit(theVal)
{
 theValLen=theVal.length
 for(var i=0;i<theValLen;i++)
 {
  thechar=theVal.substring(i,i+1)
  if (thechar< "0" || thechar >"9")
  {
   return false 
  } 
 }
 return true
}
//registation form vaildations here

function user_validate()
{

 if(document.frm.ucounty.value=="0") 
 {
 	alert("please select country");
	document.frm.ucounty.focus();
 } 
 else if(document.frm.umobile.value=="" && document.frm.sendcode.value=="") 
 {
 	alert("please enter the either mobile no or sender id value");
	
 }   
 else if(document.frm.uemail.value=="") 
 {
 	alert("please enter the value");
	document.frm.uemail.focus();
 }
 else
 {
 	document.frm.action="adduserfinal.asp";
	document.frm.submit();	
 }
}

function frm_package()
{
	var flg=0;
	var myid;
	leng=document.frm.pack_id.length;

	for(i=0;i<leng;i++)
	{
		if(document.frm.pack_id[i].checked==true)
		{
			flg=1;
			myid=document.frm.pack_id[i].value;
			
		}
	}
	if(document.frm.pack_id.checked==true)
	{
		flg=1;
		myid=document.frm.pack_id.value;
	}
	
	if(flg==1)
	{
		if(myid==1)
		{
			document.frm.action="reg_form.asp";
			document.frm.submit();		
		}
		else
		{			
			document.frm.action="reg_form_others.asp?reg_type_id="+myid;
			document.frm.submit();		
		}
	}

	else
	{
		alert("Please Select Registration type");
		return false;
	}
}


function frm_validate()
{
	
 lens1=document.frm.logname.value;
 lens2=document.frm.upass.value;
 lens3=document.frm.upass2.value;			
	
 if(document.frm.logname.value=="") 
 {
	alert("please enter the login name");
	document.frm.logname.focus();
 }
 else if ((lens1.length)<=3)
 {
 	alert("please enter more then 3 characters");
	document.frm.logname.focus();
 }
 else if(document.frm.upass.value=="") 
 {
 	alert("please enter the password");
	document.frm.upass.focus();
 }
 else if ((lens2.length)<=3)
 {
 	alert("please enter more then 3 characters");
	document.frm.upass.focus();
 }
 else if(document.frm.upass2.value=="") 
 {
 	alert("please enter the value");
	document.frm.upass2.focus();
 }
 else if ((lens3.length)<=3)
 {
 	alert("please enter more then 3 characters");
	document.frm.upass2.focus();
 } 
 else if(document.frm.upass2.value!=document.frm.upass.value) 
 {
 	alert("Please enter the both passwords same");
	document.frm.upass.focus();
 } 
 else if(document.frm.uname.value=="") 
 {
 	alert("please enter the name");
	document.frm.uname.focus();
 } 
 else if(document.frm.ulname.value=="") 
 {
 	alert("please enter the last name");
	document.frm.ulname.focus();
 }  
 else if(document.frm.umobile.value=="") 
 {
 	alert("please enter the mobile");
	document.frm.umobile.focus();
 }   
 else if(document.frm.uemail.value=="") 
 {
 	alert("please enter the email");
	document.frm.uemail.focus();
 }    
 else if(document.frm.ucomp.value=="") 
 {
 	alert("please enter the company");
	document.frm.ucomp.focus();
 }     
 else if(document.frm.uaddrs.value=="") 
 {
 	alert("please enter the address");
	document.frm.uaddrs.focus();
 }  
 else if(document.frm.ucity.value=="") 
 {
 	alert("please enter the city");
	document.frm.ucity.focus();
 }  
 else if(document.frm.ucounty.value=="0") 
 {
 	alert("please select country");
	document.frm.ucounty.focus();
 }  
 else if(document.frm.uagree.checked==false) 
 {
 	alert("please agree to the Terms & Conditions");
	document.frm.uagree.focus();
 }
 else if(document.frm.sender_id.value == "")
 {
   alert("please enter the sender id");
   document.frm.sender_id.focus();
 } 
 else if(document.frm.sender_id.value.length <3)
 {
  alert("please enter atleast 3 characters")
  document.frm.sender_id.focus();
 }
 else if(document.frm.sender_id.value!="" && isDigit(document.frm.sender_id.value))
{
  alert("Invalid SenderID, Atleast one character is required");
  document.frm.sender_id.focus(); 
  //return false;
}
 else
 {
 	document.frm.action="reg_add.asp";
	document.frm.submit();	
 }

}


function frm_validate_others()
{
	
 lens1=document.frm.logname.value;
 lens2=document.frm.upass.value;
 lens3=document.frm.upass2.value;			
 lens4=document.frm.sender_id.value;
 regtype=document.frm.reg_type_id.value;
 
 if(document.frm.logname.value=="") 
 {
	alert("please enter the login name");
	document.frm.logname.focus();
 }
 else if ((lens1.length)<=3)
 {
 	alert("please enter more than 3 characters");
	document.frm.logname.focus();
 }
 else if(document.frm.upass.value=="") 
 {
 	alert("please enter the password");
	document.frm.upass.focus();
 }
 else if ((lens2.length)<=3)
 {
 	alert("please enter more then 3 characters");
	document.frm.upass.focus();
 }
 else if(document.frm.upass2.value=="") 
 {
 	alert("please enter the password");
	document.frm.upass2.focus();
 }
 else if ((lens3.length)<=3)
 {
 	alert("please enter more then 3 characters");
	document.frm.upass2.focus();
 } 
 else if(document.frm.upass2.value!=document.frm.upass.value) 
 {
 	alert("Please enter the both passwords same");
	document.frm.upass.focus();
 } 
 else if(document.frm.uname.value=="") 
 {
 	alert("please enter the name");
	document.frm.uname.focus();
 } 
 else if(document.frm.ulname.value=="") 
 {
 	alert("please enter the last name");
	document.frm.ulname.focus();
 }  
 else if(document.frm.umobile.value=="") 
 {
 	alert("please enter the mobile");
	document.frm.umobile.focus();
 }   
 else if(document.frm.uemail.value=="") 
 {
 	alert("please enter the email");
	document.frm.uemail.focus();
 }    
 else if(document.frm.ucomp.value=="") 
 {
 	alert("please enter the company name");
	document.frm.ucomp.focus();
 }     
 else if(document.frm.uaddrs.value=="") 
 {
 	alert("please enter the address");
	document.frm.uaddrs.focus();
 }  
 else if(document.frm.ucity.value=="") 
 {
 	alert("please enter the city");
	document.frm.ucity.focus();
 }  
 else if(document.frm.ufax.value=="") 
 {
 	alert("please enter the fax");
	document.frm.ufax.focus();
 }  
 else if(document.frm.ucounty.value=="0") 
 {
 	alert("please select country");
	document.frm.ucounty.focus();
 }  
 else if(document.frm.uphone1.value=="") 
 {
 	alert("please enter the phone no.");
	document.frm.uphone1.focus();
 }  
 else if(document.frm.uagree.checked==false) 
 {
 	alert("please agree to the Terms & Conditions");
	document.frm.uagree.focus();
 }
  else if(regtype=="2" && document.frm.uagree1.checked==false) 
 {
 	alert("Please agree to the Affiliate Terms & Conditions");
	document.frm.uagree1.focus();
 }
  else if(document.frm.sender_id.value!="" && isDigit(document.frm.sender_id.value))
{
  alert("Invalid SenderID, Atleast one character is required");
  document.frm.sender_id.focus(); 
  //return false;
}
 else if ((lens4.length)<3)
 {
 	alert("Please enter atleast 3 characters for sender id");
	document.frm.sender_id.focus();
 }
 else
 {
 	document.frm.action="reg_add_others.asp";
	document.frm.submit();	
 }

}

//validation for login page
function frm_validate2(qut_id)
{

 if(document.frm.logname.value=="") 
 {
	alert("please enter the login name");
	document.frm.logname.focus();
 }
 else if(document.frm.upass.value=="") 
 {
 	alert("please enter the password");
	document.frm.upass.focus();
 }
 else
 {
 	document.frm.action="loginchk.asp?qut_id="+qut_id;
	document.frm.submit();	
 }
}
// validatoion phonebook

function addphbook() 
{
 var a=document.frm.ph_no.value;
 if(document.frm.ph_name.value=="") 
 {
	alert("Please enter the name");
	document.frm.ph_name.focus();
 }
 /*else if(document.frm.ucounty.value==0)
 {
 	alert("Country must be selected");
	document.frm.ucounty.focus();
 }*/
 else if(document.frm.ph_no.value=="") 
 {
 	alert("Please enter the phone no.");
	document.frm.ph_no.focus();
 }
 else if(a.substr(0,2)=="00" || a.substr(0,1)=="+") 
 {
 	alert("Phone no. should not begin with + or 00");
	document.frm.ph_no.focus();
 }
 else
 {
 	document.frm.action="phonebook_add.asp";
	document.frm.submit(); 
			
 }	
}

// validatoion phonebook

function delphbook() 
{
	var cnt;
        cnt=0
		var tot
		tot = parseInt(document.frm.pbook_id.length)
		
		for(i=0;i<tot;i++)
		{
 		      if(document.frm.pbook_id[i].checked)
		      {
		        cnt=1;
		      }
		}//end of for

        if (cnt==-1)
        {
          alert(" Select Contact Name to Delete")
          return false;
        }

        if (!confirm("Are you sure you want to delete")==1)
		{
			return false;
		}
		else
		{
			document.frm.action="del_phonebook.asp";
			document.frm.submit();
		}
}

// validatoion phone_group

function addgroup() 
{
 if(document.frm.ph_name.value=="") 
 {
	alert("please enter the name");
	document.frm.ph_name.focus();
 }
 else
 {
 	document.frm.action="phonegroup_add.asp";
	document.frm.submit(); 		
 }	
}
// validatoion phone_group

function addgroup_edit() 
{
 if(document.frm.ph_name.value=="") 
 {
	alert("please enter the name");
	document.frm.ph_name.focus();
 }
 else
 {
 	document.frm.action="phonegroup_edit_data.asp";
	document.frm.submit(); 		
 }	
}
// validatoion phone_group

function delgroup() 
{
	var cnt;
        cnt=0
		var tot
		tot = parseInt(document.frm.pbook_id.length)
		
		for(i=0;i<tot;i++)
		{
 		      if(document.frm.pbook_id[i].checked)
		      {
		        cnt=1;
		      }
		}//end of for

        if (cnt==-1)
        {
          alert(" Select Name to Delete")
          return false;
        }

        if (!confirm("Are you sure you want to delete")==1)
		{
			return false;
		}
		else
		{
			document.frm.action="del_phonegroup.asp";
			document.frm.submit();
		}
}

// validatoion phonebook

function addphbook_edit() 
{
 if(document.frm.ph_name.value=="") 
 {
	alert("please enter the name");
	document.frm.ph_name.focus();
 }
 /*else if(document.frm.ucounty.value==0)
 {
 	alert("Country must be selected");
	document.frm.ucounty.focus();
 }*/
 else if(document.frm.ph_no.value=="") 
 {
 	alert("please enter the phone no");
	document.frm.ph_no.focus();
 }
 else
 {
 	document.frm.action="phonebook_edit_data.asp";
	document.frm.submit(); 		
 }	
}

//script for add contacts in groups

function addphone_grp()
{
//lst_phbook
//lst_grpbook

sel =document.frm.lst_phbook;
val1=sel.options[sel.selectedIndex].value;
val2=sel.options[sel.selectedIndex].text;
if (val1!="")
{
	len=document.frm.lst_grpbook.length;
	document.frm.lst_grpbook.length=(len)+1;
	document.frm.lst_grpbook.options[len].value = val1;
	document.frm.lst_grpbook.options[len].text = val2;
}
}

function delphone_grp()
{
	len=document.frm.lst_grpbook.length;
	if (len!="")
	{
		sel =document.frm.lst_grpbook;
		val0=sel.selectedIndex;		
		val1=sel.options[sel.selectedIndex].value;
		//alert(val0);
		sel.remove(val0);
		//document.frm.lst_grpbook.length=len-1;
		//for(i=0;i<=len-1;len++)
		{
			
		}
	}
}

function savephone_grp()
{
//	cont_group_add.asp
	len=document.frm.lst_grpbook.length;
	if (len!="")
	{
		grp_id=document.frm.grp_id.value;
		sel =document.frm.lst_grpbook.options.length;
		for(i=0;i<=sel-1;i++) 
		{
			document.frm.lst_grpbook.options[i].selected=true;
		}
		
		document.frm.action="cont_group_add.asp";
		document.frm.submit();
		//sel =document.frm.lst_grpbook;
		//val0=sel.selectedIndex;		
		//val1=sel.options[sel.selectedIndex].value;
	}
	else
	{
		alert("Please insert Phone Book contacts");	
	}
}

//for the import addressbook

function addimport()
{
	 if(document.frm.importaddress.value=="") 
	 {
		alert("please enter the value");
		document.frm.importaddress.focus();
	 }
	 else
	 {
		document.frm.action="import_phonebook_add.asp";
		document.frm.submit(); 		
	 }	
}

function kil()
{
	var c = event.keyCode;
	var C = String.fromCharCode ;
	alert(event.keyCode);
	if(c==13)
	{
		var str=document.frm.importaddress.value;
		var s=str.split(C);
		alert(s.lenght);
				
	}
//		var str=document.frm.importaddress.value;
		//var s=str.split();
//		alert(str);

	
}

////validation function for forgot_pass.asp
function check_id()
{
  var sel;
  sel=0;
  for(i=0;i<2;i++)
  {
     if(document.frm1.optsel[i].checked)
	   {
	     sel=document.frm1.optsel[i].value;
		 
	 }
  }
  if(sel==0)
  {
   alert("Select Atleast One Option");
   return false;
   }
   else if(sel==1)
   {
     if(document.frm1.login_name.value=="")
	  {
	    alert("Enter Login Name.");
		document.frm1.login_name.focus();
		return false;
	  }
   }
   else if(sel==2)
      {
	  		if(document.frm1.email_id.value=="")
			{
			  alert("Enter Email Id.");
			  document.frm1.email_id.focus();
			  return false;
			}
	
	  }
   
}

////validation function for forgot_pass.asp
function check_id1()
{
  var sel;
  sel=0;
  sel=document.frm1.optsel.value;
  if(sel==1)
   {
     if(document.frm1.login_name.value=="")
	  {
	    alert("Enter Login Name.");
		document.frm1.login_name.focus();
		return false;
	  }
   }
   else if(sel==2)
      {
	  		if(document.frm1.login_name.value=="")
			{
			  alert("Enter Email Id.");
			  document.frm1.login_name.focus();
			  return false;
			}
	
	  }
   
}

//Validation for edit_profile.asp


function edit_prof_validate()
{
	
 
 if(document.frm.fname.value=="") 
 {
 	alert("please enter First name");
	document.frm.fname.focus();
 return false; } 
 else if(document.frm.lname.value=="") 
 {
 	alert("please enter Last name");
	document.frm.lname.focus();
 return false; }  
 else if(document.frm.mobile.value=="") 
 {
 	alert("please enter Mobile no");
	document.frm.mobile.focus();
 return false; }   
 else if(document.frm.email.value=="") 
 {
 	alert("please enter Email Id");
	document.frm.email.focus();
 return false; }    
 else if(document.frm.comp.value=="") 
 {
 	alert("please enter Company Name");
	document.frm.comp.focus();
 return false; }     
 else if(document.frm.address1.value=="") 
 {
 	alert("please enter Address");
	document.frm.address1.focus();
 return false; }  
 else if(document.frm.city.value=="") 
 {
 	alert("please enter City");
	document.frm.city.focus();
 return false; }  
 else if(document.frm.zip.value=="") 
 {
 	alert("please enter Zip code");
	document.frm.zip.focus();
 return false; }  
 else if(document.frm.country.value=="0") 
 {
 	alert("please select country");
	document.frm.country.focus();
 return false; }  
 else if(document.frm.tel1.value=="") 
 {
 	alert("please enter Telephone No.");
	document.frm.tel1.focus();
 return false; }  

}

//validation for change_pass.asp

function pass_validate()
{
	
 lens2=document.frm.new_pass.value;
 lens3=document.frm.conf_pass.value;			
	
 if(document.frm.login_name.value=="") 
 {
	alert("Please enter Login name");
	document.frm.login_name.focus();
 return false;}
 
  else if(document.frm.old_pass.value=="") 
 {
 	alert("Please enter Old Password");
	document.frm.old_pass.focus();
 return false;}

 else if(document.frm.new_pass.value=="") 
 {
 	alert("Please enter New Password");
	document.frm.new_pass.focus();
 return false;}

 else if ((lens2.length)<=3)
 {
 	alert("Please enter more then 3 characters");
	document.frm.new_pass.focus();
 return false;}
 else if(document.frm.conf_pass.value=="") 
 {
 	alert("please enter Confirm password.");
	document.frm.conf_pass.focus();
 return false;}
 else if ((lens3.length)<=3)
 {
 	alert("please enter more then 3 characters");
	document.frm.conf_pass.focus();
 return false;} 
 else if(document.frm.new_pass.value!=document.frm.conf_pass.value) 
 {
 	alert("Please enter the both passwords same");
	document.frm.new_pass.focus();
 return false;} 
}


// insert contacts to sms send page

function insertcont()
{
		var cnt;
        cnt=0
		var tot
		tot = parseInt(document.frm.pbook_id.length)
		
		for(i=0;i<tot;i++)
		{
 		      if(document.frm.pbook_id[i].checked)
		      {
		        cnt=1;
		      }
              
              
		}//end of for
        //alert(cnt);
        if ((cnt==-1) ||(cnt==0))
        {
          alert(" Select Name to Insert")
          return false;
        }

        if (!confirm("Are you sure you want to insert")==1)
		{
			return false;
		}
		else
		{
			document.frm.action="add_popup_phonebook.asp";
			document.frm.submit();
		}
}

// validation to inbox setting page

function addinboxid() 
{
 if(document.frm.inboxid.value=="") 
 {
	alert("please enter the inbox id");
	document.frm.inboxid.focus();
 }
 else
 {
 	document.frm.action="inboxsettings_add.asp";
	document.frm.submit(); 		
 }	
}

// submit the sms page 
function subpage()
{
var f;
f =	document.frm ;
if(f.PhoneNumber.value =="")
{
	alert("Please Enter Phone Number")
	f.PhoneNumber.focus();
}
else if(f.fromname.value=="0")
{
	alert("Please select from")
	f.fromname.focus();
}
else if(f.Text.value=="")
{
	alert("Please enter message")
	f.Text.focus();
}

else if(!mobile_validate(f.PhoneNumber.value))
{
 alert("Please enter numbers only without any special characters")
 f.PhoneNumber.select();
 f.PhoneNumber.focus();
 return false;
}

else
	{
	document.frm.action="send_sms.asp";	
	document.frm.submit();	
	}
}

// submit the reminder sms page 
function subpage_rem()
{
     
      if(document.frm.PhoneNumber.value=="")
	 {
		alert("please enter the Phone number");
		document.frm.PhoneNumber.focus();
		return false;
	 }

	   else if(document.frm.fromname.value=="0")
	 {
		alert("please enter the sender");
		document.frm.fromname.focus();
		return false;
	 }
	 else if(document.frm.Text.value=="")
	 {
		alert("please enter the message");
		document.frm.Text.focus();
		return false;
	 }
	 else if(document.frm.from_date.value=="")
	 {
		alert("please enter the Sending Date");
		document.frm.from_date.focus();
		return false;
	 }
    
    else if(!getval(document.frm.from_date.value))
	{
   alert("You cannot set a reminder for Date / Time that has passed")
	frm.from_date.select();
	frm.from_date.focus();
	 return false;
	}

	else if(!mobile_validate(frm.PhoneNumber.value))
	{
	 alert("Please enter numbers only without any special characters")
	 frm.PhoneNumber.select();
	 frm.PhoneNumber.focus();
	 return false;
	}

	else
	{
    
	document.frm.action="reminder_send_sms.asp";	
	document.frm.submit();	
	return true;
	}
}


function mobile_validate(strString)
   //  check for valid numeric strings	
   {
   
   var strValidChars = "0123456789,";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function validateSms()
{
	if(document.frm.PhoneNumber.value=="") 
	 {
		alert("please enter the phone number");
		document.frm.PhoneNumber.focus();
		return false;
	 }	
	else if(document.frm.select.value=="")
	 {
		alert("please enter the sender");
		document.frm.select.focus();
		return false;
	 }	
	else if(document.frm.Text.value=="")
	 {
		alert("please enter the message");
		document.frm.Text.focus();
		return false;
	 }

	else
	 {
		document.frm.submit();
		return true;	 
	 }
	 
}


 function getval()
{
	yy=document.frm.from_date.value;
	
	yy1=yy.split('/');
	dd=yy1[0];
    yy=yy1[2];
	mm=yy1[1] -1;
	//d=dd & "/" & mm & "/" yy;
	var d2 = new Date(yy,mm,dd);
	var now = new Date();
	var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate());
	//alert(d2);
	//alert(d1);
    if(d2 < d1) 
	{
     return false;
    }
    return true;
}