﻿function TextScrub(inText) {
    outText = inText.replace(/{/g, "(");
    outText = outText.replace(/}/g, ")");
    outText = outText.replace(/</g, "(");
    outText = outText.replace(/>/g, ")");
    outText = outText.replace(/%/g, " ");
    outText = outText.replace(/'/g, "\"");
    return outText;
}

function CheckFrames() {
    var redirectUrl;

    if (top.location.href.indexOf("Search_Models") < 0 && top.location.href.indexOf("Search_Model_Results") < 0) {
        if (top.location.pathname.substring(1, 4) == "MMS") {
            alert("MMS");
        }
        else {
            redirectUrl = top.location.protocol + "//" + top.location.host + "/Search_Model_Results.aspx?";

            param_ModelID = "ModelID=";
            param_ModelNum = "ModelNum=";
            param_mfgModelNum = "mfgModelNum=";
            param_ManufactureID = "ManufactureID=";
            param_Selected = "Selected=";
            param_Position = "Position=";
            param_mfg = "mfg=";
            param_Type = "Type=";
            param_Mark = "Mark=";
            var curParam;

            params = document.location.search.substring(1, 512);

            paramArray = params.split("&");

            k = paramArray.length;

            for (i = 0; i < k; i++) {
                curParam = TextScrub(unescape(paramArray[i]));

                if (curParam.indexOf('ModelID=') == 0) param_ModelID = curParam;
                if (curParam.indexOf('ModelNum=') == 0) param_ModelNum = curParam;
                if (curParam.indexOf('mfgModelNum=') == 0) param_mfgModelNum = curParam;
                if (curParam.indexOf('ManufactureID=') == 0) param_ManufactureID = curParam;
                if (curParam.indexOf('Selected=') == 0) param_Selected = curParam;
                if (curParam.indexOf('Position=') == 0) param_Position = curParam;
                if (curParam.indexOf('mfg=') == 0) param_mfg = curParam;
                if (curParam.indexOf('Type=') == 0) param_Type = curParam;
                if (curParam.indexOf('Mark=') == 0) param_Mark = curParam;
            }

            redirectUrl = redirectUrl + param_ModelID + '&' + param_ModelNum + '&' + param_mfgModelNum + '&' + param_ManufactureID + '&' + param_Selected + '&' + param_Position + '&' + param_mfg + '&' + param_Type + '&' + param_Mark;

            top.location.href = redirectUrl;

        }
    }
}

//date function
RightNow = new Date();
var themonth;
var ModelIsFocus;
var PartIsFocus;
var EmailFocus = false;
var SearchFocus = false;
var DefSearchFocus = false;

var month = RightNow.getMonth() + 1;
if (month == 1) themonth = "January";
if (month == 2) themonth = "February";
if (month == 3) themonth = "March";
if (month == 4) themonth = "April";
if (month == 5) themonth = "May";
if (month == 6) themonth = "June";
if (month == 7) themonth = "July";
if (month == 8) themonth = "August";
if (month == 9) themonth = "September";
if (month == 10) themonth = "October";
if (month == 11) themonth = "November";
if (month == 12) themonth = "December";

var date = RightNow.getDate();
var year = RightNow.getYear();
var day = RightNow.getDay();
if (year == 100) { year = "2000"; }
if (year == 101) { year = "2001"; }
if (year == 102) { year = "2002"; }
if (year == 103) { year = "2003"; }
if (year == 104) { year = "2004"; }
if (year == 105) { year = "2005"; }


function newWin(name, url, width, height, args) 
{
    var newWin = new Object();

    newWin.args = args;
    newWin.url = url;
    newWin.name = name;
    newWin.width = width;
    newWin.height = height;

    if (document.layers) {// browser is NN
        newWin.left = window.screenX + ((window.outerWidth - newWin.width) / 2);
        newWin.top = window.screenY + ((window.outerHeight - newWin.height) / 2);
        var attr = 'screenX=' + newWin.left + ',screenY=' + newWin.top + ',width=' + newWin.width + ',height=' + newWin.height + ',' + newWin.args;
    }
    else {// browser is MSIE
        newWin.left = (screen.width - newWin.width) / 2;
        newWin.top = (screen.height - newWin.height) / 2;
        var attr = 'left=' + newWin.left + ',top=' + newWin.top + ',resizable=yes,width=' + newWin.width + ',height=' + newWin.height + ',' + newWin.args;
    }

    newWin.win = window.open(newWin.url, newWin.name, attr);
    newWin.win.opener = self;
    newWin.win.focus();
}


function CheckFrameParent() {
    var redirectUrl;
    var midUrl;
    var imgNum;
    if (top.location.href.indexOf("ModelFrames") < 0) {
        redirectUrl = top.location.href;
        midUrl = top.location.href;
        midUrl = midUrl.substring(midUrl.indexOf("//") + 2, midUrl.length);
        midUrl = midUrl.substring(midUrl.indexOf("/") + 1, midUrl.indexOf(".aspx"));
        redirectUrl = redirectUrl.substring(0, redirectUrl.indexOf("&Mark"));
        redirectUrl = redirectUrl.replace(midUrl, "ModelFrames");
        midUrl = top.location.href;
        midUrl = midUrl.substring(midUrl.indexOf("&Mark") + 6, midUrl.indexOf("&Mark") + 7);
        redirectUrl = redirectUrl + "&Mark=" + midUrl;
        top.location.href = redirectUrl; // top.location.href.replace("PartLists","ModelFrames");			
        //top.location.href = top.location.href.substring(0, top.location.href.indexof("Type"));
    }
    //	if(self.location.href.indexOf("PartLists") > 0)
    //	{
    //		top.contents.location.replace("/FrameImgList.aspx?ModelID=145798&ModelNum=lat1000gge&ManufactureID=1&Selected=LW13-17&Position=0&mfg=Maytag&Type=Appliance#5");
    //	}

}


//Added on Dec 31, 2003 for combining the search boxes
function keyPress(key) {
    if (key == '13' && (EmailFocus == true || SearchFocus == true || DefSearchFocus == true)) {
        if (EmailFocus == true) {
            document.getElementById('infobar_btn_Submit').focus();
        }
        else if (SearchFocus == true) {
            document.getElementById('menu_SearchButton').focus();
            //	document.getElementById('menu_SearchButton').click();
        }
        else if (DefSearchFocus == true) {
            document.getElementById('ImageButton1').focus();
            //	document.getElementById('ImageButton1').click();				
        }
    }
    else if (key == '13') {
        document.getElementById('ImageButton1').focus();
    }
}


function Email_OnClick() {
    if (navigator.appName != "Netscape") {
        EmailFocus = true;
        SearchFocus = false;
    }
}


function Search_OnClick() {
    if (navigator.appName != "Netscape") {
        EmailFocus = false;
        SearchFocus = true;
    }
}


function DefModelSearch_OnClick() {
    if (navigator.appName != "Netscape") {
        EmailFocus = false;
        DefSearchFocus = true;
    }
}


function val_msg() {
    return true;
}	

