function addItemToCart(objectName){

    document.getElementById("itemid").value = document.getElementById("ID_"+objectName).value;      
    document.forms[0].action =  "https://email-list.com" + basePath + "shoppingCart/shop/showcart.aspx";
    document.forms[0].__VIEWSTATE.name = 'cart';
    document.forms[0].submit();
}

function addItemNoToCart(itemNo){
    document.getElementById("itemid").value = itemNo;       
    document.forms[0].action =  "https://email-list.com" + basePath + "shoppingCart/shop/showcart.aspx";
    document.forms[0].__VIEWSTATE.name = 'cart';
    document.forms[0].submit();
}

function ViewCart(){
    window.location.href =  "https://email-list.com" + basePath + "shoppingCart/shop/showcart.aspx";
}

function AddCustomItemToCart()
{
    var item = document.getElementById("itemid");
    eval( "item.value =" + "CL" + document.getElementById("ctl00_ContentPlaceHolder1_priceCategory").value );
    
    addItemNoToCart(item.value );
}

function AddCustomEmailListItemToCart()
{
    var item = document.getElementById("itemid");
    eval( "item.value =" + "CEL" + document.getElementById("ctl00_ContentPlaceHolder1_EmailSearchControl1_priceCategory").value );
    addItemNoToCart(item.value );
}

function AddCustomEmailListItemToCartHP() {
    var item = document.getElementById("itemid");
    eval("item.value =" + "CEL" + document.getElementById("ctl00_ContentPlaceHolder1_Search_priceCategory").value);
    addItemNoToCart(item.value);
}

function DetermineAndAddItem(results,type){
    results = results.replace(/,/,"" )
    var num = CalculatePriceCategory(results);
    var item;
    eval( "item =" + "CL" + num );
    if(type == "N" && document.getElementById("ReturnLink") != null){    
		if ( document.getElementById("ReturnLink").value.indexOf('&type=nation') < 0)
			document.getElementById("ReturnLink").value += '&type=nation';
    }
	else
		if(document.getElementById("ReturnLink") != null)
		document.getElementById("ReturnLink").value = document.getElementById("ReturnLink").value.replace(/&type=nation/,"");
    addItemNoToCart(item);
}


function CalculatePriceCategory(results){
        if ( results < 2501 )
            return 1;
        else if (results < 5001) 
            return 2;
        else if (results < 10001)
            return 3;
        else if (results < 15001)
            return 4;
        else if (results < 20001)
            return 5;
        else if (results < 30001)
            return 6;
        else if (results < 35001)
            return 7;
        else if (results < 40001)
            return 8;
        else if (results < 45001)
            return 9;
        else if (results < 50001)
            return 10;
        else if (results < 75001)
            return 11;
        else if (results < 100001)
            return 12;
        else if (results < 200001)
            return 13;
        else
            return 14;        

}

 function show(control){
    if (document.getElementById(control).className == 'show')
        document.getElementById(control).className ='hide';
    else
        document.getElementById(control).className ='show';
 }

function PostAffiliateForm(){
    Page_ClientValidate();

    if (Page_IsValid && Page_ClientValidate)
    {
        document.forms[0].action = 'http://affiliate.email-list.com/affiliate/join.aspx';
        document.forms[0].__VIEWSTATE.name = 'join';
        document.forms[0].submit();
    }
}

function validationRecaptchaJS() {
    if (!Page_ClientValidate("affiliateGroup")) {
        return false;
    }
    else {
        if ($.browser.msie && $.browser.version <= 6) {
            document.forms[0].action = 'http://affiliate.email-list.com/affiliate/join.aspx';
            document.forms[0].__VIEWSTATE.name = 'join';
            document.forms[0].submit();
            return;
        }

        ws.ValidateRecapatcha(
            Recaptcha.get_challenge(),
            Recaptcha.get_response(),
            function (result) {
                if (result == true) {
                    document.forms[0].action = 'http://affiliate.email-list.com/affiliate/join.aspx';
                    document.forms[0].__VIEWSTATE.name = 'join';
                    document.forms[0].submit();
                }
                else {
                    $("#recaptcha_instructions_image").html("Incorrect. Try again.");
                    document.getElementById('recaptcha_instructions_image').style.color = "#CC0000";
                    Recaptcha.reload();
                    return false;
                }
            }
        );
    }
    return true;
}

function validateJMCaptchaJS() {
    if (!Page_ClientValidate("affiliatesGroup")) {
        return false;
    }
    else {

        var src = $("div.jmcaptcha img").attr("src");
        src = src.substring(23, src.length - 4);

        var entered = $("input[name$='CaptchaControl1']").val();

        ws.ValidateJMCaptcha(
            src,
            entered,
            function(result) {
                if (result == "1") {
                    document.forms[0].action = 'http://affiliate.email-list.com/affiliate/join.aspx';
                    document.forms[0].__VIEWSTATE.name = 'join';
                    document.forms[0].submit();
                }
                else {
                    alert("Wrong code. Please try again!");
                    $("input[name$='CaptchaControl1']").focus();

                    return false;
                }
            }
        );
    }
    return true;
}
