//-----------------------------------------------------------------------------
// togglelayer : toggle login and order tracking layer when user not logged in
//-----------------------------------------------------------------------------
function togglelayer(param) 
{
    if (param == "login") 
    {
        if (document.getElementById('ctl00_logindrop').style.display == "none") 
        {
            //alert("show login");
            document.getElementById('ctl00_logindrop').style.display = "block";
            if (document.getElementById('ctl00_ordertrackdrop').style.display == "block") 
            {
                document.getElementById('ctl00_ordertrackdrop').style.display = "none";
            }
        }
        else 
        {
            //alert("hide login ");
            document.getElementById('ctl00_logindrop').style.display = "none";
        }
    }
    if (param == "trackorder") 
    {
        if (document.getElementById('ctl00_ordertrackdrop').style.display == "none") 
        {
            //alert("show order");
            document.getElementById('ctl00_ordertrackdrop').style.display = "block";
            if (document.getElementById('ctl00_logindrop').style.display == "block") 
            {
                document.getElementById('ctl00_logindrop').style.display = "none";
            }
        }
        else 
        {
            //alert("hide order");
            document.getElementById('ctl00_ordertrackdrop').style.display = "none";
        }
    }
}

function postLogin(usr, pwd) 
{
    //alert(usr+" - " +pwd);
    var f = document.loginfm;
    f.ctl00$MainContent$LoginForm$UserName.value=usr;
    f.ctl00$MainContent$LoginForm$Password.value=pwd;
    f.submit();

}

//-----------------------------------------------------------------------------
// runFlash : script for running home flash banner
//-----------------------------------------------------------------------------
function runFlash() {
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ');
    document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ');
    document.write(' width="722" height="261" id="sparts_banner" align="middle">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="allowFullScreen" value="false" />');
    document.write('<param name="movie" value="banner.swf" /><param name="quality" value="high" />');
    document.write('<param name="bgcolor" value="#ffffff" />');
    document.write('<param name="wmode" value="opaque" />');
    document.write('<param name="wmode" value="transparent" />');
    document.write('<embed src="sparts_banner.swf" wmode="opaque" quality="high" bgcolor="#ffffff" ');
    document.write('width="722" height="261" name="sparts_banner" align="middle" allowScriptAccess="sameDomain" ');
    document.write('allowFullScreen="false" type="application/x-shockwave-flash" ');
    document.write('pluginspage="http://www.adobe.com/go/getflashplayer" />');
    document.write('</object>');
}

//-----------------------------------------------------------------------------
// Search > hideAlldiv: hide smart search layer
//-----------------------------------------------------------------------------
function hideAlldiv() {
  document.getElementById('ctl00_step1').style.display='block';

    document.getElementById('ctl00_ss_model').style.color = "#999999";
    document.getElementById('ctl00_ss_model').value = "MODEL # Search";
    document.getElementById('smartmodel').style.display='none';

    document.getElementById('ctl00_ss_part').style.color = "#999999";
    document.getElementById('ctl00_ss_part').value = "PART # Search";
    document.getElementById('smartpart').style.display='none';
    document.getElementById('ctl00_partsugg').style.display='none';
    document.getElementById('ctl00_morepart').style.display='none';

  if (document.getElementById('smartkeyword').style.display=='block') {
    document.getElementById('ctl00_ss_keyword').style.color = "#999999";
    document.getElementById('ctl00_ss_keyword').value = "KEYWORD Search";
    document.getElementById('smartkeyword').style.display='none';
    document.getElementById('ctl00_keywordsugg').style.display='none';
  }
  if (document.getElementById('ctl00_ss_model').value == "" ||
      document.getElementById('ctl00_ss_part').value == "" ||
      document.getElementById('ctl00_ss_keyword').value == "" ) {
      document.getElementById('ctl00_ss_model').style.color = "#999999";
      document.getElementById('ctl00_ss_part').style.color = "#999999";
      document.getElementById('ctl00_ss_keyword').style.color = "#999999";
      document.getElementById('ctl00_ss_model').value = "MODEL # Search";
      document.getElementById('ctl00_ss_part').value = "PART # Search";
      document.getElementById('ctl00_ss_keyword').value = "KEYWORD Search";
  }
  if (document.getElementById("ctl00_MainContent_drpMMM") != null) {
      document.getElementById("ctl00_MainContent_drpMMM").style.display = "block";
  }
}

//-----------------------------------------------------------------------------
// Search > ajax calling for model, part, keyword and quick search
//-----------------------------------------------------------------------------
var model_return_cnt = 0;
var onlymodelid = "";
var onlymodelname = "";
function ajaxFunction(mode, key, key2, evt) {
    var evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (mode == "modelsearch" || mode == "partsearch") {
        if (evt.keyCode == 13) {
            return;
        }
    }
    if (key == "" || key == "MODEL # Search" || key == "PART # Search" || key == "Enter Spec #" || key == "KEYWORD Search") {
        //alert("not valid keyword");
        document.getElementById('smartmodel').style.display = "none";
        document.getElementById('smartpart').style.display = "none";
        document.getElementById('ctl00_partsugg').style.display = 'none';
        document.getElementById('ctl00_morepart').style.display = 'none';
        document.getElementById('smartkeyword').style.display = "none";
        document.getElementById('ctl00_keywordsugg').style.display = 'none';
        return;
    }
    //var dummystring = Math.floor(Math.random() * 11);
    var xmlHttp = initxmlHttp();
    var ret;
    var final_ret;
    var arrret=new Array(4);

    //ignore < >
    key = key.replace("<", "").replace(">", "");    
    // for model search
    if (mode == "modelsearch") {
        key = key.replace("-", "");
        //alert(key);
        if (trim(key) != "" && trim(key).length > 2) {
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    ret = xmlHttp.responseText;
                    //alert("ret=" + ret);
                    arrret = ret.split("^", 4);
                    model_return_cnt = arrret[0];
                    final_ret = arrret[3];
                    if (final_ret == null || final_ret == "") {
                        document.getElementById("smartmodel").style.display = "none";
                        return;
                    } else {
                        document.getElementById('smartmodel').innerHTML = final_ret;
                        document.getElementById("smartmodel").style.display = "block";
                        if (document.getElementById("ctl00_MainContent_drpMMM") != null) {
                            document.getElementById("ctl00_MainContent_drpMMM").style.display = "none";
                        }
                    }
                    if (model_return_cnt == "1") {
                        //document.getElementById("ctl00_ss_model").value = arrret[2];
                        //document.getElementById('ctl00_modelovergo').style.display = "block";
                        onlymodelid = arrret[1];
                        onlymodelname = arrret[2];
                    } else {
                        //document.getElementById('ctl00_modelovergo').style.display = "none";
                        onlymodelid = "";
                        onlymodelname = "";
                    }
                }
            }
            xmlHttp.open("GET", "/ajax/_ajax.aspx?mode=modelsearch&ss_model=" + key + "&searchkey=" + key2, true);
            xmlHttp.send(null);
        } else {
            document.getElementById('ctl00_ss_model').focus();
            document.getElementById("smartmodel").style.display = "none";
            return;
        }
    }
    // for Part Search
    else if (mode == "partsearch") {
        if (trim(key) != "" && trim(key).length > 2) {
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    ret = xmlHttp.responseText;
                    if (trim(ret) != "noresult") {
                        document.getElementById('smartpart').innerHTML = xmlHttp.responseText;
                        document.getElementById("smartpart").style.display = "block";
                        document.getElementById('ctl00_partsugg').style.display = 'block';
                        document.getElementById('ctl00_morepart').style.display = 'block';
                    } else {
                        document.getElementById("smartpart").style.display = "none";
                        document.getElementById('ctl00_partsugg').style.display = 'none';
                        document.getElementById('ctl00_morepart').style.display = 'none';
                    }
                }
            }
            xmlHttp.open("GET", "/ajax/_ajax.aspx?mode=partsearch&ss_part=" + key + "&searchkey=" + key2, true);
            xmlHttp.send(null);
        } else {
            document.getElementById('ctl00_ss_part').focus();
            return;
        }
    }
    // for keyword Search
    else if (mode == "keywordsearch") {
    if (trim(key) != "" && key != "KEYWORD Search" && trim(key).length > 2) {
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    ret = xmlHttp.responseText;
                    if (trim(ret) != "noresult") {
                        document.getElementById('smartkeyword').innerHTML = xmlHttp.responseText;
                        document.getElementById("smartkeyword").style.display = "block";
                        //document.getElementById('ctl00_keywordgo').style.display = 'block';
                        document.getElementById('ctl00_keywordsugg').style.display = 'block';
                    } else {
                        //document.getElementById('ctl00_keywordgo').style.display = 'block';
                        document.getElementById("smartkeyword").style.display = "none";
                        document.getElementById('ctl00_keywordsugg').style.display = 'none';
                    }
                }
            }
            xmlHttp.open("GET", "/ajax/_ajax.aspx?mode=keywordsearch&ss_keyword=" + key + "&searchkey=" + key2, true);
            xmlHttp.send(null);
        } else {
            document.getElementById('ctl00_ss_keyword').focus();
            return;
        }
    }
} // End of AjaxFunction

function initxmlHttp() {
    //alert(3434);
    var xmlHttp;
    try {  // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {  // Internet Explorer  
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support this functionality!");
                return false;
            }
        }
    }
    return xmlHttp;     
}

//-----------------------------------------------------------------------------
// Search > fetch result for model, part, keyword search
//-----------------------------------------------------------------------------
function checkEnter(evt, flag) {
    //alert(flag);
    var val = "";
    if (flag == "model") {
        val = document.getElementById('ctl00_ss_model').value;
        if (evt.keyCode == 13) {
            if(val=="MODEL # Search") {
                alert("Please enter valid model #.");
                return false;
            }
            else {
                if (val.length > 2) {
                    document.getElementById('smartmodel').style.display = "none";
                    fetchModel("", "");
                    return false;
                }
                else {
                    alert("Please enter more than 2 characters.");
                    return false;
                }
            }
        }
    }
    else if (flag == "part") {
        val = document.getElementById('ctl00_ss_part').value;
        if (evt.keyCode == 13) {
            if (val.length > 2) {
                fetchPart(val);
                return false;
            }
            else {
                alert("Please enter more than 2 characters.");
                return false;
            }
        }
    }
    else if (flag == "keyword") {
        val = document.getElementById('ctl00_ss_keyword').value;
        if (evt.keyCode == 13) {
            if (val.length > 2) {
                fetchKeyword(val);
                return false;
            }
            else {
                alert("Please enter more than 2 characters.");
                return false;
            }
        }
    }
    else {
        return false;
    }
}

