// Calculate 10% of selected package to set to daily cap from hidden form fields;
function setCap() {
    var setCapProcess = false;
    if (document.body.ProdID != null && document.body.daily_cap != null)
    { // Standard Packages
        var setCapType = "ProdID";
        var setCapProcess = true;
    }
    if (document.body.PromoID != null && document.body.daily_cap != null)
    { // Promo Packages
        var setCapType = "PromoID";
        var setCapProcess = true;
    }
    if (setCapProcess == true)
    {
        for (i=0;i<eval("document.body."+setCapType+".length");i++)
        {
        	if (eval("document.body."+setCapType+"["+i+"].checked"))
        	{
        		document.body.daily_cap.value = Math.floor(eval("document.body.qty_" + eval("document.body."+setCapType+"["+i+"].value") + ".value") * .1);
        	}
        }
    }
}

// Check redirect URL;
function checkURLRedir(x){
    if (x == 'http://www.yourwebsite.com' || x == '') {
        document.body.cRURL.value = '';
        return false;
    } else if (x.indexOf("APIREDIRECT") != -1) {
    	return true;
    } else {
        var urlRegxp = /^http[s]{0,1}:\/\/[a-z|A-Z|0-9]*\.(\w)\.*/;
        return(urlRegxp.test(x));
    }
}

// Purchase leads;
function goGetTrafficLeads(){
    var okay = 1;
    var f = document.body;
    
    if (okay){
		if (document.body.PromoID) {
			var radioChecked = false;
			for (var i=0; i<document.body.PromoID.length; i++)  {
				if (document.body.PromoID[i].checked)  {
					radioChecked = true;
				}
			} 
			if (!radioChecked) {
				okay = 0;
				alert("Please select a Lead Package to continue.");
			}
		}
	}
	if (okay){
        if(document.body.Opportunity1){
            var str = document.body.Opportunity2.value;
            str = str.replace(/^\s*|\s*$/g,"");
    		if (document.body.Opportunity1.value == 0 && str.length < 3){
    			alert("Please select your Primary Business Opportunity.")
    			okay = 0;
    		}else{
    		    document.body.Primary_Opportunity1.value = document.body.Opportunity1.value;
    		    document.body.Primary_Opportunity2.value = document.body.Opportunity2.value;
    		}
    	}
	}

    if(okay){
        if(f.cRURL.value == 'http://www.yourwebsite.com' || f.cRURL.value == ''){
            f.cRURL.value = '';
            okay = 0;
        }
        if(okay && f.cRURL.value > '') {
            okay = checkURLRedir(f.cRURL.value);
        }
        if (!okay) {
            alert("You must enter a valid URL for Redirection ( http://www.yourwebsite.com )");
            f.cRURL.value = 'http://www.yourwebsite.com';
            f.cRURL.select();
            f.cRURL.focus();
        }
    }
    if (okay) {
        f.submit();
    }
}

// Set company fields;
function validateCompany(){
    var ok = 1;
	if (ok == true){
        if(document.body.Opportunity1){
            var str = document.body.Opportunity2.value;
            str = str.replace(/^\s*|\s*$/g,"");
    		if (document.body.Opportunity1.value == 0 && str.length < 3){
    			alert("Please select your Primary Business Opportunity.")

    			ok = false
    		}else{
    		    document.body.Primary_Opportunity1.value = document.body.Opportunity1.value;
    		    document.body.Primary_Opportunity2.value = document.body.Opportunity2.value;
    		}
    	}
	}
	return(ok);
}

