
function confirmDelete(url, msg){
    var is_confirmed = confirm(msg);
    if(is_confirmed){
        document.location = url ;
    } else {
        return false;
    }
}



function is_agreed()
{
     if(!document.form1.agree.checked)
      {
       alert("Please Select I Agree option");
       return false;
      }
 return true;
}

function focusform()
 {
  var c=document.forms.length;
  //alert(c);
  if(c>0 ) 
  {
  	if(typeof document.s_form == 'undefined')
    {
   		len=document.forms[0].elements.length;
    }
    else
    {
    	len=document.forms[1].elements.length;
    }
   
   
   for(i=0;i<len;i++)
   {
    //alert(document.forms[0].elements[i].type);
    if(typeof document.s_form == 'undefined')
    {
    	if(document.forms[0].elements[i].type != "hidden" && document.forms[0].elements[0].disabled!=true && document.forms[0].elements[i].type!="select-one")
	    {
	      document.forms[0].elements[i].focus();
	      break;
	    }
    }
    else
    {
    	if(document.forms[1].elements[i].type != "hidden" && document.forms[1].elements[i].disabled!=true && document.forms[1].elements[i].type!="select-one")
	    {
	      document.forms[1].elements[i].focus();
	      break;
	    }
    }
   }
  }
 }
 
function validate()
	{
	
	 if(trim(document.form1.txt_fname.value)=="")
	 {
	  alert("Please enter the First Name");
	  document.form1.txt_fname.focus();
	  return false;
	 }
	 if(trim(document.form1.txt_lname.value)=="")
	 {
	  alert("Please enter the Last Name");
	  document.form1.txt_lname.focus();
	  return false;
	 }
	 if(trim(document.form1.txt_bill_lname.value)=="")
	 {
	  alert("Please enter the Billing Person's Last Name");
	  document.form1.txt_bill_lname.focus();
	  return false;
	 }
	 if(trim(document.form1.txt_bill_email.value)=="")
	{
	alert("Please enter Billing Person's Email Address");
  	document.form1.txt_bill_email.focus();
  	return false;
	}
	if (!validEmail(document.form1.txt_bill_email,"Email Address",true))
    	return false;	
	 if(trim(document.form1.txt_user.value)=="")
	 {
	  alert("Please enter the User Name");
	  document.form1.txt_user.focus();
	  return false;
	 }
	 if(trim(document.form1.txt_company.value)=="")
	 {
	  alert("Please enter the Company Name");
	  document.form1.txt_company.focus();
	  return false;
	 }
	 if(trim(document.form1.txt_address1.value)=="")
	 {
	  alert("Please enter the Address Line 1");
	  document.form1.txt_address1.focus();
	  return false;
	 }
	 if(trim(document.form1.txt_city.value)=="")
	 {
	  alert("Please enter the City");
	  document.form1.txt_city.focus();
	  return false;
	 }
	/* kashi : Bug 183 - zip should allow alpha also now; so no validation at all !! 
	
	  if(isNaN(document.form1.txt_zip.value))
	    {
	 alert("Please enter only numeric values(0-9) in Zip");
	 document.form1.txt_zip.focus();
	 return false;
	   } */
	 ctry=document.form1.country.selectedIndex;
	  if(document.form1.country.options[ctry].value=="")
	 {
	  alert("Please Select the Country");
	  document.form1.country.focus();
	  return false;
	 }
	 if(!isInteger(document.form1.txt_phone))
	{
	alert("Please enter only numeric values(0-9), -, ( , ),.,;,X in Phone");
 	document.form1.txt_phone.focus();
 	return false;
	} 
	if(!isInteger(document.form1.txt_fax))
	{
	alert("Please enter only numeric values(0-9), -, ( , ),.,;,X in Fax");
 	document.form1.txt_fax.focus();
 	return false;
	}
	 
	 ptry=document.form1.plan_id.selectedIndex;
	  if(document.form1.plan_id.options[ptry].value=="")
	 {
	  alert("Please Select the Plan");
	  document.form1.plan_id.focus();
	  return false;
	 }
	 if ((document.form1.payment_cycle[0].checked == false)
	&& (document.form1.payment_cycle[1].checked == false)
	&& (document.form1.payment_cycle[2].checked == false)  
	&& (document.form1.payment_cycle[3].checked == false))
	{
		alert ("Please Select Payment Cycle");
		return false;
	}
	if(isNaN(document.form1.txt_special_price.value))
	    {
	 alert("Please enter only numeric values(0-9) in Special Price");
	 document.form1.txt_special_price.focus();
	 return false;
	   }
	if ((document.form1.invoice[0].checked == false)
	&& (document.form1.invoice[1].checked == false) )
	{
	alert ("Please Select Invoicing");
	return false;
	}
	btry=document.form1.business_type.selectedIndex;
	  if(document.form1.business_type.options[btry].value=="")
	 {
	  alert("Please Select the Business Type");
	  document.form1.business_type.focus();
	  return false;
	 }
	 if (((document.form1.payment_cycle[0].checked == true)
	|| (document.form1.payment_cycle[1].checked == true) 
	|| (document.form1.payment_cycle[2].checked == true)) && (document.form1.txt_special_price.value != ""))
	{		
	}
	else
	{
		if ((document.form1.paid[0].checked == false)
		&& (document.form1.paid[1].checked == false) )
		{
			alert ("Please Select Customer type as Complimentary or Paid");
			return false;
		}
	 } 
	document.form1.paid[0].disabled = true;	
	document.form1.sub_users_new_plan.value ="<?=$sub_users_new_plan?>";
	
	fill_value();
	
	//alert("old "+document.form1.sub_users_old_plan.value);
	//alert("new plan="+document.form1.sub_users_new_plan.value);
	
	abc=parseInt(document.form1.sub_users_old_plan.value);
	abc1=parseInt(document.form1.sub_users_new_plan.value);
	
	//alert("old "+document.form1.sub_users_old_plan_id.value);
	//alert("new plan="+document.form1.sub_users_new_plan_id.value);	
	abc2=parseInt(document.form1.sub_users_old_plan_id.value);
	abc3=parseInt(document.form1.sub_users_new_plan_id.value);
	if(((abc1) < (abc)) && ((abc2) != (abc3)))
	{		
		var agree=confirm("All your Sub Users will get expired as you are degrading the Plan.");
		if (agree)
			return true ;
		else
			return false ;
	}
		
	
 return true;
}