function fetchModel(param1, param2) {
    // param1: model oid, param2: model name
    //alert("1: " + param1 + " 2: " + param2);
    if (document.getElementById("ctl00_MainContent_drpMMM") != null) {
        document.getElementById("ctl00_MainContent_drpMMM").style.display = "block";
    }
    document.getElementById('smartmodel').style.display = "none";
    var model = param2;
    if (model == "MODEL # Search") {
        alert("Please enter valid model #.");
        return false;
    }
    else{
        if (model == "") {
            model = document.getElementById('ctl00_ss_model').value;
            if (model == "MODEL # Search") {
                alert("Please enter valid model #.");
                return false;
            }
            else {
                if (trim(model).length < 3) {
                    alert("Please enter more than 2 characters.");
                    return false;
                }
                else {
                    //alert("fetch model submit");
                    document.getElementById('smartmodel').style.display = "none";
                    location.href = "/ModelList.aspx?Catalog=Parts_and_Accessories&model=" + model;
                    //alert(urlencode(model));
                    return false;
                }
            }
        }
        else {
            if (trim(model).length < 3) {
                alert("Please enter more than 2 characters.");
                return false;
            }
        }
    }
    //location.href = "/PartsList.aspx?Catalog=Parts_and_Accessories&Category=" + model;
    location.href = "/Products/Parts_and_Accessories/" + model + "/Default.aspx";
    //alert(urlencode(model));
    return false;
}

function fetchPart(param1) {
    var searchkey = null;
    var searchflag = null;
    if (trim(param1).length < 3) {
        alert("Search keyword should be more than 2 chracters.");
        return false;
    }
    var ssp = document.getElementById('ctl00_ss_part').value;
    if (ssp != "PART # Search" && trim(ssp) != "") {
        document.getElementById('smartpart').style.display = "none";
        document.getElementById('ctl00_partsugg').style.display = 'none';
        document.getElementById('ctl00_morepart').style.display = 'none';
        searchkey = trim(param1);
        searchflag = "bypartno";
        //location.href = "/search.aspx";
        //location.href = "/search.aspx?searchkey=" + searchkey + "&searchflag=" + searchflag;
        //Added by Raji
        location.href = "/PartsList.aspx?Catalog=Parts_and_Accessories&PartSearch=" + searchkey;
        return false;
    } else {
        alert("Please enter valid part # or specification.");
        return false;
    }
}

function keywordEnter(param, evt) {
    var evt = (evt) ? evt : ((window.event) ? window.event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if (evt.keyCode == 13) {
        if (trim(param) == "" || param == "KEYWORD Search") {
            alert("Please enter valid keyword.");
            document.getElementById('ctl00_ss_keyword').focus();
            return false;
        } else {
            getDivision(param);
        }
    }
}

function getDivision(keyword) {
    //alert(keyword);
    if (trim(keyword) == "" || keyword == "KEYWORD Search") {
        alert("Please enter valid keyword.");
        document.getElementById('ctl00_ss_keyword').focus();
        return false;
    } else {
        document.getElementById('ctl00_key_searchkey').value = keyword;
        document.getElementById('ctl00_step1').style.display = "none";
        document.getElementById('ctl00_step2').style.display = "block";
        //alert("keyword=" + keyword);
    }
}

function fetchKeyword(keyword) {
    var searchkey = keyword; //document.getElementById('ctl00_key_searchkey').value;
    //location.href = "/test.aspx?modelid=" + modelid + "&searchkey=" + searchkey + "&searchflag=bykeyword";
    //Added by Raji
    if (trim(keyword) == "" || keyword == "KEYWORD Search") {
        alert("Please enter valid keyword.");
        document.getElementById('ctl00_ss_keyword').focus();
        return false;
    } else {
        document.getElementById('smartkeyword').style.display = "none";
        document.getElementById('ctl00_keywordsugg').style.display = "none";
        location.href = "/PartsList.aspx?Catalog=Parts_and_Accessories&SearchKey=" + searchkey;
        return false;
    }
}

//-----------------------------------------------------------------------------
// Search > Remove Text : when cursor focuses on search input box
//-----------------------------------------------------------------------------
function removetext(flag) {
    //alert(flag);
    if (flag == "model")
    {
        if (document.getElementById('ctl00_ss_model').value == "MODEL # Search")
        {
            document.getElementById('ctl00_ss_model').value = "";
            document.getElementById('ctl00_ss_model').style.color = "#333333";
        }
        document.getElementById('ctl00_step1').style.display='block';
        document.getElementById('ctl00_ss_part').style.color = "#999999";
        document.getElementById('ctl00_ss_part').value = "PART # Search";
        document.getElementById('smartpart').style.display = 'none';
        document.getElementById('ctl00_partsugg').style.display = 'none';
        document.getElementById('ctl00_morepart').style.display = 'none';
        //document.getElementById('ctl00_keywordgo').style.display = 'none';
        document.getElementById('ctl00_ss_keyword').style.color = "#999999";
        document.getElementById('ctl00_ss_keyword').value = "KEYWORD Search";
        document.getElementById('smartkeyword').style.display='none';
        document.getElementById('ctl00_keywordsugg').style.display = 'none';
        return false;
    /*<%if hidedropdownlist = "yes" Then%>
    document.fm_view.view.style.visibility = 'visible';
    document.fm_sort.sortkey.style.visibility = 'visible';
    <%end if%>*/
    }
    else if (flag == "part") {
        if (document.getElementById('ctl00_ss_part').value == "PART # Search")
        {
            document.getElementById('ctl00_ss_part').value = "";
            document.getElementById('ctl00_ss_part').style.color = "#333333";
        }
        document.getElementById('ctl00_step1').style.display = 'block';
        document.getElementById('ctl00_ss_model').style.color = "#999999";
        document.getElementById('ctl00_ss_model').value = "MODEL # Search";
        document.getElementById('smartmodel').style.display='none';
        //document.getElementById('ctl00_keywordgo').style.display = 'none';
        document.getElementById('ctl00_ss_keyword').style.color = "#999999";
        document.getElementById('ctl00_ss_keyword').value = "KEYWORD Search";
        document.getElementById('smartkeyword').style.display='none';
        document.getElementById('ctl00_keywordsugg').style.display = 'none';
        return false;
    /*<%if hidedropdownlist = "yes" Then%>
    document.fm_view.view.style.visibility = 'visible';
    document.fm_sort.sortkey.style.visibility = 'visible';
    <%end if%>*/
    }
    else if (flag == "keyword") {
        if (document.getElementById('ctl00_ss_keyword').value == "KEYWORD Search")
        {
            document.getElementById('ctl00_ss_keyword').value = "";
            document.getElementById('ctl00_ss_keyword').style.color = "#333333";
        }
        document.getElementById('ctl00_ss_part').style.color = "#999999";
        document.getElementById('ctl00_ss_part').value = "PART # Search";
        document.getElementById('smartpart').style.display='none';
        document.getElementById('ctl00_partsugg').style.display = 'none';
        document.getElementById('ctl00_morepart').style.display = 'none';
        document.getElementById('ctl00_ss_model').style.color = "#999999";
        document.getElementById('ctl00_ss_model').value = "MODEL # Search";
        document.getElementById('smartmodel').style.display = 'none';
        return false;
    /*<%if hidedropdownlist = "yes" Then%>
    document.fm_view.view.style.visibility = 'visible';
    document.fm_sort.sortkey.style.visibility = 'visible';
    <%end if%>*/
    }
    else 
    {
        return false;
    }
}

//-----------------------------------------------------------------------------
// Utility functions
//-----------------------------------------------------------------------------
function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}

//-----------------------------------------------------------------------------
// Email Validation
//-----------------------------------------------------------------------------
function checkEMailVlidation(strings) {
    var i;
    var check = 0;
    var dot = 0;
    var before = "";
    var after = "";

    if (strings.length == 0) return (false);

    for (i = 0; i < strings.length; i++) {
        if (strings.charAt(i) == '@') { check = check + 1; }
        else if (check == 0) { before = before + strings.charAt(i); }
        else if (check == 1) { after = after + strings.charAt(i); }
    }

    if (check >= 2 || check == 0) {
        return (false);
    }

    if (before.length < 1 || after.length < 1) {
        return (false);
    }

    for (i = 0; i < before.length; i++) {
        if (!((before.charAt(i) >= 'A' && before.charAt(i) <= 'z') ||
			(before.charAt(i) >= '0' && before.charAt(i) <= '9') ||
			(before.charAt(i) == '_') || (before.charAt(i) == '-') ||
			(before.charAt(i) == '.'))) {
            return (false);
        }
    }

    for (i = 0; i < after.length; i++) {
        if (!((after.charAt(i) >= 'A' && after.charAt(i) <= 'z') ||
			(after.charAt(i) >= '0' && after.charAt(i) <= '9') ||
			(after.charAt(i) == '_') || (after.charAt(i) == '.') ||
			(after.charAt(i) == '-'))) {
            return (false);
        }
    }

    for (i = 0; i < after.length; i++) {
        if (after.charAt(i) == '.') {
            dot = dot + 1;
        }
    }

    if (dot < 1) {
        return (false);
    }

    return (true);
}

function getArticleDetail(title, dt, file, fm) {
    document.getElementById('ctl00_MainContent_art_title').value = title;
    document.getElementById('ctl00_MainContent_art_date').value = dt;
    document.getElementById('ctl00_MainContent_art_file').value = file;
    document.getElementById('ctl00_MainContent_art_view').value = "detail";
    fm.submit();
}

function refineSearch () {
    if (document.getElementById("ctl00_MainContent_txtRefineKey").value == "Enter Keyword") {
        alert("Please enter a valid keyword.");
        return false;
    } else {
        document.forms[0].submit();
    }
}

function clearEnterKeyword() {
    if (document.getElementById("ctl00_MainContent_txtRefineKey").value == "Enter Keyword") {
        document.getElementById("ctl00_MainContent_txtRefineKey").value = ''; 
    }
    else {
        return;
    }
}

function modelCodeValidate() {
    if (document.getElementById("ctl00_MainContent_drpModelCode").value == "Select Model Code") {
        alert("Please select model code.");
        return false;
    } else {
        document.forms[0].submit();
    }
}

