﻿var toCloseImg = "true";
function flip(divId) {
    var div = document.getElementById(divId);
    if (div.style.display == 'none')
        div.style.display = 'block';
    else
        div.style.display = 'none';
}

function ShowElement(divId) {
    var div = document.getElementById(divId);
    div.style.display = 'inline';
}

function HideElement(divId) {
    var div = document.getElementById(divId);
    div.style.display = 'none';
}
function isEnter(e) {
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) {
        return true;
    } else {
        return false;
    }
}
function OpenWindowWithParam(WindowName, ParamValue, cid, ptitle) {
    var newImg1 = new Image();
    var newUrl = ParamValue.replace("&IW=40", "");
    var newUrl = newUrl.replace("http://www.johnstonesupply.com/DesktopModules/webStore/Thumbnail.aspx?IP=", "http://www.johnstonesupply.com");
    newImg1.src = newUrl;
    var oManager = GetRadWindowManager();
    var oWindow = window.radopen(null, WindowName);
    oWindow.set_title(ptitle);
    oWindow.SetUrl(newUrl);
    if (newImg1.width != 0) {
        oWindow.SetWidth(newImg1.width + 50);
        oWindow.SetHeight(newImg1.height + 70);
    } else {
        oWindow.SetWidth(600);
        oWindow.SetHeight(600);
    }
    oWindow.set_offsetElementID(cid);
    oWindow.set_openerElementID(cid);
    toCloseImg = "true";
}
function OpenPDWindowWithParam(WindowName, ParamValue, cid, ptitle) {
    var newImg1 = new Image();
    var newUrl = ParamValue.replace("&IW=100", "");
    var newUrl = newUrl.replace("http://www.johnstonesupply.com/DesktopModules/webStore/Thumbnail.aspx?IP=", "http://www.johnstonesupply.com"); newImg1.src = newUrl;
    var oManager = GetRadWindowManager();
    var oWindow = window.radopen(null, WindowName);
    oWindow.set_title(ptitle);
    oWindow.SetUrl(newUrl);
    if (newImg1.width != 0) {
        oWindow.SetWidth(newImg1.width + 50);
        oWindow.SetHeight(newImg1.height + 70);
    } else {
        oWindow.SetWidth(600);
        oWindow.SetHeight(600);
    }
    oWindow.set_offsetElementID(cid);
    oWindow.set_openerElementID(cid);
    toCloseImg = "true";
}

function OpenWindow(WindowName) {
    window.radopen(null, WindowName);
}

function OpenPartWindow(part, cid) {
   
    var newUrl = '~/windows/ProductInfo.aspx?prodno=' + part;
    var oWindow = window.radopen(null, "radWindow2");
    oWindow.SetUrl(newUrl);
    oWindow.set_title(part + " Details");
    oWindow.SetWidth(540);
    oWindow.SetHeight(600);
    oWindow.set_offsetElementID(cid);
    oWindow.set_openerElementID(cid);
    

}

function CloseWindow(WindowName) {
    var oManager = GetRadWindowManager();
    var oWindow = oManager.GetWindowByName(WindowName);
    if (oWindow != null && toCloseImg == "true") {
        oWindow.Close();
        
    }
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function hasCookie(radtt) {
    var radtip = $find(radtt);
    var logincookie = readCookie("login");
    if (logincookie == null) {
        setTimeout("hasCookie('" + radtt + "')", 1000);
    } else {
        if (logincookie == "yes") {
      //     updateCart();
        //    updateShipMethods();
            radtip.hide();
           
        
        }

    }
}

function setToolTitle(title, tooltipid) {
    var tooltip = $find(tooltipid);
    tooltip.set_title(title);
}
function pausecomp(millis) {
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while (curDate - date < millis);
}
function logoff() {
    createCookie("login", "no", 999);
    eraseCookie("LoginDS");
    window.location = window.location;

}
function checkStore() {
  
    var locate = window.location;
    var storecookie = readCookie("store");
   // if (location != "http://devstore.johnstoneds.com:71/selectStore.aspx" && (storecookie == null || storecookie == "")) {
   //     window.location = "http://devstore.johnstoneds.com:71/selectStore.aspx";
   // }
}

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
    return null
}

