	/*PROGRAMMER     :  KRN
     SCRIPT NAME    :  scripts.js
     CREATED ON     :  06/Nov/2006
     MODIFIED ON    :  13/Nov/2006*/

    /*//Description   :- function to validate an email id*/
    function isBadEmail(strg) {
            email_array = strg.split('@');
            if (email_array.length != 2) return true;
            if (email_array[1].split(".").length < 2) return true;
            if (email_array[1].split(".")[1].length < 1) return true;
            if (strg.indexOf('@') < 1) return true;
            if (strg.indexOf(' ') != -1) return true;
            if (email_array[1].indexOf('.') < 1) return true;
            if (strg.length < 5) return true;
            return false;
          }
     //-------------------------------------------------------------------------

   // Calendar management
   function show_calendar(obj)
        {
                    gfPop.fStartPop(obj,Date);
        }
    //-------------------------------------------------------------------------

    // Leads registeration management
    function  NewLeadsSignup()
     {
        var  Fname =  document.FrmPartner.name.value;
        var newFname = Fname.replace(/ /g,"");
        //Name
        if(Fname=='')
        {
            alert("Please Enter Your Name");
            document.FrmPartner.name.focus();
            return false;
        }

        var  surname =  document.FrmPartner.surname.value;
        var newsurname = surname.replace(/ /g,"");
        //surname
        if(newsurname=='')
        {
            alert("Please Enter Your Surname");
            document.FrmPartner.surname.focus();
            return false;
        }

        var  email =  document.FrmPartner.email.value;
        var newemail = email.replace(/ /g,"");
        //email
        if(newemail=='')
        {
            alert("Please Enter Your E-mail");
            document.FrmPartner.email.focus();
            return false;
        }
       if(isBadEmail(newemail))
        {
             alert("Invalid Email Id");
            document.FrmPartner.email.focus();
            return false;
        }
        var  phone =  document.FrmPartner.phone.value;
        var newphone = phone.replace(/ /g,"");
        //phone
        if(newphone=='')
        {
            alert("Please Enter Your Phone Number With Area Code");
            document.FrmPartner.phone.focus();
            return false;
        }
        //country
        if(document.FrmPartner.custom_country.value=='')
        {
            alert("Please Select Your Country");
            document.FrmPartner.custom_country.focus();
            return false;
        }
        return true;
    }
     //------------------------------------------------------------------------

    //function to validate the login form
	function login_validate()
	{
	//user name
	if(document.frm_login.txt_uname.value=="")
	{
	alert("Please enter the user name");
	document.frm_login.txt_uname.focus();
	return false;
	}
	//password
	if(document.frm_login.txt_pwd.value=="")
	{
	alert("Please enter password");
	document.frm_login.txt_pwd.focus();
	return false;
	}
	return true;
	}
     //------------------------------------------------------------------------

    //Description   :- function to partner edit profile
     function change_profile_form()
     {
            //user name
        if(document.frm_change_profile.text_first_name.value=='')
        {
            alert("Please Enter Your First Name!!");
            document.frm_change_profile.text_first_name.focus();
            return false;
        }
            if(document.frm_change_profile.text_last_name.value=='')
        {
            alert("Please Enter Your Surame!!");
            document.frm_change_profile.text_last_name.focus();
            return false;
        }

           if(document.frm_change_profile.text_email.value=='')
        {
            alert("Please Enter Your Email Address!!");
            document.frm_change_profile.text_email.focus();
            return false;
        }
          if(isBadEmail(document.frm_change_profile.text_email.value))
        {
             alert("Invalid Email Id");
            document.frm_change_profile.text_email.focus();
            return false;
        }
             if(document.frm_change_profile.text_phone.value=='')
        {
            alert("Please Enter Your Phone Number with Area Code!!");
            document.frm_change_profile.text_phone.focus();
            return false;
        }
        if(document.frm_change_profile.sel_country.value=='')
        {
            alert("Please Select country!!");
            document.frm_change_profile.sel_country.focus();
            return false;
        }

        return true;
     }
     //------------------------------------------------------------------------

    //Description   :- function to user edit password
     function change_password_form()
     {
            //user name
        if(document.frm_change_password.text_old_pass.value=='')
        {
            alert("Please Enter Your Old Password!!");
            document.frm_change_password.text_old_pass.focus();
            return false;
        }
         if(document.frm_change_password.text_new_pass.value=='')
        {
            alert("Please Enter New Password!!");
            document.frm_change_password.text_new_pass.focus();
            return false;
        }
          if(document.frm_change_password.text_confirm_pass.value=='')
        {
            alert("Please ReType Your New Password!!");
            document.frm_change_password.text_confirm_pass.focus();
            return false;
        }
          //confirm password
        if(document.frm_change_password.text_new_pass.value!=document.frm_change_password.text_confirm_pass.value)
        {
            alert("Please confirm your password");
            document.frm_change_password.text_confirm_pass.focus();
            return false;
        }

        return true;
    }
    //------------------------------------------------------------------------

    //Description   :- function to update follwup date
     function UpdateFollwupDate()
     {
        //date
        if(document.frm_leadFollowup.followup.value=='')
        {
            alert("Please Enter New Follow up Date.");
            document.frm_leadFollowup.followup.focus();
            return false;
        }
      return true;
    }
     //------------------------------------------------------------------------

    //Description   :- function to lead assign
     function UpdateLeadAssign()
     {
        //Partner
        if(document.frm_leadAsssign.sel_partners.value=='')
        {
            alert("Please Select a Partner.");
            document.frm_leadAsssign.sel_partners.focus();
            return false;
        }
        var agree= window.confirm("Are you sure you want to assign this lead? \n If yes you can not UNDO this process.");
		if(agree)
		{
			return true;
		}
        else return false;

      return true;
    }
    //------------------------------------------------------------------------

    //Description   :- email form vailidation
    function mailsetup_validate(){
      
    /*  if(document.frm_emails.list_events.value=="ChooseEvent")
	  {
             alert(document.frm_emails.list_events.value) ;
            document.frm_emails.list_events.focus();
            return false;
      }
	*/ 
      if(document.frm_emails.fromtxt.value==""){
             alert("Please Enter From Email ID") ;
            document.frm_emails.fromtxt.focus();
            return false;
      }
      /* if(isBadEmail(document.frm_emails.fromtxt.value))
        {
             alert("Invalid Email Id");
            document.frm_emails.fromtxt.focus();
            return false;
        }*/
       var  sub =  document.frm_emails.subjecttxt.value;
       var newsub = sub.replace(/ /g,"");
      if(newsub==""){
             alert("Please Enter Subject") ;
            document.frm_emails.subjecttxt.focus();
            return false;
      }
      var  bdy =  document.frm_emails.bodytxt.value;
      var newbdy = bdy.replace(/ /g,"");
      if(newbdy==""){
             alert("Please Enter Mail Body") ;
            document.frm_emails.bodytxt.focus();
            return false;
      }

     return true;
    }
    //------------------------------------------------------------------------

    // Partners registeration management
    function  NewPartners()
     {
        var  Fname =  document.FrmPartner.name.value;
        var newFname = Fname.replace(/ /g,"");
        //Name
        if(Fname=='')
        {
            alert("Please Enter Your Name");
            document.FrmPartner.name.focus();
            return false;
        }

       /* var  surname =  document.FrmPartner.surname.value;
        var newsurname = surname.replace(/ /g,"");
        //surname
        if(newsurname=='')
        {
            alert("Please Enter Your Surname");
            document.FrmPartner.surname.focus();
            return false;
        }*/

        var  email =  document.FrmPartner.email.value;
        var newemail = email.replace(/ /g,"");
        //email
        if(newemail=='')
        {
            alert("Please Enter Your E-mail");
            document.FrmPartner.email.focus();
            return false;
        }
        if(isBadEmail(newemail))
        {
             alert("Invalid Email Id");
            document.FrmPartner.email.focus();
            return false;
        }
        var  phone =  document.FrmPartner.phone.value;
        var newphone = phone.replace(/ /g,"");
        //phone
        if(newphone=='')
        {
            alert("Please Enter Your Phone Number With Area Code");
            document.FrmPartner.phone.focus();
            return false;
        }
        //country
/*        if(document.FrmPartner.custom_country.value=='')
        {
            alert("Please Select Your Country");
            document.FrmPartner.custom_country.focus();
            return false;
        }
        var  PartnerID =  document.FrmPartner.PartnerID.value;
        var newPartnerID = PartnerID.replace(/ /g,"");
        //PartnerID
        if(newPartnerID=='')
        {
            alert("Please Enter Your Username(PartnerID)");
            document.FrmPartner.PartnerID.focus();
            return false;
        }
        var  Password =  document.FrmPartner.Password.value;
        var newPassword = Password.replace(/ /g,"");
        //Password
        if(newPassword=='')
        {
            alert("Please Enter Your Password");
            document.FrmPartner.Password.focus();
            return false;
        }
        var  RePassword =  document.FrmPartner.RePassword.value;
        var newRePassword = RePassword.replace(/ /g,"");
        //Password
        if(newRePassword=='')
        {
            alert("Please Confirm Your Password");
            document.FrmPartner.RePassword.focus();
            return false;
        }
        //Password Mismatch
        if(newRePassword!=newPassword)
        {
            alert("Password Mismatch");
            document.FrmPartner.Password.focus();
            return false;
        }
*/        return true;
    }
	/****************************************************
				admin name check for updation
				 PROGRAMMER     :  JVK
	******************************************************/
	function changenameinfo_validate()
	{
		if(document.frm_userinfo.txt_username.value=="")
		{
			alert("Enter the user name!");
			document.frm_userinfo.txt_username.focus;
			return false;
		}
		var agree= confirm("Do you Want to update the user name?");
		if(agree)
		{
				return true;
		}
		return false;
	}
	/****************************************************
				admin password check for updation
				 PROGRAMMER     :  JVK
	******************************************************/
	function changepassword_validate()
	{
		if(document.frm_password.txt_oldpassword.value=="")
		{
			alert("Enter the old password!");
			document.frm_password.txt_oldpassword.focus;
			return false;
		}
		if(document.frm_password.txt_password.value=="")
		{
			alert("Enter the new password!");
			document.frm_password.txt_password.focus;
			return false;
		}
		if(document.frm_password.txt_repassword.value=="")
		{
			alert("Retype the password!");
			document.frm_password.txt_repassword.focus;
			return false;
		}
		if(document.frm_password.txt_password.value!=document.frm_password.txt_repassword.value)
		{
			alert("Password doesn't match!");
			document.frm_password.txt_repassword.focus;
			return false;
		}		var agree= confirm("Do you Want to update the password?");
		if(agree)
		{
			return true;
		}
		return false;
	}
	/****************************************************
				admin Profile check for updation
				 PROGRAMMER     :  JVK
	******************************************************/
	function changeemailid_validate()
	{
		if(document.frm_emailid.txt_firstname.value=="")
		{
			alert("Enter the First Name!");
			document.frm_emailid.txt_firstname.focus;
			return false;
		}
		if(document.frm_emailid.txt_surname.value=="")
		{
			alert("Enter the Surame!");
			document.frm_emailid.txt_surname.focus;
			return false;
		}
		if(document.frm_emailid.txt_emailid.value=="")
		{
			alert("Enter the E-mail ID!");
			document.frm_emailid.txt_emailid.focus;
			return false;
		}
		if(isBadEmail(document.frm_emailid.txt_emailid.value))
		{
			alert("Enter Valid E-mail ID!");
			document.frm_emailid.txt_emailid.focus;
			return false;
		}
		var agree= confirm("Do you Want to update the User Profile?");
		if(agree)
		{
			return true;
		}
		return false;
	}

    //----------------------------------------------------
    //Description   :- function to lead assign
     function PartneMailManage(status,MId)
     {
        var status	=	status ;
        if(status=='Approve')
        {
        var agree= window.confirm("Are you sure you want to approve this mail? \n If OK this mail send to all recipients \n You can not UNDO this process.");
		if(agree)
		{
			window.location="mailApprove.php?status=Approve&MId=" + MId;
		}
        }
        if(status=='Reject')
        {
        var agree= window.confirm("Are you sure you want to reject this mail? \n If OK this mail will add to the Rejected list. \n You can not UNDO this process.");
        if(agree)
        {
            window.location="mailApprove.php?status=Reject&MId=" + MId;
        }
        }
        if(status=='Delete')
        {
        var agree= window.confirm("Are you sure you want to delete this mail? \n If OK this mail will delete from the list. \n You can not UNDO this process.");
        if(agree)
        {
            window.location="mailApprove.php?status=Delete&MId=" + MId;
        }
        }
    }
     //----------------------------------------------------
    //Description   :- function to delete mails
     function PartneMailDelete(status,MId)
     {
        var status  =   status ;
        if(status=='Approve')
        {
        var agree= window.confirm("Are you sure you want to delete this mail? \n If OK this mail will delete from the list. \n You can not UNDO this process.");
        if(agree)
        {
            window.location="mailApprove.php?status=Delete&MId=" + MId + "&backurl=Approve";
        }
        }
        if(status=='Reject')
        {
        var agree= window.confirm("Are you sure you want to delete this mail? \n If OK this mail will delete from the list. \n You can not UNDO this process.");
        if(agree)
        {
            window.location="mailApprove.php?status=Delete&MId=" + MId + "&backurl=Reject";
        }
        }
    }
    //------------------------------------------------------------------------

    //Description   :- Auto email form vailidation
    function Automailsetup_validate(){

      var  fr =  document.frm_automails.fromtxt.value;
       var newfr = fr.replace(/ /g,"");

      if(newfr==""){
             alert("Please Enter From Email ID") ;
            document.frm_automails.fromtxt.focus();
            return false;
      }
      if(newfr!="$pEmail")
      {
       if(isBadEmail(newfr))
        {
             alert("Invalid Email Id");
            document.frm_automails.fromtxt.focus();
            return false;
        }
      }  
       var  sub =  document.frm_automails.subjecttxt.value;
       var newsub = sub.replace(/ /g,"");
      if(newsub==""){
             alert("Please Enter Subject") ;
            document.frm_automails.subjecttxt.focus();
            return false;
      }
      var  time =  document.frm_automails.timeframe.value;
       var newtime = time.replace(/ /g,"");
      if(newtime=="" || isNaN(newtime)){
             alert("Please Enter a Valid Delivery Time Frame") ;
            document.frm_automails.timeframe.focus();
            return false;
      }
      var  bdy =  document.frm_automails.bodytxt.value;
      var newbdy = bdy.replace(/ /g,"");
      if(newbdy==""){
             alert("Please Enter Mail Body") ;
            document.frm_automails.bodytxt.focus();
            return false;
      }

     return true;
    }
	
	function templatesetup_validate()
	{ //frm_templatemails
	
	
       var  fr1 =  document.frm_templatemails.fromtxt.value;
       var newfr1 = fr1.replace(/ /g,"");

      if(newfr1==""){
             alert("Please Enter From Email ID") ;
            document.frm_templatemails.fromtxt.focus();
            return false;
      }
      if(newfr1!="$pEmail")
      {
       if(isBadEmail(newfr1))
        {
             alert("Invalid Email Id");
            document.frm_templatemails.fromtxt.focus();
            return false;
        }
      }  
       var  sub1 =  document.frm_templatemails.subjecttxt.value;
       var newsub1 = sub1.replace(/ /g,"");
      if(newsub1==""){
             alert("Please Enter Subject") ;
            document.frm_templatemails.subjecttxt.focus();
            return false;
      }
     
      var  bdy1 =  document.frm_templatemails.bodytxt.value;
      var newbdy1 = bdy1.replace(/ /g,"");
      if(newbdy1==""){
             alert("Please Enter Mail Body") ;
            document.frm_templatemails.bodytxt.focus();
            return false;
      }

     return true;

	}

    //----------------------------------------------------
    //Description   :- function to Delete Auto Mail
     function DeleteAutoMail(status,MId,flag,part)
     {
		  //alert(part);
        var status  =   status ;
        if(status=='Delete')
        {
        var agree= window.confirm("Are you sure you want to Delete this mail? \n If yes this mail will delete from the list. \n You can not UNDO this process.");
        if(agree)
        {
            window.location="UpdateManage.php?delmode=DeleteAutoMail&MId=" + MId+ "&flag="+flag+ "&part="+part;
        }
        }
   }

   //----------------------------------------------------
    //Description   :- function to Change status Auto Mail
     function UpdateStatsusAutoMail(status,MId,mode,part)
     {
		  //alert(part);
        var status  =   status ;
        var agree= window.confirm("Are you sure you want to change the status to " + status + "?");
        if(agree)
        {
          window.location="UpdateManage.php?updmode=StatusAutoMail&MId=" + MId + "&autostatus=" + status+ "&flag=" +mode +"&part=" +part;
        }
   }
   /*******************************************************
   		change the status 
	******************************************************/
    function updatestatus(page,name,id,status)
    {
        if(confirm("Are you sure to modify the status of this " + name + "?")){
             window.location = page + "?mode=" + name + "&lId=" + id + "&status=" + status  ;
		}
    }
   	function OpenWindow(url)
	{
       nw = open(url,'new','height=570,width=550,scrollbars=yes,resizable=1');
	   nw.focus();
	}
	
	//validate the eamil template
	function changetmp_validate(){
		if(document.frm_template.txt_sub.value == ""){
			alert("Please enter the subject");
			document.frm_template.txt_sub.focus();
			return false;
		}
		if(document.frm_template.txt_template.value == ""){
			alert("Please enter the mail body");
			document.frm_template.txt_template.focus();
			return false;
		}
		return true;
	}
  	/*----------------------------------------------------------------
    Description   :- Common Function to confirm the deletion and redirect to the delete validation page
    Programmer    :- MNU
    Last Modified :- 19/FEB/2009
    -------------------------------------------------------------------*/
	function deleteconfirm(page,name,params,msg,msg1,msg3,msg4)
	{ 
		var newmsg	= msg+ name + "?\n"+ msg1 + name + msg3;
		if(msg4)
			newmsg	+= " \n"+msg4;
 		if(confirm(newmsg))
		window.location = page + "?" + params +"&name="+ name;
	}
	/*----------------------------------------------------------------
    Description   :- function to change the status of the links
    Programmer    :- MNU
    Last Modified :- 19/FEB/2009
    -------------------------------------------------------------------*/
	function updatestatusconfirm(page,name,msg)
    {
	    if(confirm(msg + name ))
				window.location = page  ;
		else 
				return false;
    }
	/*----------------------------------------------------------------
	Description   :- Function is used to show the payment info 
	Programmer    :- MNU
	Last Modified :- 20/FEB/2008
	-------------------------------------------------------------------*/
	function showPaymentInfo(){
		var Gateway = document.getElementById('Paymentgateway').value;
		if(Gateway==''){
			alert("Please select payment method");
		}else{
			var url= "ajax_common.php?action=Paymentinfo&gateway="+Gateway;
			ajaxpage(url,'Paymentdetails');
		}//end if
	}
	/*----------------------------------------------------------------
	Description   :- Function is used to show the payment info 
	Programmer    :- MNU
	Last Modified :- 20/FEB/2008
	-------------------------------------------------------------------*/
	function showPayment(){
		var Gateway = document.getElementById('Paymentgateway').value;
		if(Gateway==''){
			document.getElementById('Paymentdetails').style.display = "none";
			alert("Please select payment method");
		}else{
				if(Gateway==1)
				{
					document.getElementById('Paymentdetails').style.display='block';
				}
		}//end if
}

   function  upgrade_lead()
     {
        var  PartnerID =  document.FrmPartner.PartnerID.value;
        var newPartnerID = PartnerID.replace(/ /g,"");
        //PartnerID
        if(newPartnerID=='')
        {
            alert("Please Enter Your Username(PartnerID)");
            document.FrmPartner.PartnerID.focus();
            return false;
        }
        var  Password =  document.FrmPartner.Password.value;
        var newPassword = Password.replace(/ /g,"");
        //Password
        if(newPassword=='')
        {
            alert("Please Enter Your Password");
            document.FrmPartner.Password.focus();
            return false;
        }
        var  RePassword =  document.FrmPartner.RePassword.value;
        var newRePassword = RePassword.replace(/ /g,"");
        //Password
        if(newRePassword=='')
        {
            alert("Please Confirm Your Password");
            document.FrmPartner.RePassword.focus();
            return false;
        }
        //Password Mismatch
        if(newRePassword!=newPassword)
        {
            alert("Password Mismatch");
            document.FrmPartner.Password.focus();
            return false;
        }
				var  Paymentgateway =  document.FrmPartner.Paymentgateway.value;
        var newPaymentgateway = Paymentgateway.replace(/ /g,"");
		//payment
        if(newPaymentgateway=='')
        {
            alert("Please Select a Gateway");
            document.FrmPartner.Paymentgateway.focus();
            return false;
        }

        return true;
    }
	
	/*----------------------------------------------------------------
	Description   :- Function is submit money type
	Programmer    :- MNU
	Last Modified :- 26/FEB/2009
	-------------------------------------------------------------------*/

	function submit_moneytype()
	{		//document.getElementById('money_type').value;
		var moneytype=document.moneytype.money_type.value;
		window.location = "settings_validate.php?mode=money_type&money_type="+moneytype  ;
	}
		/*----------------------------------------------------------------
	Description   :- Function to get commision
	Programmer    :- MNU
	Last Modified :- 03/MAR/2009
	-------------------------------------------------------------------*/

	function list_commision()
	{		//document.getElementById('money_type').value;
		var status=document.commision_form.commision.value;
		window.location = "index.php?act=partners_commision&status="+status ;
	}
	function email_validation()
	{	  
		var  email =  document.frm_paypal.paypal_id.value;
        var newemail = email.replace(/ /g,"");
        //email
        if(newemail=='')
        {
            alert("Please Enter Your E-mail");
            document.frm_paypal.paypal_id.focus();
            return false;
        }
        if(isBadEmail(newemail))
        {
             alert("Invalid Email Id");
            document.frm_paypal.paypal_id.focus();
            return false;
        }
		return true;
	}	
	function email_validation_paypal()
	{	
		var  email =  document.getElementById('paypal_id').value;
        var newemail = email.replace(/ /g,"");
        //email
        if(newemail=='')
        {
            alert("Please Enter Your E-mail");
            document.getElementById('paypal_id').focus();
            return false;
        }
        if(isBadEmail(newemail))
        {
             alert("Invalid Email Id");
            document.getElementById('paypal_id').focus();
            return false;
        }
		return true;
	}
	/*----------------------------------------------------------------
	Description   :- Function for refund
	Programmer    :- MNU
	Last Modified :- 25/MAR/2009
	-------------------------------------------------------------------*/
	function confirm_refund(id)
	{
		var msg="Do you want to refund the amount.\n If OK the commission deducted from the parent partner account and the upgraded lead can not be logged in again";
		if(confirm(msg))
				window.location = "index.php?act=partners_subscription&action=refund&payment_id="+id  ;
		else 
				return false;	
		
	}
	
	//make the index page as default
	function makeDefault(indexId){
		url = "ajaxPage.php?process=default&indexId="+indexId;
		container = "default_index_"+indexId;
		ajaxpage(url,container);
	}