//Toggle Refine Search
function ToggleSearch() {
   if (document.getElementById("ctl00_MainContent_tdSearch").style.display == "block") {
        document.getElementById("ctl00_MainContent_tdSearch").style.display = "none"
    }
    else {
       document.getElementById("ctl00_MainContent_tdSearch").style.display = "block"
   }
}

//Model Codes by Model No
function modelCodeSearch(key, evt) {
    //alert("key:|" + key + "|");
    //alert("event:" + evt.keyCode);
    var evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt.keyCode == 13) {
        //alert("enter key");
        return false;
    }    
    //if (key == "") return;
    var j;
    //var dummystring = Math.floor(Math.random() * 11);
    var xmlHttp = initxmlHttp();
    var ret;
    var final_ret;
    var arrret = new Array(4);
    var list = document.getElementById('ctl00_MainContent_drpModelCode');
 
    //key = key.replace("-", "");
    if (trim(key) != "" && key.length >= 3) {
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                ret = xmlHttp.responseText;
                //alert(ret);
                if (ret.length > 0 && ret != "No Model Code Found") {
                    arrret = ret.split(",");
                    //var newListItem = document.createElement('option');
                    //newListItem.text = 'All Model Codes';
                    //newListItem.value = 'All';
                    //list.options.add(newListItem);

                    for (var i = list.length - 1; i >= 0; i--) {
                        list.remove(i);
                    }

                    var k = 0;
                    for (j = 0; j < arrret.length; j++) {
                        var newListItem = document.createElement('option');
                        newListItem.text = arrret[j];
                        newListItem.value = arrret[j];
                        list.options.add(newListItem);
                    }
                    document.getElementById("ctl00_MainContent_drpModelCode").style.display = "block";
                    //document.getElementById("ctl00_MainContent_drpModelCode").disabled = false;
                }
                else {
                    for (var i = list.length - 1; i >= 0; i--) {
                        list.remove(i);
                    }
                    var newListItem = document.createElement('option');
                    newListItem.text = 'No Model Code Found';
                    newListItem.value = '';
                    list.options.add(newListItem);
                    //document.getElementById("ctl00_MainContent_drpModelCode").disabled = true;
                }
            }
        }
        xmlHttp.open("GET", "/ajax/_ajax.aspx?mode=modelcodesearch&ss_model=" + key, true);
        xmlHttp.send(null);
    } else if (trim(key)=="") {
        for (var i = list.length - 1; i >= 0; i--) {
            list.remove(i);
        }
        var newListItem = document.createElement('option');
        if (document.getElementById('ctl00_MainContent_drpModel') != null) {
            newListItem.text = 'Select Model# First';
        }
        else {
            newListItem.text = 'Enter Model# First';
        }
        newListItem.value = '';
        list.options.add(newListItem);
        //document.getElementById("ctl00_MainContent_drpModelCode").disabled = true;
    }    
    else {
        for (var i = list.length - 1; i >= 0; i--) {
            list.remove(i);
        }
        //alert("need more letters");
        var newListItem = document.createElement('option');
        newListItem.text = 'No Model Code Found';
        newListItem.value = '';
        list.options.add(newListItem);
        //document.getElementById("ctl00_MainContent_drpModelCode").disabled = true;
        document.getElementById('ctl00_MainContent_txtModelNo').focus();
        return;
    }
}

function getModelbyDivision(key, evt) {
    //alert(2323);
    var evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt.keyCode == 13) {
        alert("enter key");
        return false;
    }
    var xmlHttp = initxmlHttp();
    var ret;
    var j;
    var list = document.getElementById('ctl00_MainContent_drpModel');
    var key = document.getElementById('ctl00_MainContent_drpDivision').value;
    var parttype = document.getElementById('ctl00_MainContent_hiddenParttype').value;
    var arrret = new Array();
    //alert("key=" + key);
    if (key != "") {
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                ret = xmlHttp.responseText;
                alert("ret="+ret)
                if (ret.length > 0 && ret != "No Model Found") {
                    var tmp = "<select name='ctl00$MainContent$drpModel' id='ctl00_MainContent_drpModel'"
                        + " class='copy' style='width:136px;' "
                        + " onchange=\"modelCodeSearch(document.getElementById('ctl00_MainContent_drpModel').value, event);\">" 
                        + ret + "</select>";
                    document.getElementById('div_drpModel').innerHTML = tmp;                    
                    //                    for (var i = list.length - 1; i >= 0; i--) {
                    //                        list.remove(i);
                    //                    }
                    //                    arrret = ret.split(",");
                    //                    var k = 0;
                    //                    var newListItem = document.createElement('option');
                    //                    newListItem.text = "Select Model";
                    //                    newListItem.value = "";
                    //                    list.options.add(newListItem);
                    //                    for (j = 0; j < arrret.length; j++) {
                    //                        var newListItem = document.createElement('option');
                    //                        newListItem.text = arrret[j].split("^")[1];
                    //                        newListItem.value = arrret[j].split("^")[0];
                    //                        list.options.add(newListItem);
                    //                    }
                }
                else {
                    var tmp = "<select name='ctl00$MainContent$drpModel' id='ctl00_MainContent_drpModel'"
                        + " class='copy' style='width:136px;' "
                        + " onchange=\"modelCodeSearch(document.getElementById('ctl00_MainContent_drpModel').value, event);\">" 
                        + " <option value=''>No Model Found</option></select>";
                    document.getElementById('div_drpModel').innerHTML = tmp;
                    //                    for (var i = list.length - 1; i >= 0; i--) {
                    //                        list.remove(i);
                    //                    }
                    //                    var newListItem = document.createElement('option');
                    //                    newListItem.text = 'No Model Found';
                    //                    newListItem.value = '';
                    //                    list.options.add(newListItem);
                    //                    document.getElementById("ctl00_MainContent_drpModelCode").disabled = true;
                }
            }
        }
        xmlHttp.open("GET", "/ajax/_ajax.aspx?mode=quickmodelsearch&division=" + key + "&parttype=" + parttype, true);
        xmlHttp.send(null);
    }
    else {
        var tmp = "<select name='ctl00$MainContent$drpModel' id='ctl00_MainContent_drpModel'"
            + " class='copy' style='width:136px;' "
            + " onchange=\"modelCodeSearch(document.getElementById('ctl00_MainContent_drpModel').value, event);\">"
            + " <option value=''>Select Product First</option></select>";
        document.getElementById('div_drpModel').innerHTML = tmp;
        //        for (var i = list.length - 1; i >= 0; i--) {
        //            list.remove(i);
        //        }
        //        var newListItem = document.createElement('option');
        //        newListItem.text = 'Select Product First';
        //        newListItem.value = '';
        //        list.options.add(newListItem);

        //Empty Model Code Search Empty
        //        var list = document.getElementById('ctl00_MainContent_drpModelCode');
        //        for (var i = list.length - 1; i >= 0; i--) {
        //            list.remove(i);
        //        }
        //        var newListItem = document.createElement('option');
        //        newListItem.text = 'Select Model# First';
        //        newListItem.value = '';
        //        list.options.add(newListItem);
    }
    //Empty Model Code Search Empty
    var listMC = document.getElementById('ctl00_MainContent_drpModelCode');
    for (var i = listMC.length - 1; i >= 0; i--) {
        listMC.remove(i);
    }
    var newListItem = document.createElement('option');
    newListItem.text = 'Select Model# First';
    newListItem.value = '';
    listMC.options.add(newListItem);
}

//update in progress
function onUpdating() {
    var gridView = document.getElementById('ctl00_MainContent_gvPartsList');
    var updateProgressDiv = document.getElementById('ctl00_MainContent_UpdateProgress');

    var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);

    var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);

    Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
}

function toggleBrowseTab(param) {
    var arrh = new Array();
    arrh[0] = "tab_tvvideo";
    arrh[1] = "tab_mobile";
    arrh[2] = "tab_photo";
    arrh[3] = "tab_office";
    arrh[4] = "tab_appliance";
    
    var arrqTab = new Array();
    arrqTab[0] = "ctl00_MainContent_tvvideo";
    arrqTab[1] = "ctl00_MainContent_mobile";
    arrqTab[2] = "ctl00_MainContent_photo";
    arrqTab[3] = "ctl00_MainContent_office";
    arrqTab[4] = "ctl00_MainContent_appliance";
    
    var imgPath = new String();
    var i;
    for (i = 0; i < 5; i++) {
        if (arrqTab[i] == param) {
            document.getElementById(arrqTab[i]).style.display = "block";
            document.getElementById(arrh[i]).style.backgroundImage = "url(Images/site/tab_selected_bg.png)";
            document.getElementById(arrh[i]).style.color = "#ffffff";
        }
        else {
            document.getElementById(arrqTab[i]).style.display = "none";
            document.getElementById(arrh[i]).style.backgroundImage = "url(Images/site/tab_unselected_bg.gif)";
            document.getElementById(arrh[i]).style.color = "#666666";
        }
    } 
}

//-----------------------------------------------------------------------------
// Enter key control functions
//-----------------------------------------------------------------------------
//function stopRKey(evt) {
//    var evt = (evt) ? evt : ((window.event) ? window.event : null);
//    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
//    //alert("here: " + node.name);
//    if ((evt.keyCode == 13) && (node.type == "text") && (node.name == "ctl00$ss_model")) 
//    {
//        //alert("key="+model_return_cnt);
//        if (model_return_cnt == "1") 
//        {
//            //alert(onlymodelid+"one result, enter enable"+onlymodelname);
//            fetchModel(onlymodelid, onlymodelname);
//        }
//        else
//            return false;
//    } 
//    else if ((evt.keyCode == 13) && (node.type == "text") && (node.name == "ctl00$ss_part")) 
//    {
//        //alert("part key=" + node.value);
//        fetchPart(node.value);
//    }
//    else if ((evt.keyCode == 13) && (node.type == "text") && (node.name == "ctl00$ss_keyword")) {
//        //alert("keyword key=" + node.value);
//        fetchKeyword(node.value);
//    }
//}

//Open image in new window
function OpenLargeImage(info) {
    //window.open(img, 'newwindow', config = 'left=230,top=100,height=650,width=650, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no');
    win = window.open(info, 'DetailedView', "toolbar=no, width=700, height=600, resizable=yes, menubars=no, status=no, location=no, scrollbars=yes, top=80, left=200");

}

