<!--//
var async = true;
var def_country = 'US';  // Default Country
var alt_country = 'CA'; // Alternate Country
var ALERT_TITLE = "Attention!";
var ALERT_BUTTON_TEXT = "Ok";

if (navigator.appVersion.indexOf("MSIE")!=-1) {
        var bName = 'MSIE';
        var temp = navigator.appVersion.split("MSIE");
        var bVer = parseFloat(temp[1]);
} else {
        var bName = navigator.appName;
        var bVer = parseFloat(navigator.appVersion);
}

function getstamp()     {
        date = new Date();
        return date.getTime();
}

function loadDoc(url, postdata, cb_func) {
        var req;
        req = false;
    if (window.XMLHttpRequest) {
        try { req = new XMLHttpRequest(); } catch(e) { req = false; }
    } else if (window.ActiveXObject) {
        try { req = new ActiveXObject("Msxml2.XMLHTTP"); } 
                catch(e) { 
                        try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
                        catch(e) { req = false; }
                }
    }
        if(req) {
                req.open("POST", url, async);
                req.onreadystatechange = function() { 
                        if (req.readyState == 4 && req.status == 200 && cb_func != "") {
                                eval("cb_"+cb_func+"(req.responseText);");
                        }
                }
                req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                req.send(postdata);
        }
}

function selectAll (frm, item) {
        var e = frm.elements;
        var re = new RegExp("^"+item);
        for (i=0;i<e.length;i++) {
                if (e[i].id != '' && e[i].id.match(re)) {
                        e[i].checked = true;
                }
        }
}

function del_event (id) {
        if (jsconfirm()) location.href = 'index.php?l=account&d=deletereg&id='+id+'&tab=5';
}

function jsconfirm (note) {
        if (note == undefined) note = 'Are you sure you want to complete this action?';
        if (confirm(note)) {
                return true;
        } else {
                return false;
        }
}

function cb_updatePrice (txt) {
        var result = txt.split("||");
        if (document.getElementById("product_price")) document.getElementById("product_price").innerHTML = result[0];
        if (document.getElementById("list_price")) document.getElementById("list_price").innerHTML = result[1];
        if (document.getElementById("sale_price")) document.getElementById("sale_price").innerHTML = result[2];
        if (document.getElementById("product_price"+result[3])) document.getElementById("product_price"+result[3]).innerHTML = result[0];
        if (document.getElementById("sale_price"+result[3])) document.getElementById("sale_price"+result[3]).innerHTML = result[2];
}

function cb_getResult (txt) {
        document.getElementById("message").innerHTML = txt;
}

function cb_revResult (txt) {
        eval(txt);
}

function cb_payResult (txt) {
        if (txt != "ok") {
                document.getElementById("message").innerHTML = txt;
        } else {
                document.forms['payment'].submit();
        }
}

function rowVisibility (strVisibility, intRowIndex) {
        if (navigator.product == "Gecko" && navigator.productSub && navigator.productSub > "20041010" && (navigator.userAgent.indexOf("rv:1.8") != -1 || navigator.userAgent.indexOf("rv:1.9") != -1)) {
                document.getElementById("cc_table").rows[intRowIndex].style.visibility = strVisibility;
        } else if (strVisibility == "visible") {
                if(document.all && document.compatMode && document.compatMode == "CSS1Compat" && !window.opera) {
                        document.getElementById("cc_table").rows[intRowIndex].style.display = "block";
                } else if (document.getElementById && document.getElementById("cc_table").rows) {
                        document.getElementById("cc_table").rows[intRowIndex].style.display = "table-row";
                }
        } else if (strVisibility == "collapse") {
                document.getElementById("cc_table").rows[intRowIndex].style.display = "none";
        }
}

function cc_type (val) {
        if (val == 'Solo' || val == 'Switch') {
                rowVisibility('visible', 5);
                rowVisibility('visible', 6);
        } else {
                rowVisibility('collapse', 5);
                rowVisibility('collapse', 6);
        }
}

function clearMessages () {
        document.getElementById("message").innerHTML = '';
}

