    function calculateTotCost(){
        var ad      = parseInt(document.getElementById('max_admins').value);
        if(isNaN(ad)) ad = 0;
        var ag      = parseInt(document.getElementById('max_agents').value);
        if(isNaN(ag)) ag = 0;
        var mo      = document.getElementById('nummonths');
        mo          = parseInt(mo.options[mo.selectedIndex].value);
        if(isNaN(mo)) mo = 0;
        document.getElementById('totcost').value    = ((ad + ag) * mo) * 25;
    }

    function validateForm(version){
        var fields  = new Array();
        fields.push('first_name');
        fields.push('last_name');
        fields.push('payer_email');
        fields.push('company_name');

        var names   = new Array();
        names.push('First Name');
        names.push('Last Name');
        names.push('Email Id');
        names.push('Company Name');

        var conditions  = new Array();
        conditions.push('');
        conditions.push('');
        conditions.push('');
        conditions.push('');

        var alerts      = new Array();
        alerts.push('');
        alerts.push('');
        alerts.push('');
        alerts.push('');

        var existingCompany = 0;

        if(parseInt(version) == 0){
        }else if(parseInt(version) == 1){
            fields.push('address_phone');
            names.push('Skype ID');
            conditions.push('');
            alerts.push('');
        }else if(parseInt(version) == 2){
            fields.push('address_phone');
            names.push('Skype ID');
            conditions.push('');
            alerts.push('');
            if(!isEmpty(document.getElementById('company_code').value)){
                existingCompany = 1;
                fields.push('max_agents');
                names.push('Agent Licences');
                conditions.push(' > 0');
                alerts.push('Please ensure Agent Licences is a value greater than zero');
            }else{
                fields.push('max_admins');
                names.push('Admin Licences');
                conditions.push(' > 0');
                alerts.push('Please ensure Admin Licences is a value greater than zero');
            }
        }

        for(var i = 0; i < fields.length; i++){
            var element = document.getElementById(fields[i]);
            if(isEmpty(element.value)){
                alert(names[i] + " is a mandatory field");
                element.focus();
                return false;
            }
            if(conditions[i].length > 0){
                try{
                    if(!eval(element.value + conditions[i])){
                        alert(alerts[i]);
                        element.focus();
                        return false;
                    }
                }catch(error){
                    alert(alerts[i]);
                    element.focus();
                    return false;
                }
            }
        }

        if(!isEmail((document.getElementById('payer_email').value))){
            alert("Please provide a valid email address");
            return false;
        }

        if(
            parseInt(version) == 2
            &&
            existingCompany == 0
            &&
            (
                isEmpty(document.getElementById('max_agents').value)
                ||
                parseInt(document.getElementById('max_agents').value) == 0
            )
        ){
            if(confirm(
                "You have chosen to purchase ZERO agent licenses."
                + " To harness the full potential of Phipe,"
                + " it is recommended that you purchase at least ONE agent license."
                + "\r\nClick OK to update agent licenses, CANCEL to continue with ZERO agent licenses"
            )) return false;
        }

        return document.getElementById('eula').checked;
    }

	function isEmpty(s){
		return ((s == null) || (trim(s).length == 0))
	}

	function trim(s){
		var i;
		var ss;
		ss = s + "" ;

		for ( i = (ss.length-1) ; i >= 0 ; i--){
			c = ss.charAt(i) ;

			if( (c != ' ') && (c != '\t') )
				break ;
		}
		ss = ss.substr(0, i+1);
		for ( i = 0; i < ss.length; i++){
			c = ss.charAt(i) ;

			if( (c != ' ') && (c != '\t') )
				break ;
		}
		ss = ss.substr(i, (ss.length));
		return ss ;
	}

    function isEmail(s){
		var ss;
		ss = trim(s);
        if(isEmpty(ss)){
          return false;
        }
		if (ss.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
			return true;
		else 
		   return false;
	}

    function submit_click(frm)
     {
        if(!isEmail( frm.txtEmail.value))
        {
            alert("Please provide a valid email address");
            return false;
        }
        else
        {
            frm.Submit.value	= 'Please Wait...';
            frm.Submit.disabled	= true;
            return true;
        }
     }

     function sendMail(to, subject){
        document.location.href = "mailto:" + to + "@" + "phipe." + "com" + "?subject=" + subject;
     }

     function validateAffiliateForm(frm){
        if(!isEmail( frm.txtEmail.value) || !isEmail( frm.txtToEmail.value))
        {
            alert("Please provide a valid email address");
            return false;
        }
        if(isEmpty( frm.txtName.value))
        {
            alert("Please provide a valid name");
            return false;
        }
        frm.submit();
        return true;
     }

     function clickInstall(frm){
         try{
             if(document.all){
                 document.frames.__iframe.__submitInstallForm();
             }
         }catch(error){}

         frm.target = "_blank";
         frm.action = '../clickonce/Phipe%20Enterprise%20Plus.application';
         frm.submit();
     }

     function clickDownload(frm){
         frm.target = "_self";
         frm.action = 'download.php';
         frm.submit();
     }