//Open detailed description for featured item from part detail page
function DetailedDesc(param) {
    window.open(param, 'detaileddesc', config = 'left=230,top=100,height=650,width=900, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no');
}

//check data for shippping calculator
function checkdata() {
      if (document.getElementById("txtZipCode").value.toUpperCase() != "APO" && document.getElementById("txtZipCode").value.toUpperCase() != "FPO") {
        if (document.getElementById("drpCountry").options[0].selected && document.getElementById("txtZipCode").value.length != 5)
         {
            alert("Please enter a valide zip code.");
            document.getElementById("txtZipCode").focus();
            return false;
        } else {
            return;
        }
    } else {
        return;
    }
}

function shippingPopupBasket() 
{
    window.open("/CalculateShipping.aspx?mode=basket", 'Shipping', config = 'left=200,top=80,height=550,width=500, toolbar=no, menubar=yes, scrollbars=yes, resizable=yes,location=no, directories=no, status=no');
}

function shippingPopupPart(oversize, weight, w, h, l, price, pid)
{
    window.open('/CalculateShipping.aspx?mode=parts&oversize=' + oversize + '&weight=' + weight + '&w=' + w + '&h=' + h + '&l=' + l + '&price=' + price + '&pid=' + pid, 'Shipping', config = 'left=200,top=80,height=550,width=500, toolbar=no, menubar=yes, scrollbars=yes, resizable=yes,location=no, directories=no, status=no');
}

function openIns(link) {
    var newwindow = window.open(link, "st3", "toolbar=no,width=500,height=700,resizable=1,menubars=0,statusbars=0,location=0,scrollbars=1");
    newwindow.focus();
}

function checkb2binfo() {
    var f = document.aspnetForm;
    //alert(f.ctaxid.value.length);
    if (f.ctl00$MainContent$cname.value.length == 0) {
        f.ctl00$MainContent$cname.value = f.ctl00$MainContent$ufname.value + " " + f.ctl00$MainContent$ulname.value;
        if (trim(f.ctl00$MainContent$cname.value).length == 0) {
            alert("Please enter business name.");
            f.ctl00$MainContent$cname.focus();
            return false;
        }
    }
    if (f.ctl00$MainContent$caddr.value.length == 0) {
        alert("Please enter business address.");
        f.ctl00$MainContent$caddr.focus();
        return false;
    }
    if (f.ctl00$MainContent$ccity.value.length == 0) {
        alert("Please enter business city.");
        f.ctl00$MainContent$ccity.focus();
        return false;
    }
    if (f.ctl00$MainContent$cstate.options[0].selected) {
        alert("Please select business state.");
        f.ctl00$MainContent$cstate.focus();
        return false;
    }
    if (f.ctl00$MainContent$czip.value.length == 0) {
        alert("Please enter business zip code.");
        f.ctl00$MainContent$czip.focus();
        return false;
    }
    if (f.ctl00$MainContent$ctaxid.value.length == 0) {
        alert("Please enter business tax ID number.");
        f.ctl00$MainContent$ctaxid.focus();
        return false;
    }
    if (f.ctl00$MainContent$ufname.value.length == 0) {
        alert("Please enter contact first name.");
        f.ctl00$MainContent$ufname.focus();
        return false;
    }
    if (f.ctl00$MainContent$ulname.value.length == 0) {
        alert("Please enter contact last name.");
        f.ctl00$MainContent$ulname.focus();
        return false;
    }
    if (f.ctl00$MainContent$uphone.value.length == 0) {
        alert("Please enter contact phone number.");
        f.ctl00$MainContent$uphone.focus();
        return false;
    }
    if (f.ctl00$MainContent$ufax.value.length == 0) {
        alert("Please enter contact fax number.");
        f.ctl00$MainContent$ufax.focus();
        return false;
    }
    if (f.ctl00$MainContent$uemail.value.length == 0) {
        alert("Please enter contact email address.");
        f.ctl00$MainContent$uemail.focus();
        return false;
    }
    if (!checkEMailVlidation(f.ctl00$MainContent$uemail.value)) {
        alert("Please input a valid email address.");
        f.ctl00$MainContent$uemail.focus();
        return false;
    }
    if (f.ctl00$MainContent$upwd.value.length == 0) {
        alert("Please enter password.");
        f.ctl00$MainContent$upwd.focus();
        return false;
    }
    if (f.ctl00$MainContent$upwd.value.length < 6) {
        alert("Password should be at least 6 characters.");
        f.ctl00$MainContent$upwd.focus();
        return false;
    }
    if (f.ctl00$MainContent$upwd_confirm.value.length == 0) {
        alert("Please enter confirm password.");
        f.ctl00$MainContent$upwd_confirm.focus();
        return false;
    }
    if (f.ctl00$MainContent$upwd_confirm.value != f.ctl00$MainContent$upwd.value) {
        alert("Password don't match. Please enter password again.");
        f.ctl00$MainContent$upwd_confirm.value = "";
        f.ctl00$MainContent$upwd.value = "";
        f.ctl00$MainContent$upwd.focus();
        return false;
    }
    
    // resale certificate verification
    //alert(f.ctl00$MainContent$cstate.value);
    if(f.ctl00$MainContent$cstate.value=="NJ"){
        if (f.ctl00$MainContent$st_auth_num.value.length == 0) {
		alert("Please enter Authority Number.");
		f.ctl00$MainContent$st_auth_num.focus();
		return false;
	    }
	    if (f.ctl00$MainContent$st_biznature.value.length == 0) {
		    alert("Please enter item (2).");
		    f.ctl00$MainContent$st_biznature.focus();
		    return false;
	    }
	    if (f.ctl00$MainContent$st_bizpurcahse.value.length == 0) {
		    alert("Please enter item (3).");
		    f.ctl00$MainContent$st_bizpurcahse.focus();
		    return false;
	    }
	    if (f.ctl00$MainContent$st_bizpurcahse.value.length > 4000) {
		    alert("You can only enter up to 4000 characters for item (3).");
		    f.ctl00$MainContent$st_bizpurcahse.focus();
		    return false;
		}
		if (!f.ctl00$MainContent$st_four_a.checked &&
	        !f.ctl00$MainContent$st_four_b.checked &&
	        !f.ctl00$MainContent$st_four_c.checked) {
		    alert("Please check at least one for item (4).");
		    f.ctl00$MainContent$st_four_a.focus();
		    return false;
		}
	    if (!f.ctl00$MainContent$st_disclaimer.checked) {
		    alert("Please read and confirm the disclaimer.");
		    f.ctl00$MainContent$st_disclaimer.focus();
		    return false;
	    }
	    if (f.ctl00$MainContent$st_name.value.length == 0) {
		    alert("Please enter name.");
		    f.ctl00$MainContent$st_name.focus();
		    return false;
	    }
	    if (f.ctl00$MainContent$st_address.value.length == 0) {
		    alert("Please enter address.");
		    f.ctl00$MainContent$st_address.focus();
		    return false;
	    }
	    if (f.ctl00$MainContent$st_signature.value.length == 0) {
		    alert("Please enter signature(name).");
		    f.ctl00$MainContent$st_signature.focus();
		    return false;
	    }
	    if (f.ctl00$MainContent$st_title.value.length == 0) {
		    alert("Please enter title.");
		    f.ctl00$MainContent$st_title.focus();
		    return false;
		}
    }
    else {
        if (f.ctl00$MainContent$stnr_name.value.length == 0) {
            alert("Please enter name.");
            f.ctl00$MainContent$stnr_name.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_location.value.length == 0) {
            alert("Please enter Business Location.");
            f.ctl00$MainContent$stnr_location.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_regi_state.value.length == 0) {
            alert("Please enter State(s) of Registration.");
            f.ctl00$MainContent$stnr_regi_state.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_regi_num.value.length == 0) {
            alert("Please enter Registration Number(s).");
            f.ctl00$MainContent$stnr_regi_num.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_biztype.value.length == 0) {
            alert("Please enter Type of Business.");
            f.ctl00$MainContent$stnr_biztype.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_desc1.value.length == 0) {
            alert("Please enter Description.");
            f.ctl00$MainContent$stnr_desc1.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_desc2.value.length == 0) {
            alert("Please enter Description.");
            f.ctl00$MainContent$stnr_desc2.focus();
            return false;
        }
        if (!f.ctl00$MainContent$stnr_disclaimer.checked) {
            alert("Please read and confirm the disclaimer.");
            f.ctl00$MainContent$stnr_disclaimer.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_signature.value.length == 0) {
            alert("Please enter signature(name).");
            f.ctl00$MainContent$stnr_signature.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_title.value.length == 0) {
            alert("Please enter title.");
            f.ctl00$MainContent$stnr_title.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_date.value.length == 0) {
            alert("Please enter date.");
            f.ctl00$MainContent$stnr_date.focus();
            return false;
        }
        if (f.ctl00$MainContent$stnr_address.value.length == 0) {
            alert("Please enter address.");
            f.ctl00$MainContent$stnr_address.focus();
            return false;
        }
    }
    //f.ctl00$MainContent$mode.value = "1";
    return true;
}

function SetUniqueRadioButton(nameregex, current,hdnAddressID,AddressId)
{  
    re = new RegExp(nameregex);
    for(i = 0; i < document.forms[0].elements.length; i++)
    {
        elm = document.forms[0].elements[i] 
        if (elm.type == 'radio')
        {
            if (re.test(elm.name))
            {
                elm.checked = false;
            }
        }
    }
    current.checked = true; 
    document.getElementById(hdnAddressID).value = AddressId; 
}

function SetUniqueCustomPayment(nameregex, current, hdnSelectedID, PaymentID) {

    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
    document.getElementById(hdnSelectedID).value = PaymentID;
    //SetCustomPaymentOptions(AddressId);
}

//function SetCustomPaymentOptions(AddressId) {
//    if(AddressId == "Prepaid Cash" || AddressId == "Prepaid Check" || AddressId == "Net30")
//    {
//        if (document.getElementById("ctl00_MainContent_ChkBillAddr") != null)
//        {
//            document.getElementById("ctl00_MainContent_ChkBillAddr").style.display = "block";
//        }
//        if (document.getElementById("ctl00_MainContent_ChkShipAddr") != null)
//        {
//            document.getElementById("ctl00_MainContent_ChkShipAddr").style.display = "block";
//        }
//    }
//    else
//    {
//        if (document.getElementById("ctl00_MainContent_ChkBillAddr") != null)
//        {
//            document.getElementById("ctl00_MainContent_ChkBillAddr").style.display = "block";
//        }
//        if (document.getElementById("ctl00_MainContent_ChkShipAddr") != null)
//        {
//            document.getElementById("ctl00_MainContent_ChkShipAddr").style.display = "block";
//        }
//    }
//}