function LeapYear(year) 
{
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) return true;
	else return false;
}
function okForm(myday,mymonth,myyear,field)
{
if(mymonth=="January")
{
	mymonth=1;
}
if(mymonth=="February")
{
	mymonth=2;
}
if(mymonth=="March")
{
	mymonth=3;
}
if(mymonth=="April")
{
	mymonth=4;
}
if(mymonth=="May")
{
	mymonth=5;
}
if(mymonth=="June")
{
	mymonth=6;
}
if(mymonth=="July")
{
	mymonth=7;
}
if(mymonth=="August")
{
	mymonth=8;
}
if(mymonth=="September")
{
	mymonth=9;
}
if(mymonth=="October")
{
	mymonth=10;
}
if(mymonth=="November")
{
	mymonth=11;
}
if(mymonth=="December")
{
	mymonth=12;
}
	if(myday > 31) {
		alert("The maximum number of days in a month is 31.\n"+myday+" is invalid in " + field);
		return false;
	}
	if((mymonth==4) || (mymonth==6) || (mymonth==9) || (mymonth==11)) {
		if(myday>30) {
		alert("Only 30 days in the month you have selected in " + field);
		return false;
		}
	}
	if((mymonth==2) && (myday > 29)) {
		alert("The maximum number of days in February is 29.\n"+myday+" is invalid in "  + field);
		return false;
	}
	if(!LeapYear(myyear) && (mymonth == 2) && (myday > 28)) {
		alert("There are only 28 days in February "+myyear + "in "  + field );
		return false;
	}
	return true;
}


function abc()
{
	if (((document.form1.payment_cycle[0].checked == true)
	|| (document.form1.payment_cycle[1].checked == true) 
	|| (document.form1.payment_cycle[2].checked == true))
	&& (document.form1.txt_special_price.value != "")
	&& (document.form1.plan_id.value != ""))
	{
		//alert ("Disable Complimentary ");
		document.form1.paid[0].disabled = true;
	}
	
}

