var prodPopup = "";

function CheckModal() {
    if(prodPopup) {
        if(!(prodPopup.closed)) {
            prodPopup.focus(); 
        } 
    }
}

function WindowClosed() {
    if(prodPopup) {
        if(!(prodPopup.closed)) {
            prodPopup.close(); }
    }
}

function NavigateSelf(sURL) {
    document.location.href = sURL;
}

function clearMe(formControl)
{
    formControl.text = "";
}

function clearDefault(formControl, strDefault)
{
    if (formControl.text == strDefault)
    {
        formControl.text = "";
    }
    else
    {
        formControl.select();
    }
}

function removeOptions(oSelect, bAllowReload) {
	if (oSelect && oSelect.tagName && oSelect.tagName.toLowerCase() == "select") {
		var o = oSelect.options;
		if (o && o.length) {
			// shortcut if "length" property is not read-only
			o.length = 0;

			while (o.length > 0)
			{
				if (o.remove)
				{
					o.remove(o.length - 1);
				}
				else
				{
					o[o.length - 1] = null;
					if (bAllowReload)
					{
						history.go(0);
					}
				}
			}
			return true;
		}
	}

	return false;
}


function ShowDiv(divId) {
    var divFloat = document.getElementById(divId);
    divFloat.className = "float";
}
function ShowDivWide(divId) {
    var divFloat = document.getElementById(divId);
    divFloat.className = "floatWide";
}
function HideDiv(divId) {
    var divFloat = document.getElementById(divId);
    divFloat.className = "DisplayNone";
}
function ShowDivShortPage(divId) {
    var divFloat = document.getElementById(divId);
    divFloat.className = "floatShort";
}
function ShowDivPromo(divId) {
    var divFloat = document.getElementById(divId);
    divFloat.className = "floatPromo";
}

function ShowDivClass(divId, cssClass)
{
    var divFloat = document.getElementById(divId);
    divFloat.className = cssClass;
}

function ShowProducts(idVal, popupPage)
{
    var idType = "";
    switch (popupPage) {
        case "IndustryProduct":
            idType = "icr";
            break;
        case "ProductCard":
            idType = "pl";
            break;
        default: 
            idType = "icr";
    }
    
    var pURL = "/Popups/" + popupPage + ".aspx?" + idType + "=" + idVal;

    var width  = 50;
    var height = 50;
    var left   = (screen.width  - 650 - width)/2;
    var top    = (screen.height - 600 - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    prodPopup = window.open(pURL, 'ipWin', params);
    if (window.focus) {prodPopup.focus()}

    return false;
}

function ResizeWin(winName)
{
    var newWidth = 0;
    var newHeight = 0;
    var imgCount = 0;

    switch (winName)
    {
        case 'prodPopup':
            newHeight = 650;
            newWidth = 185;
            imgCount = document.images.length;
            newWidth = newWidth * imgCount;
    }
    window.resizeTo(newWidth, newHeight);
}

function openPopUp(windowURL, windowName, windowWidth, windowHeight, windowTop, windowLeft){
	var winHandle = window.open(windowURL,windowName,"toolbar=no,scrollbars=yes,resizable=yes,top=" + windowTop + ",left=" + windowLeft + ",width="	+ windowWidth + ",height=" + windowHeight);
	if(winHandle != null) winHandle.focus();
	return winHandle;
}

function AddToCart(ProductPackageID)
{
    alert(ProductPackageID);
}

function is_int(value){ 
  if((parseFloat(value) == parseInt(value)) && !isNaN(value)){
      return true;
  } else { 
      return false;
  } 
}

function redirectHttpToHttps()
{
    var currentLocation = window.location.href; 
    var currentProtocol = currentLocation.substr(0, 5);
    if(currentProtocol != "https")
    {
        var httpURL = window.location.hostname + window.location.pathname + window.location.search;
        var httpsURL = "https://" + httpURL; 
        window.location.href = httpsURL;
    }
}

function returnToHttp()
{
    var currentLocation = window.location.href; 
    var currentProtocol = currentLocation.substr(0, 5);
    if(currentProtocol == "https")
    {
        var httpsURL = window.location.hostname + window.location.pathname + window.location.search;
        var httpURL = "http://" + httpsURL; 
        window.location.href = httpURL;
    }
}