function selectShippingMethod(ShippingMethodID, ShippingRate, ShippingMethodClientID, ShippingRateClientID) {
    /*if (document.getElementById("ctl00_MainContent_Shipping_SingleShipping_hdnShippingMethodID") != null) {
        document.getElementById("ctl00_MainContent_Shipping_SingleShipping_hdnShippingMethodID").value = ShippingMethodID;
    }
    if (document.getElementById("ctl00_MainContent_Shipping_SingleShipping_hdnShippingRate") != null) {
        document.getElementById("ctl00_MainContent_Shipping_SingleShipping_hdnShippingRate").value = ShippingRate;
    }*/

    if (document.getElementById(ShippingMethodClientID) != null) {
        document.getElementById(ShippingMethodClientID).value = ShippingMethodID;
    }
    if (document.getElementById(ShippingRateClientID) != null) {
        document.getElementById(ShippingRateClientID).value = ShippingRate;
    }
    SetShippingTotal(ShippingRate);
}

function selectShippingMethod22(param) {
    //alert(param);
    var arrret = new Array(3);
    arrret = param.split("|", 4);
    if (document.getElementById(arrret[2]) != null) {
        document.getElementById(arrret[2]).value = arrret[0];
    }
    if (document.getElementById(arrret[3]) != null) {
        document.getElementById(arrret[3]).value = arrret[1];
    }
    SetShippingTotal(arrret[1]);    
}

function selectShippingMethod23(param) {
    //alert(param);
    var arrret = new Array(3);
    
    arrret = param.split("|", 4);
    if (document.getElementById(arrret[2]) != null) {
        document.getElementById(arrret[2]).value = arrret[0];
    }
    if (document.getElementById(arrret[3]) != null) {
        document.getElementById(arrret[3]).value = arrret[1];
    }
    //alert("0=" + arrret[0] + "  //  " + "1=" + arrret[1] + "  //  " + "2=" + arrret[2] + "  //  " + "3=" + arrret[3]);
    //alert("hdnShippingMethodID = " + document.getElementById('ctl00_MainContent_hdnShippingMethodID').value + " hdnShippingRate = " + document.getElementById('ctl00_MainContent_hdnShippingRate').value);
    
    SetShippingTotal(arrret[1].replace('$',''));
}

function selectShippingMethodforOrder(param) {
    //alert(param);
    var arrret = new Array(1);

    arrret = param.split("|");
    //alert(arrret[0]+arrret[1]);
    if (document.getElementById('ctl00_MainContent_hdnSelectedShipId') != null) {
        document.getElementById('ctl00_MainContent_hdnSelectedShipId').value = arrret[0];
    }
    if (document.getElementById('ctl00_MainContent_hdnSelectedShipRate') != null) {
        document.getElementById('ctl00_MainContent_hdnSelectedShipRate').value = arrret[1].replace('$','');
    }
    document.getElementById('ctl00_MainContent_txtShipping').value = arrret[1].replace('$', '');
    document.getElementById('ctl00_MainContent_txtTotal').value = Math.abs(document.getElementById('ctl00_MainContent_txtSubtotal').value) + Math.abs(arrret[1].replace("$", "")) + Math.abs(document.getElementById('ctl00_MainContent_txtHandling').value) + Math.abs(document.getElementById('ctl00_MainContent_txtTax').value);
    document.getElementById('ctl00_MainContent_txtTotal').value = parseFloat(document.getElementById('ctl00_MainContent_txtTotal').value).toFixed(2);
    //if(document.getElementById('ctl00_MainContent_lblQuoteNo')==null)
    if (document.getElementById('ctl00_MainContent_txtMemo').value.indexOf("Shipping Method Changed") == -1)
        document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Shipping Method Changed.";
}

function SetShippingTotal(ShippingTotal) {

    ShippingTotalID = "ctl00_MainContent_shippingTotal";
    GrandTotalID = "ctl00_MainContent_grandTotal";
    SubTotalID = "ctl00_MainContent_subTotal";
    TaxTotalID = "ctl00_MainContent_taxTotal";
    HandlingTotalID = "ctl00_MainContent_handlingTotal";

    if (document.getElementById(ShippingTotalID) != null) {
        if (document.all)
            document.getElementById(ShippingTotalID).innerText = ShippingTotal;  
        else
            document.getElementById(ShippingTotalID).textContent = ShippingTotal;  
    }

    if (document.getElementById(ShippingTotalID) != null && document.getElementById(GrandTotalID) != null
        && document.getElementById(SubTotalID) != null 
        && document.getElementById(TaxTotalID) != null && document.getElementById(HandlingTotalID) != null )
     {
        var shipTot = ShippingTotal;
        var taxTotal;
        var handlingTotal;
        var subTotal;        
        var cur = "$"; 
        if (document.all) {
            taxTotal = document.getElementById(TaxTotalID).innerText;
            handlingTotal = document.getElementById(HandlingTotalID).innerText;
            subTotal = document.getElementById(SubTotalID).innerText;
        } else {
            taxTotal = document.getElementById(TaxTotalID).textContent;
            handlingTotal = document.getElementById(HandlingTotalID).textContent; 
            subTotal = document.getElementById(SubTotalID).textContent;
        }
        if (handlingTotal == null || handlingTotal == '' || handlingTotal == '0') {
            handlingTotal = document.getElementById(HandlingTotalID).value;
        }
        shipTot = Math.abs(shipTot.toString().replace(cur, ''));
        subTot = Math.abs(subTotal.toString().replace(cur, ''));
        taxTot = Math.abs(taxTotal.toString().replace(cur, ''));
        handlingTot = Math.abs(handlingTotal.toString().replace(cur, ''));
        var total = parseFloat(subTot + shipTot + taxTot + handlingTot).toFixed(2);
        //alert(subTot + "+" + shipTot + "+" + taxTot + "+" + handlingTot+"="+total);
        if (document.all)
            document.getElementById(GrandTotalID).innerText = cur + total;
        else
            document.getElementById(GrandTotalID).textContent = cur + total;
    }
}

function DisplayCity(CountryDrpID, trDrpID, trTxtID) {    
    if (document.getElementById(CountryDrpID).value == "UNITED STATES") {
        document.getElementById(trDrpID).style.display = "block";
        document.getElementById(trTxtID).style.display = "none";        
    }
    else {
        document.getElementById(trDrpID).style.display = "none";
        document.getElementById(trTxtID).style.display = "block";
    }
}