function ShowPDToolTip(prodno, tooltipid) {
   
   // createCookie("pdetails", tooltipid, 999);
    //createCookie("currentpart", prodno, 999);
    //refreshPart(prodno);
 
   // var tid = readCookie("pdetails");
    var ptooltip = $find(tooltipid);
    // ptooltip.set_targetControlID(element.id);

    ptooltip.show();
    createCookie("mainContextMenu", "false", "1");
   // ptooltip.set_title(prodno + " Details");
  //      createCookie("priceTimer", "2", 999);

   
}
function findFocus() {
    // grab Id of form element with current focus
    for (var i = 0; i < document.forms.length; i++) {
        frm = document.forms[i];
        for (var j = 0; frm.elements.length; j++) {
            if (elm.focus == true) return frm.elements[j];
        }
    }
    return false;
}
function refreshPart(pnum) {
    //var PriceandCart = document.getElementById(readCookie("priceandcartClientID"));
    var RAPPartDesc = $find(readCookie("RAPPartDesc"));
    //var RAPAttributes = $find(readCookie("RAPAttributes"));
    var RTSProdDetails = $find(readCookie("RTSProdDetails"));
    //var RAPPriceAndCart = $find(readCookie("RAPPriceAndCart"));
    var tabs = RTSProdDetails.get_tabs();
    var descTab = tabs.getTab(0);
    descTab.select();
    //createCookie("pnum", pnum, 1);
    RAPPartDesc.ajaxRequest('product=' + pnum);
  //  RAPAttributes.ajaxRequest('product=' + pnum);
   // RAPPriceAndCart.ajaxRequest('product=' + pnum);
   // RAPAttributes.ajaxRequest('update');
}
function autoIframe(frameId) {
    try
{
    frame = parent.document.getElementById(frameId);
    innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
    objToResize = (frame.style) ? frame.style : frame;
    
    //if (screen.width < 1024 && screen.height < 768) {
    //    objToResize.height = parent.getWindowHeight();
    //    objToResize.width = parent.getWindowWidth();
   //    
   // } else {
   //     if (navigator.userAgent.indexOf("MSIE") != -1) {
    //        if (parent.getWindowHeight() < innerDoc.documentElement.scrollHeight) {
     //           objToResize.height = parent.getWindowHeight();
     //       } else {
    //            objToResize.height = innerDoc.documentElement.scrollHeight;
     //       }
//
    //    } else {
           //objToResize.height = "100%";
    //    objToResize.height = parent.getWindowHeight();
   //     }
    //  }


    var height = parent.window.innerHeight; //Firefox
 
    if (parent.document.body.clientHeight) {
        height = parent.document.body.clientHeight; //IE

    }
    //resize the iframe according to the size of the
    //window (all these should be on the same line)
    
    if (frame.style.height != parseInt(height - frame.offsetTop - 8) + "px") {
        frame.style.height = parseInt(height - frame.offsetTop - 8) + "px";
    }
    
    
}
  catch(err) {
  
   }

}

function getWindowHeight() {
    if (document.all) {
        return document.body.offsetHeight;
    }
    else {
        return window.innerHeight;
    }
}

function getWindowWidth() {
    if (document.all) {
        return document.body.offsetWidth;
    }
    else {
        return window.innerWidth;
    }
}



function Querystring(qs) { 
    this.params = {};

    if (qs == null) qs = location.search.substring(1, location.search.length);
    if (qs.length == 0) return;

    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); 


    for (var i = 0; i < args.length; i++) {
        var pair = args[i].split('=');
        var name = decodeURIComponent(pair[0]);

        var value = (pair.length == 2)
			? decodeURIComponent(pair[1])
			: name;

        this.params[name] = value;
    }
}

Querystring.prototype.get = function(key, default_) {
    var value = this.params[key];
    return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
    var value = this.params[key];
    return (value != null);
}


function resizeCurrentFrame() {
    var qs = new Querystring();
    var fid = qs.get("frameid");
  
    autoIframe(fid);
}