function updatePrice (frm, url) {
        var e = frm.elements;
        var opts = [];
        var post;
        for (i=0; i<e.length; i++) {
                if (e[i].type == 'select-one') {
                        opts.push(e[i].name+"="+e[i].value);
                }
                if ((e[i].type == 'radio' || e[i].type == 'checkbox') && e[i].checked) {
                        opts.push(e[i].name+"="+e[i].value);
                }
        }
        post = opts.join("&");
        loadDoc(url, post, 'updatePrice');
}

function check_payment (url) {
        var e = document.forms['payment'].elements;
        var data = [];
        var post;
        for (i=0; i<e.length; i++) data.push(e[i].name+"="+e[i].value);
        post = data.join("&");
        loadDoc(url, post, 'payResult');
}

function edit_event (id) {
        loadDoc('index.php?l=edit_registry', 'id='+id, 'revResult');
}

function hold_order () {
        loadDoc('checkout.php?l=hold_order', '', 'revResult');
}

function ajaxPost (frm, url, result) {
        if (!result) result = 'getResult';
        var e = frm.elements;
        var data = [];
        var post;
        for (i=0; i<e.length; i++) {
                if ((e[i].type == 'checkbox' && e[i].checked) || e[i].type != 'checkbox') {
                        data.push(e[i].name+"="+e[i].value);
                }
        }
        post = data.join("&");
        loadDoc(url, post, result);
}

function pause (form_name, perform) {
        form = document.forms[form_name];
        ajaxPost(form, 'index.php?l=loading', 'revResult');
        setTimeout("ajaxPost(form, '"+perform+"', 'revResult')", 2000);
}

function toggle_country (value, type) {
        if (value != def_country && value != alt_country && value != "") {
                document.getElementById(type+'_other').style.display = 'inline';
                document.getElementById(type+'_state').style.display = 'none';
                document.forms['customer_info'].elements['userinfo['+type+'_oset]'].value = '1';
        } else {
                document.getElementById(type+'_other').style.display = 'none';
                document.getElementById(type+'_state').style.display = 'inline';
                document.forms['customer_info'].elements['userinfo['+type+'_oset]'].value = '0';
        }
}

function reset_forms (items, form) {
        for (x in items) {
                var titem = items[x];
                var fitem = document.forms[form].elements[titem];
                if (fitem.selectedIndex != null)
                        fitem.selectedIndex = 0;
                else
                        fitem.value = '';
        }
}

function bill_to_ship (form) {
        if (form.elements['userinfo[same]'].checked) {
                form.elements['userinfo[ship_first_name]'].value                = form.elements['userinfo[bill_first_name]'].value;
                form.elements['userinfo[ship_last_name]'].value                 = form.elements['userinfo[bill_last_name]'].value;
                form.elements['userinfo[ship_company_name]'].value              = form.elements['userinfo[bill_company_name]'].value;
                form.elements['userinfo[ship_address1]'].value                  = form.elements['userinfo[bill_address1]'].value;
                form.elements['userinfo[ship_address2]'].value                  = form.elements['userinfo[bill_address2]'].value;
                form.elements['userinfo[ship_city]'].value                              = form.elements['userinfo[bill_city]'].value;
                form.elements['userinfo[ship_state]'].selectedIndex             = form.elements['userinfo[bill_state]'].selectedIndex;
                form.elements['userinfo[ship_other]'].value                             = form.elements['userinfo[bill_other]'].value;
                form.elements['userinfo[ship_zip]'].value                               = form.elements['userinfo[bill_zip]'].value;
                form.elements['userinfo[ship_country]'].selectedIndex   = form.elements['userinfo[bill_country]'].selectedIndex;
                toggle_country(form.elements['userinfo[ship_country]'].value, 'ship');
        }
}

function popupImage (full_url, url) {
         window.open(full_url+'index.php?l=product_images&'+url,'popupImage','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150');
}

function reload_image (prefix, num) {
        var stamp = getstamp();
        document.images['verify_image'+num].src = prefix+'include/classes/class.iverify.php?'+stamp;
        if (bName == "MSIE" && bVer == 6) {
                alert('Image Reloaded Successfully!');
        }
}

function toggle_div (fname) {
        if (document.getElementById(fname).style.display == 'block')
                document.getElementById(fname).style.display = 'none';
        else 
                document.getElementById(fname).style.display = 'block';
}

//-->