//Postal Code Search for City and State
function postalCodeSearch(StateID, CityID, zipcodeID, countryID, evt) {
    var evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt.keyCode == 13) {
        return false;
    }  
    var j;
    //var dummystring = Math.floor(Math.random() * 11);
    var xmlHttp = initxmlHttp();
    var ret;
    var final_ret;
    var arrret = new Array(4);
    var zipcode, country, hdncity, hdnbcity, hdnscity;

    if (document.getElementById("ctl00_MainContent_Payment_PaymentManager_AddressManager_EditForm_CountryName") != null) {
        StateID = "ctl00_MainContent_Payment_PaymentManager_AddressManager_EditForm_RegionCodeTextBox";
        CityID = "ctl00_MainContent_Payment_PaymentManager_AddressManager_EditForm_CityList";
        zipcodeID = "ctl00_MainContent_Payment_PaymentManager_AddressManager_EditForm_PostalCodeTextBox";
        countryID = "ctl00_MainContent_Payment_PaymentManager_AddressManager_EditForm_CountryName";
        hdncity = "ctl00_MainContent_Payment_PaymentManager_AddressManager_EditForm_hdnCity";
    }
    else if (document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_CountryName") != null) {
        StateID = "ctl00_MainContent_Shipping_AddressManager_EditForm_RegionCodeTextBox";
        CityID = "ctl00_MainContent_Shipping_AddressManager_EditForm_CityList";
        zipcodeID = "ctl00_MainContent_Shipping_AddressManager_EditForm_PostalCodeTextBox";
        countryID = "ctl00_MainContent_Shipping_AddressManager_EditForm_CountryName";
        hdncity = "ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity";
    }
    else if (document.getElementById("ctl00_MainContent_AddressManager_EditForm_CountryName") != null) {
        StateID = "ctl00_MainContent_AddressManager_EditForm_RegionCodeTextBox";
        CityID = "ctl00_MainContent_AddressManager_EditForm_CityList";
        zipcodeID = "ctl00_MainContent_AddressManager_EditForm_PostalCodeTextBox";
        countryID = "ctl00_MainContent_AddressManager_EditForm_CountryName";
        hdncity = "ctl00_MainContent_AddressManager_EditForm_hdnCity";
    }

    if (document.getElementById(CityID) == null && document.getElementById(StateID) == null &&
       document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_CityList") != null &&
       document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_RegionCodeTextBox") != null) {
        CityID = "ctl00_MainContent_Shipping_AddressManager_EditForm_CityList";
        StateID = "ctl00_MainContent_Shipping_AddressManager_EditForm_RegionCodeTextBox";
        zipcode = document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_PostalCodeTextBox").value;
        country = document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_CountryName").value;
        hdncity = "ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity";
    }
    else {
        zipcode = document.getElementById(zipcodeID).value;
        country = document.getElementById(countryID).value;
        if (document.getElementById("ctl00_MainContent_EditForm_hdnCity") != null)
            hdncity = "ctl00_MainContent_EditForm_hdnCity";
        else if (document.getElementById("ctl00_MainContent_BUSCityLabel") != null) {
            hdnbcity = "ctl00_MainContent_BUSCityLabel";
            hdnscity = "ctl00_MainContent_SUSCityLabel";
        }
    }
    
    var list = document.getElementById(CityID);
    if (trim(zipcode) != "" && zipcode.length >= 5 && trim(country) != "" && trim(country) == "UNITED STATES") {
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                ret = xmlHttp.responseText;
                if (ret.length > 0 && ret != "No City Found") {
                    arrret = ret.split(",");
                    for (var i = list.length - 1; i >= 0; i--) {
                        list.remove(i);
                    }
                    for (j = 1; j < arrret.length; j++) {
                        var newListItem = document.createElement('option');
                        newListItem.text = arrret[j];
                        newListItem.value = arrret[j];
                        list.options.add(newListItem);
                    }
                    document.getElementById(CityID).style.display = "block";
                    document.getElementById(CityID).disabled = false;
                    document.getElementById(StateID).style.display = "block";
                    document.getElementById(StateID).value = arrret[0];
                    if (document.getElementById("ctl00_MainContent_BUSCityLabel") != null) {
                        document.getElementById(hdnbcity).value = list.options[0].value;
                    }
                    else if (document.getElementById("ctl00_MainContent_SUSCityLabel") != null) {
                        document.getElementById(hdnscity).value = list.options[0].value;
                    }
                    else {
                        document.getElementById(hdncity).value = list.options[0].value;
                    }
                    //                    if (document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity") != null) {
                    //                        document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity").value = list.options[0].value;
                    //                    }
                    //                    if (document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity") != null) {
                    //                        document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity").value = list.options[0].value;
                    //                    }

                    //document.getElementById(StateID).disabled = true;
                    //stateCodeSearch(StateID, zipcode, country, evt);
                }
                else {
                    for (var i = list.length - 1; i >= 0; i--) {
                        list.remove(i);
                    }
                    var newListItem = document.createElement('option');
                    newListItem.text = 'No City Found';
                    newListItem.value = '';
                    list.options.add(newListItem);
                    document.getElementById(CityID).disabled = true;
                }
            }
        }
        xmlHttp.open("GET", "/ajax/_ajax.aspx?mode=citycodesearch&zipcode=" + zipcode, true);
        xmlHttp.send(null);
    } else if (trim(zipcode) == "") {
        if (list != null) {
            for (var i = list.length - 1; i >= 0; i--) {
                list.remove(i);
            }
            var newListItem = document.createElement('option');
            newListItem.text = 'Enter ZipCode First';
            newListItem.value = '';
            list.options.add(newListItem);
            document.getElementById(CityID).disabled = true;
            if (document.getElementById("ctl00_MainContent_BUSCityLabel") != null) {
                document.getElementById(hdnbcity).value = "";
            }
            else if (document.getElementById("ctl00_MainContent_SUSCityLabel") != null) {
                document.getElementById(hdnscity).value = "";
            }
            else {
                document.getElementById(hdncity).value = "";
            }
//            if (document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity") != null) {
//                document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity").value = "";
//            }
//            if (document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity") != null) {
//                document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity").value = "";
//            }
        }
        //document.getElementById(StateID).value = "";
        //document.getElementById(StateID).disabled = false;
    }
    else {
        //alert("need more letters");
        if (list != null) {
            for (var i = list.length - 1; i >= 0; i--) {
                list.remove(i);
            }
            var newListItem = document.createElement('option');
            newListItem.text = 'No City Found';
            newListItem.value = '';
            list.options.add(newListItem);
            document.getElementById(CityID).disabled = true;
            if (document.getElementById("ctl00_MainContent_BUSCityLabel") != null) {
                document.getElementById(hdnbcity).value = "";
            }
            else if (document.getElementById("ctl00_MainContent_SUSCityLabel") != null) {
                document.getElementById(hdnscity).value = "";
            }
            else {
                document.getElementById(hdncity).value = "";
            }
//            if (document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity") != null) {
//                document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity").value = "";
//            }
//            if (document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity") != null) {
//                document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity").value = "";
//            }
        } 
        //document.getElementById(StateID).value = "";
        //document.getElementById(StateID).disabled = false;  
        return;
    }
}

function setCityHiddenValue(strcity) {
    //alert(strcity);
    var hdncity;
    if (document.getElementById("ctl00_MainContent_Payment_PaymentManager_AddressManager_EditForm_hdnCity") != null) {
        hdncity = "ctl00_MainContent_Payment_PaymentManager_AddressManager_EditForm_hdnCity";
    }
    else if (document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity") != null) {
        hdncity = "ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity";
    }
    else if (document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity") != null) {
        hdncity = "ctl00_MainContent_AddressManager_EditForm_hdnCity";
    }
    document.getElementById(hdncity).value = strcity;
    
    
    
//    if (document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity") != null) {
//        document.getElementById("ctl00_MainContent_AddressManager_EditForm_hdnCity").value = strcity;
//    }
//    if (document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity") != null) {
//        document.getElementById("ctl00_MainContent_Shipping_AddressManager_EditForm_hdnCity").value = strcity;
//    }
}




/*
function stateCodeSearch(StateID, zipcode, country, evt) {    
    var evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt.keyCode == 13) {
        return false;
    }
    var j;
    //var dummystring = Math.floor(Math.random() * 11);
    var xmlHttp = initxmlHttp();
    var ret;
    var final_ret;
    var arrret = new Array(4);
    var list = document.getElementById(StateID);

    if (trim(zipcode) != "" && zipcode.length == 5 && trim(country) != "" && trim(country) == "UNITED STATES") {
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                ret = xmlHttp.responseText;
                if (ret.length > 0 && ret != "") {
                    document.getElementById(StateID).value = ret;
                    document.getElementById(StateID).style.display = "block";
                    document.getElementById(StateID).disabled = false;
                }
                else {
                    document.getElementById(StateID).value = '';
                    document.getElementById(StateID).disabled = true;
                }
            }
        }
        xmlHttp.open("GET", "/ajax/_ajax.aspx?mode=statecodesearch&zipcode=" + zipcode, true);
        xmlHttp.send(null);
    } else if (trim(zipcode) == "") {
        document.getElementById(StateID).value = '';
        document.getElementById(StateID).disabled = true;
    }
    else {
        //alert("need more letters");
        document.getElementById(StateID).value = '';
        document.getElementById(StateID).disabled = true;
        return;
    }
}
*/

function goPartTypeSearch(key) {
    location.href = "/PartsList.aspx?PartType=" + key;
}

// For Exploded View: BOM List background color change as location selected.
var preparam = '';
var prei = 0;
function changebg(param) {
    var i = 0;
    var x = document.getElementsByName(param).length;
    //alert(x+" : current="+param+" & "+prei+" : pre="+preparam);
    if (preparam != '' && prei != 0) {
        for (i = 0; i < prei; i++) {
            document.getElementById(preparam + "_" + i + "a").style.backgroundColor = '';
            document.getElementById(preparam + "_" + i + "b").style.backgroundColor = '';
            document.getElementById(preparam + "_" + i + "c").style.backgroundColor = '';
        }
        preparam = '';
        prei = 0;
    }
    //alert("h1");
    if (param != '' && param != 'NoLocation') {
        //alert("h2");
        if (x == 0) {
            //alert("h3");
            alert("We can't find a location number for this part. please contact us at 1-800-627-4368.");
            preparam = '';
            prei = 0;
            return;
        } else {
            //alert("h4 : "+x);
            for (i = 0; i < x; i++) {
                //alert("h5 : "+param+"_"+i+"a");
                document.getElementById(param + "_" + i + "a").style.backgroundColor = '#ffe13b';
                document.getElementById(param + "_" + i + "b").style.backgroundColor = '#ffe13b';
                document.getElementById(param + "_" + i + "c").style.backgroundColor = '#ffe13b';
            }
            preparam = param;
            prei = x;
        }
    } else {
        alert("We can't find a location number for this part. please contact us at 1-800-627-4368.");
        return;
    }
}
// End

function setRefineValue() {
    if (document.getElementById('ctl00_MainContent_ModelCodeLabel') != null
        && document.getElementById('ctl00_MainContent_drpModelCode') != null) {
        document.getElementById('ctl00_MainContent_ModelCodeLabel').value = document.getElementById('ctl00_MainContent_drpModelCode').value;
    }
    if (document.getElementById('ctl00_MainContent_hiddenmodelno') != null
        && document.getElementById('ctl00_MainContent_drpModel') != null) {
        document.getElementById('ctl00_MainContent_hiddenmodelno').value = document.getElementById('ctl00_MainContent_drpModel').value;
    }

    if (document.getElementById('ctl00_MainContent_drpDivision') != null
        && document.getElementById('ctl00_MainContent_drpModel') != null
        && document.getElementById('ctl00_MainContent_drpModelCode') != null) {
        if (document.getElementById('ctl00_MainContent_drpDivision').value != ""
            && document.getElementById('ctl00_MainContent_drpModel').value == "") {
            var selIndex = document.getElementById('ctl00_MainContent_drpModel').selectedIndex;
            var ttt = document.getElementById('ctl00_MainContent_drpModel').options[selIndex].text;
            if (ttt == "No Model Found") {
                alert("Currently, there is no matching part under the selected product. Please select another product.");
                document.getElementById('ctl00_MainContent_drpDivision').focus();
            }
            else {
                alert("Please select model.");
                document.getElementById('ctl00_MainContent_drpModel').focus();
            }
            return false;            
        }
    }
}

function setCityValue() {
    if (document.getElementById('ctl00_MainContent_SUSCityDrp') != null
        && document.getElementById('ctl00_MainContent_SUSCityLabel') != null) {
        document.getElementById('ctl00_MainContent_SUSCityLabel').value = document.getElementById('ctl00_MainContent_SUSCityDrp').value;
    }
    if (document.getElementById('ctl00_MainContent_BUSCityDrp') != null
        && document.getElementById('ctl00_MainContent_BUSCityLabel') != null) {
        document.getElementById('ctl00_MainContent_BUSCityLabel').value = document.getElementById('ctl00_MainContent_BUSCityDrp').value;
    }

    if (document.getElementById('ctl00_MainContent_EditForm_USCityDrp') != null
        && document.getElementById('ctl00_MainContent_EditForm_hdnCity') != null) {
        document.getElementById('ctl00_MainContent_EditForm_hdnCity').value = document.getElementById('ctl00_MainContent_EditForm_USCityDrp').value;
    }
    //return false;
}