function validate(){
    
	 if(trim(document.form1.first_name.value)=="")
	 {
	  alert("Please enter the First Name");
	  document.form1.fname.focus();
	  return false;
	 }
	 if(trim(document.form1.last_name.value)=="")
	 {
	  alert("Please enter the Last Name");
	  document.form1.lname.focus();
	  return false;
	 }
	  if(trim(document.form1.email.value)=="")
	 {
	  alert("Please enter Email Address");
	  document.form1.email.focus();
	  return false;
	 }
	if (!validEmail(document.form1.email,"Email Address",true))
    	return false;	
	
	if(trim(document.form1.bill_first_name.value)=="")
	 {
	  alert("Please enter the Billing Person's First Name");
	  document.form1.bill_fname.focus();
	  return false;
	 }
	 if(trim(document.form1.bill_last_name.value)=="")
	 {
	  alert("Please enter the Billing Person's Last Name");
	  document.form1.bill_last_name.focus();
	  return false;
	 }
	 if(trim(document.form1.bill_email.value)=="")
	{
		alert("Please enter Billing Person's Email Address");
	  	document.form1.bill_email.focus();
	  	return false;
	}
	if (!validEmail(document.form1.bill_email,"Email Address",true))
    	return false;	

	 if(trim(document.form1.user.value)=="")
	 {
	  alert("Please enter the User Name");
	  document.form1.user.focus();
	  return false;
	 }
	 

	  if(trim(document.form1.pass.value)=="")
	 {
	  alert("Please enter the Password");
	  document.form1.password.focus();
	  return false;
	 }
	 if(trim(document.form1.confirm_password.value)=="")
	 {
	  alert("Please enter the Confirm Password");
	  document.form1.confirm_password.focus();
	  return false;
	 }
	  if(trim(document.form1.pass.value) != trim(document.form1.con_pass.value))
	  {
	  alert("Password and Confirm password should be same");
	  document.form1.confirm_password.focus();	  	
	  return false;	
	  }

	 if(trim(document.form1.company.value)=="")
	 {
	  alert("Please enter the Company Name");
	  document.form1.company.focus();
	  return false;
	 }
	 if(trim(document.form1.address1.value)=="")
	 {
	  alert("Please enter the Address Line 1");
	  document.form1.address1.focus();
	  return false;
	 }
	 if(trim(document.form1.city.value)==""){
	  alert("Please enter the City");
	  document.form1.city.focus();
	  return false;
	 }

	 ctry=document.form1.country.selectedIndex;
	 if(document.form1.country.options[ctry].value==""){
	  alert("Please Select the Country");
	  document.form1.country.focus();
	  return false;
	 }
	   if(!isInteger(document.form1.phone))
	 {
		alert("Please enter only numeric values(0-9), -, ( , ),.,;,X in Phone");
	 	document.form1.phone.focus();
	 	return false;
	 }  
	
	if(document.form1.phone.value=="") {
		alert("Please enter the Phone Number");
	 	document.form1.phone.focus();
	 	return false;
	 } 
	
	if(!isInteger(document.form1.fax)){
		alert("Please enter only numeric values(0-9), -, ( , ),.,;,X in Fax");
	 	document.form1.fax.focus();
	 	return false;
	} 

	 if ((document.form1.payment_cycle[0].checked == false)
        && (document.form1.payment_cycle[1].checked == false) 
        && (document.form1.payment_cycle[2].checked == false) 
        && (document.form1.payment_cycle[3].checked == false))
	 {
		alert ("Please Select Payment Cycle");
		return false;
	 }

	 btry=document.form1.business_type.selectedIndex;

	  if(document.form1.business_type.options[btry].value=="")
	 {

	  alert("Please Select the Business Type");
	  document.form1.business_type.focus();
	  return false;
	 }
 return true;
}

function fill_values(){
	document.form1.bill_first_name.value = document.form1.first_name.value;
	document.form1.bill_last_name.value = document.form1.last_name.value;
	document.form1.bill_email.value = document.form1.email.value;
}

function isDigit(c)
{   
 return ((c >= "0") && (c <= "9") || (c == "x") || (c == ".") || (c == ";")|| (c == "-") || (c == ")") || (c == "(") || (c == " ") || (c == "+"))
 //return true;
}

function isInteger(field){ 
  var i, c;
  var s = field.value;
  
 for (i = 0; i < s.length; i++)
  { // Check if current character is number.
   c = s.charAt(i);
   if (!isDigit(c)) 
    {
     return false;
    }
  }
 
 return true;
}

function isEmailAddr(email){
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
  result = true;
  }

  return result;
}

function validEmail(formField,fieldLabel,required){
  var result = true;
  
  if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
  {
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    formField.focus();
    result = false;
  }
   
  return result;
}


    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }

    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }