function getItem(id){
    var itm = false;
    if(document.getElementById)itm = document.getElementById(id);
    else if(document.all)itm = document.all[id];
    else if(document.layers)itm = document.layers[id];
    return itm;
}


function toggle(field){
    if (getItem(field).style.display == "none"){
        getItem(field).style.display = "";
        if (getItem(field+"arrow")) getItem(field+"arrow").src="/static/images/marketing/srw/arrow_down.gif";
    } else {
        getItem(field).style.display = "none";
        if (getItem(field+"arrow")) getItem(field+"arrow").src="/static/images/marketing/srw/arrow_right.gif";
    }
}

function togglePaymentOptions(field, path){
    if (getItem(field).style.display == "none"){
        getItem(field).style.display = "";
        getItem(field+"_image").src=path+"paymentoptionarrow.gif";
    } else {
        getItem(field).style.display = "none";
        getItem(field+"_image").src=path+"paymentoptionarrow_down.gif";
    }
}

function show(field){
    getItem(field).style.display = "";
}
function hide(field){
    getItem(field).style.display = "none";
}

function showEdit(field){
    getItem(field).style.display = 'none';
    getItem(field+"_EDIT").style.display = '';
//    for (i=1;i<20;i++){
//        if (getItem("edit_button_"+i)){
//            getItem("edit_button_"+i).style.display = 'none';
//        }
//    }
}
function showView(field){
    getItem(field).style.display = '';
    getItem(field+"_EDIT").style.display = 'none';
//    for (i=1;i<20;i++){
//        if (getItem("edit_button_"+i)){
//            getItem("edit_button_"+i).style.display = '';
//        }
//    }
}

function setValue(field, val){
    getItem(field).value=val;
}

function redirectTo(country){
    if (country == "US"){
        //window.location = "http://us.clearwater.com/"+getItem('domainnameUS');
        window.location = "/"+getItem('domainnameUS').value;
    } else if (country == "CA"){
        //window.location = "http://ca.clearwater.com/"+getItem('domainnameCA');
        window.location = "/"+getItem('domainnameCA').value;
    }

}

function redirectToPage(page){
    window.location = page;
}

function showNextConfirmation (num){
    getItem('box'+num).style.display = 'none';
    for (i=parseInt(num)+1; i<15; i++){
        if (getItem('box'+i)){
            getItem('box'+i).style.display = '';
            break;
        }
    }
}


function toggleConfirmation(field){
    for (i=1;i<20;i++){
        if (i != field){
            if (getItem("box"+i)){
                getItem("box"+i).style.display = 'none';
            }
            if (getItem("box"+i+"_edit")){
                getItem("box"+i+"_edit").style.display = 'none';
            }
            if (getItem("box"+i+"_image")){
                getItem("box"+i+"_image").src="/static/images/marketing/srw/paymentoptionarrow_down.gif";
            }
        }
    }
    flag = "";
    if (getItem("box"+field).style.display == ""){
        flag = "hide";
    } else {
        flag = "show";
        if (getItem("box"+field+"_edit")){
            if (getItem("box"+field+"_edit").style.display == ""){
                flag = "hide"
            } else {
                flag = "show"
            }
        }
    }
    if (flag == "hide"){
        if (getItem("box"+field+"_image")) getItem("box"+field+"_image").src="/static/images/marketing/srw/paymentoptionarrow_down.gif";
        getItem("box"+field).style.display = "none";
        if (getItem("box"+field+"_edit")){
            getItem("box"+field+"_edit").style.display = 'none';
        }
    } else {
        if (getItem("box"+field+"_image")) getItem("box"+field+"_image").src="/static/images/marketing/srw/paymentoptionarrow.gif";
        getItem("box"+field).style.display = "";
        if (getItem("box"+field+"_edit")){
            getItem("box"+field+"_edit").style.display = 'none';

        }
    }
}

function changeCreditCardImage(path){
    if (getItem("Credit Card Type").value == "amex"){
        getItem("creditcardimage").src = path+"creditcard_amex.gif";
    } else {
        getItem("creditcardimage").src = path+"creditcard.gif";
    }
}

function popup(url,w,h,s,r){
	if(!w)w=700;if(!h)h=500;if(s==null)s="yes";if(r==null)r="yes";
	window.open(url,"Popup", "height="+h+",width="+w+",toolbar=yes,location=no,status=no,menubar=no,scrollbars="+s+",resizable="+r);
}

function iddTrial(action){
    if (action == "show"){
        getItem('becomeidd').style.display = "";
        getItem('Social Insurance #').value="";
    } else {
        getItem('becomeidd').style.display = "none";
        getItem('Social Insurance #').value="1";
    }
}