function PopulateShippingAddress() {
    //alert(2);
    //alert(document.getElementById('ctl00_MainContent_chkSameAddress').checked);
    if (document.getElementById('ctl00_MainContent_chkSameAddress') != null &&
    document.getElementById('ctl00_MainContent_chkSameAddress').checked) {
        if (document.getElementById('ctl00_MainContent_BCompanyTextBox') != null
            && document.getElementById('ctl00_MainContent_SCompanyTextBox') != null) {
            document.getElementById('ctl00_MainContent_SCompanyTextBox').value = document.getElementById('ctl00_MainContent_BCompanyTextBox').value;
        }
        if (document.getElementById('ctl00_MainContent_BFirstNameTextBox') != null
            && document.getElementById('ctl00_MainContent_SFirstNameTextBox') != null) {
            document.getElementById('ctl00_MainContent_SFirstNameTextBox').value = document.getElementById('ctl00_MainContent_BFirstNameTextBox').value;
        }
        if (document.getElementById('ctl00_MainContent_BLastNameTextBox') != null
            && document.getElementById('ctl00_MainContent_SLastNameTextBox') != null) {
            document.getElementById('ctl00_MainContent_SLastNameTextBox').value = document.getElementById('ctl00_MainContent_BLastNameTextBox').value;
        }
        if (document.getElementById('ctl00_MainContent_SAddressLine1TextBox') != null
            && document.getElementById('ctl00_MainContent_BAddressLine1TextBox') != null) {
            document.getElementById('ctl00_MainContent_SAddressLine1TextBox').value = document.getElementById('ctl00_MainContent_BAddressLine1TextBox').value;
        }
        if (document.getElementById('ctl00_MainContent_SAddressLine2TextBox') != null
            && document.getElementById('ctl00_MainContent_BAddressLine2TextBox') != null) {
            document.getElementById('ctl00_MainContent_SAddressLine2TextBox').value = document.getElementById('ctl00_MainContent_BAddressLine2TextBox').value;
        }
        if (document.getElementById('ctl00_MainContent_SCountryName') != null
            && document.getElementById('ctl00_MainContent_BCountryName') != null) {
            document.getElementById('ctl00_MainContent_SCountryName').value = document.getElementById('ctl00_MainContent_BCountryName').value;
        }
        if (document.getElementById('ctl00_MainContent_SPostalCodeTextBox') != null
            && document.getElementById('ctl00_MainContent_BPostalCodeTextBox') != null) {
            document.getElementById('ctl00_MainContent_SPostalCodeTextBox').value = document.getElementById('ctl00_MainContent_BPostalCodeTextBox').value;
        }
        if (document.getElementById('ctl00_MainContent_SRegionCodeTextBox') != null
            && document.getElementById('ctl00_MainContent_BRegionCodeTextBox') != null) {
            document.getElementById('ctl00_MainContent_SRegionCodeTextBox').value = document.getElementById('ctl00_MainContent_BRegionCodeTextBox').value;
        }
        if (document.getElementById('ctl00_MainContent_SCityTextBox') != null
            && document.getElementById('ctl00_MainContent_BCityTextBox') != null) {
            document.getElementById('ctl00_MainContent_SCityTextBox').value = document.getElementById('ctl00_MainContent_BCityTextBox').value;
        }
        if (document.getElementById('ctl00_MainContent_STelephoneNumberTextBox') != null
            && document.getElementById('ctl00_MainContent_BTelephoneNumberTextBox') != null) {
            document.getElementById('ctl00_MainContent_STelephoneNumberTextBox').value = document.getElementById('ctl00_MainContent_BTelephoneNumberTextBox').value;
        }

        zipcode = document.getElementById('ctl00_MainContent_BPostalCodeTextBox').value;
        country = document.getElementById('ctl00_MainContent_BCountryName').value;
        postalCodeSearch('ctl00_MainContent_SRegionCodeTextBox', 'ctl00_MainContent_SUSCityDrp', 'ctl00_MainContent_SPostalCodeTextBox', 'ctl00_MainContent_SCountryName', this);

        DisplayCity('ctl00_MainContent_SCountryName', 'ctl00_MainContent_scitydrp', 'ctl00_MainContent_scitytxt');

        if (document.getElementById('ctl00_MainContent_SUSCityLabel') != null
            && document.getElementById('ctl00_MainContent_BUSCityDrp') != null) {
            document.getElementById('ctl00_MainContent_SUSCityDrp').value = document.getElementById('ctl00_MainContent_BUSCityLabel').value;
        }

        if (document.getElementById('ctl00_MainContent_SUSCityLabel') != null
            && document.getElementById('ctl00_MainContent_BUSCityLabel') != null) {
            document.getElementById('ctl00_MainContent_SUSCityLabel').value = document.getElementById('ctl00_MainContent_BUSCityLabel').value;
        }
    }
    else {
        document.getElementById('ctl00_MainContent_SCompanyTextBox').value = "";
        document.getElementById('ctl00_MainContent_SFirstNameTextBox').value = "";
        document.getElementById('ctl00_MainContent_SLastNameTextBox').value = "";
        document.getElementById('ctl00_MainContent_SAddressLine1TextBox').value = "";
        document.getElementById('ctl00_MainContent_SAddressLine2TextBox').value = "";
        document.getElementById('ctl00_MainContent_SCountryName').value = "UNITED STATES";
        document.getElementById('ctl00_MainContent_SPostalCodeTextBox').value = "";
        document.getElementById('ctl00_MainContent_SRegionCodeTextBox').value = "";
        document.getElementById('ctl00_MainContent_SCityTextBox').value = "";
        document.getElementById('ctl00_MainContent_STelephoneNumberTextBox').value = "";
        document.getElementById('ctl00_MainContent_SUSCityDrp').value = "";
        document.getElementById('ctl00_MainContent_SUSCityLabel').value = "";
    }
}   

function urlencode(string) {
	var utftext = "";
	string = string.replace(/\r\n/g,"\n");

	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return escape(utftext);
}

function urldecode(utftext) {
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;

    while (i < utftext.length) {

        c = utftext.charCodeAt(i);

        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        }
        else if ((c > 191) && (c < 224)) {
            c2 = utftext.charCodeAt(i + 1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        }
        else {
            c2 = utftext.charCodeAt(i + 1);
            c3 = utftext.charCodeAt(i + 2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    return string;
}

function chkall(name) {
    //alert(1);
    //alert(document.aspnetForm.allcheckbox.checked);
    var checkbox = document.aspnetForm.allcheckbox.checked;
    document.aspnetForm.allcheckbox.checked = checkbox;
    //form.checkall2.checked = checkall;
    count = document.all(name).length;
    //alert("cnt="+count)
    if (!count)
        document.getElementById(name).checked = checkbox;
    else if (count > 1)
        for (i = 0; i < count; i++)
            document.aspnetForm.ordcheckbox[i].checked = checkbox;
            //document.getElementsByName("invcheckbox")[i].checked = checkbox;
}

function checkboxmemo(flag) {
    if (flag == "ordcustcancel") {
        if (document.getElementById('ctl00_MainContent_chkCancel').checked) {
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Customer Want to Cancel.";
        }
        else {
            document.getElementById('ctl00_MainContent_txtMemo').value =
        document.getElementById('ctl00_MainContent_txtMemo').value.replace('Customer Want to Cancel.', '');
        }
    }
    else if (flag == "ordhold") {
        if (document.getElementById('ctl00_MainContent_chkHold').checked) {
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Temporary Hold Order.";
        }
        else {
            document.getElementById('ctl00_MainContent_txtMemo').value =
            document.getElementById('ctl00_MainContent_txtMemo').value.replace('Temporary Hold Order.', '');
        }
    }
    else if (flag == "ordpartial") {
        if (document.getElementById('ctl00_MainContent_chkPartial').checked) {
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + "Partial Order.";
        }
        else {
            document.getElementById('ctl00_MainContent_txtMemo').value =
            document.getElementById('ctl00_MainContent_txtMemo').value.replace('Partial Order.', '');
        }
    }
    else if (flag == "quotmail") {
        if (document.getElementById('ctl00_MainContent_chkMailedQuot').checked) {
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + "Mailed Quote.";
        }
        else {
            document.getElementById('ctl00_MainContent_txtMemo').value =
            document.getElementById('ctl00_MainContent_txtMemo').value.replace('Mailed Quote.', '');
        }
    }
    else if (flag == "quotcheck") {
        if (document.getElementById('ctl00_MainContent_chkRcvChk').checked) {
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + "Received Check.";
        }
        else {
            document.getElementById('ctl00_MainContent_txtMemo').value =
            document.getElementById('ctl00_MainContent_txtMemo').value.replace('Received Check.', '');
        }
    }
    else if (flag == "quotcancel") {
        if (document.getElementById('ctl00_MainContent_chkCustCancel').checked) {
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + "Cust Want to Cancel.";
        }
        else {
            document.getElementById('ctl00_MainContent_txtMemo').value =
            document.getElementById('ctl00_MainContent_txtMemo').value.replace('Cust Want to Cancel.', '');
        }
    }
}

function orderreopen() {
    var qa = confirm("Are you sure that you want to reopen this order?");
    if (qa) {
        document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Order Reopened.";
        //alert(1)
        return true;
    }
    else {
        return false;
    }
}

function ordercancel() {
    var qa = confirm("Are you sure that you want to cancel this order?");
    if (qa) {
        document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Order Cancelled.";
        //alert(1)
        return true;
    }
    else {
        return false;
    }
}

function paychange() {
    var con;
    //alert("value="+document.getElementById('ctl00_MainContent_drpPayType').options[0].value);
    if (document.getElementById('ctl00_MainContent_drpPayType').options[0].value == ""
        && document.getElementById('ctl00_MainContent_drpPayType').value != "") {
        con = confirm("The orginal payment has been deleted from customer profile. Therefore, you can't change back to the original payment method once you change it. Do you still want to change?");
    }
    else {
        con = true;
    }
    if(con) {
        if (document.getElementById('ctl00_MainContent_drpPayType').value == "Prepaid Check"
            || document.getElementById('ctl00_MainContent_drpPayType').value == "Net 30 Days") {
            document.getElementById('ctl00_MainContent_txtCheckNo').disabled = false;
            document.getElementById('ctl00_MainContent_txtCheckAmt').disabled = false;
            document.getElementById('ctl00_MainContent_txtCheckDate').disabled = false;
            document.getElementById('ctl00_MainContent_txtPaidAmount').disabled = true;
        }
        else {
            document.getElementById('ctl00_MainContent_txtCheckNo').value = "";            
            document.getElementById('ctl00_MainContent_txtCheckNo').disabled = true;
            document.getElementById('ctl00_MainContent_txtCheckAmt').disabled = true;
            document.getElementById('ctl00_MainContent_txtCheckDate').disabled = true;
            document.getElementById('ctl00_MainContent_txtPaidAmount').disabled = false;
            
        }
        document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Payment Method Changed.";
        return true;
    }
    else{
        document.getElementById('ctl00_MainContent_drpPayType').options[0].selected = true;
        return false;
    }
}

function orderHeadchange(flag) {
    if (flag == "custpo") {
        if (document.getElementById('ctl00_MainContent_txtMemo').value.indexOf("Customer PO# Changed") == -1)
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Customer PO# Changed.";
    }
    else if (flag == "shipfee") {
        if (document.getElementById('ctl00_MainContent_txtMemo').value.indexOf("Shipping Charge Changed") == -1)
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Shipping Charge Changed.";
    }
    else if (flag == "handfee") {
        if (document.getElementById('ctl00_MainContent_txtMemo').value.indexOf("Handling Charge Changed") == -1)
            document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Handling Charge Changed.";
    }
    return true;
}

function ccidControl() {
    var pt = document.getElementById('ctl00_MainContent_drpPayType').value;
    if (pt == "Prepaid Check" || pt == "Prepaid Cash" || pt == "Net 30 Days" || pt == "Amazon" || pt == "Paypal" || pt == "Buy.com") {
        document.getElementById('ctl00_MainContent_txtCCID').disabled = true;
    }
    else {
        document.getElementById('ctl00_MainContent_txtCCID').disabled = false;
    }
}

function addDash(fldid) {
    //alert(1);
    var len = trim(document.getElementById(fldid).value).length;
    if (len == 4) {
        document.getElementById(fldid).value = trim(document.getElementById(fldid).value) + "-";
    }
    else if (len == 9) {
        document.getElementById(fldid).value = trim(document.getElementById(fldid).value) + "-";
    }
    else if (len == 14) {
        document.getElementById(fldid).value = trim(document.getElementById(fldid).value) + "-";
    }
}

function OrderHeaderValidation() {
    var chkno = trim(document.getElementById('ctl00_MainContent_txtCheckNo').value);
    var chkamt = trim(document.getElementById('ctl00_MainContent_txtCheckAmt').value);
    var chkdate = trim(document.getElementById('ctl00_MainContent_txtCheckDate').value);
    if( chkno.length > 0 && (chkamt.length==0 || chkdate.length==0) ){
        alert("Please enter Check Amount and Date.");
        return false;
    }
    if (chkamt.length > 0 && (chkno.length == 0 || chkdate.length == 0)) {
        alert("Please enter Check Number and Date.");
        return false;
    }
    if (chkdate.length > 0 && (chkamt.length == 0 || chkno.length == 0)) {
        alert("Please enter Check Amount and Number.");
        return false;
    }
    document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + " Order Head Modified.";
    return true;
}

function QuoteHeaderValidation() {
    var chkno = trim(document.getElementById('ctl00_MainContent_txtCheckNo').value);
    var chkamt = trim(document.getElementById('ctl00_MainContent_txtCheckAmt').value);
    var chkdate = trim(document.getElementById('ctl00_MainContent_txtCheckDate').value);
    if (chkno.length > 0 && (chkamt.length == 0 || chkdate.length == 0)) {
        alert("Please enter Check Amount and Date.");
        return false;
    }
    if (chkamt.length > 0 && (chkno.length == 0 || chkdate.length == 0)) {
        alert("Please enter Check Number and Date.");
        return false;
    }
    if (chkdate.length > 0 && (chkamt.length == 0 || chkno.length == 0)) {
        alert("Please enter Check Amount and Number.");
        return false;
    }
    return true;
}

function fillPaidAmt() {
    var pt = document.getElementById('ctl00_MainContent_drpPayType').value;
    if (pt == "Prepaid Check" || pt == "Net 30 Days") {
        var chkamt = trim(document.getElementById('ctl00_MainContent_txtCheckAmt').value);
        document.getElementById('ctl00_MainContent_txtPaidAmount').value = chkamt;
    }
}

function InvoiceHeaderValidation() {
    if (document.getElementById('ctl00_MainContent_txtCheckAmtEdit') != null) {
        var chkno = trim(document.getElementById('ctl00_MainContent_txtCheckNumEdit').value);
        var chkamt = trim(document.getElementById('ctl00_MainContent_txtCheckAmtEdit').value);
        var chkdate = trim(document.getElementById('ctl00_MainContent_txtCheckDateEdit').value);

        if (chkno.length > 0 && (chkamt.length == 0 || chkdate.length == 0)) {
            alert("Please enter Check Amount and Date.");
            return false;
        }
        if (chkamt.length > 0 && (chkno.length == 0 || chkdate.length == 0)) {
            alert("Please enter Check Number and Date.");
            return false;
        }
        if (chkdate.length > 0 && (chkamt.length == 0 || chkno.length == 0)) {
            alert("Please enter Check Amount and Number.");
            return false;
        }
        return true;
    }
    else
        return true;
}

function orderAddrChange(flag) {
    var selectedid;
    var originalid;
    var memo;
    var con;
    if (flag == "bill") {
        selectedid = document.getElementById('ctl00_MainContent_drpBillAddr');
        originalid = document.getElementById('ctl00_MainContent_hdnOriginalBillAddrID');
        memo = " Billing Address Changed.";
    }
    else {
        selectedid = document.getElementById('ctl00_MainContent_drpShipAddr');
        originalid = document.getElementById('ctl00_MainContent_hdnOriginalShipAddrID');
        memo = " Shipping Address Changed.";
    }
    document.getElementById('ctl00_MainContent_txtMemo').value = document.getElementById('ctl00_MainContent_txtMemo').value + memo;
    if (selectedid.value != originalid.value && originalid.value.substring(0, 1) == "^") {
        con = confirm("The orginal address has been deleted from customer profile. Therefore, you can't change back to the original address once you change it. Do you still want to change?")
        if (con) {
            return true;
        }
        else {
            selectedid.options[0].selected = true;
            return false;
        }
    }
    else {
        return true;
    }
}

function setCookie(value) {
    var exdate = new Date();
    var expiredays = 1;
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = "JJ_SearchBar" + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function getCookie() {
    var c_name = "JJ_SearchBar";
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function toggleMainSearch() {
    var hl;    
    if(document.getElementById("ctl00_hltoggleSearch")!=null)
        hl = "ctl00_hltoggleSearch";
    else
        hl = "ctl00_MainContent_LoginForm_hltoggleSearch";
        
    if (document.getElementById("ctl00_searchcontainer").style.display == "block") {
        document.getElementById("ctl00_searchcontainer").style.display = "none";
        document.getElementById("ctl00_searchline").style.display = "block";        
        if (document.all)
            document.getElementById(hl).innerText = "Show Search";
        else
            document.getElementById(hl).textContent = "Show Search";
    }
    else {
        document.getElementById("ctl00_searchcontainer").style.display = "block"
        document.getElementById("ctl00_searchline").style.display = "none";
        if (document.all)
            document.getElementById(hl).innerText = "Hide Search";
        else
            document.getElementById(hl).textContent = "Hide Search";
    }
    return false;
}

function toggleMainSearch_Emp() {
    var hl;
    if (document.getElementById("ctl00_hltoggleSearch") != null)
        hl = "ctl00_hltoggleSearch";
    else
        hl = "ctl00_MainContent_LoginForm_hltoggleSearch";

    if (document.getElementById("ctl00_searchcontainer").style.display == "block") {
        document.getElementById("ctl00_searchcontainer").style.display = "none";
        document.getElementById("ctl00_searchline").style.display = "block";
        if (document.all)
            document.getElementById(hl).innerText = "Show Search";
        else
            document.getElementById(hl).textContent = "Show Search";
        setCookie("hide");
    }
    else {
        document.getElementById("ctl00_searchcontainer").style.display = "block"
        document.getElementById("ctl00_searchline").style.display = "none";
        if (document.all)
            document.getElementById(hl).innerText = "Hide Search";
        else
            document.getElementById(hl).textContent = "Hide Search";
        setCookie("show");
    }
    return false;
}

function filterascii(param) {
    var allascii = true;
    if (param.value != null && trim(param.value).length > 0) {
        var p = trim(param.value)
        for (var i = 0; i < p.length; i++) {
            var m = p.substring(i, i + 1).charCodeAt(0);
            if (m < 32 || m > 126) {
                allascii = false;
                break;
            }
        }
    }
    if (!allascii) {
        alert("Please use only Alphabetical letters.");
        param.value = "";
        param.focus();
        return false;
    }
    else
        return true;
}

function addClaimMemo(fld, flag) {
    //alert(1);
    var txtmemo = document.getElementById('ctl00_MainContent_txtMemo');
    if (flag == "reasonbankcarrier") {
        if (fld.options[0].text == "Select Return Reason") {
            if (txtmemo.value.indexOf("Reason Changed.") == -1)
                txtmemo.value = txtmemo.value + " Reason Changed.";
        }
        else if (fld.options[0].text == "Select Bank") {
            if (txtmemo.value.indexOf("Bank Changed.") == -1)
                txtmemo.value = txtmemo.value + " Bank Changed.";
        }
        else if (fld.options[0].text == "Select Carrier") {
            if (txtmemo.value.indexOf("Carrier Changed.") == -1)
                txtmemo.value = txtmemo.value + " Carrier Changed.";
        }
    }
    else if (flag == "condition") {
        if (txtmemo.value.indexOf("Condition Changed.") == -1)
            txtmemo.value = txtmemo.value + " Condition Changed.";
    }
    else if (flag == "actionreason") {
        if (fld.options[0].text == "Select Final Action") {
            if (txtmemo.value.indexOf("Final Action Changed.") == -1)
                txtmemo.value = txtmemo.value + " Final Action Changed.";
        }
        else {
            if (txtmemo.value.indexOf("Reason Changed.") == -1)
                txtmemo.value = txtmemo.value + " Reason Changed.";
        }
    }
    else if (flag == "result") {
        if (txtmemo.value.indexOf("Result Changed.") == -1)
            txtmemo.value = txtmemo.value + " Result Changed.";
    }
    else if (flag == "status") {
        if (txtmemo.value.indexOf("Status Changed.") == -1)
            txtmemo.value = txtmemo.value + " Status Changed.";
    }
}

//document.onkeypress = stopRKey;

