﻿/// <reference path="jquery-1.2.6-intellisense.js" />


// Used to set radiobutton in repeaters
function SetUniqueRadioButton(nameregex, current)
{
   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;
}


function SetSearchInput(objInput) {
    if (objInput.value == 'Enter keyword(s)') {
        objInput.className = 'formInput inuse';
        objInput.value = '';
    }
}

function ReSetSearchInput(objInput) {
    if (objInput.value == '') {
        objInput.className = 'formInput';
        objInput.value = 'Enter keyword(s)';
    }
}

function PrintPage() {
    if (window.print()) {
        window.print();
    }
}



/* display the help rollover thing */
function DisplayHelp(objRow, helpText, leftOffset) {
    if (helpText != "") {
        var posArray = findPos(objRow);
        document.getElementById('helpText').style.left = posArray[0] - 200 - leftOffset + "px";
        document.getElementById('helpText').style.top = posArray[1] + 25 + "px";
        document.getElementById('helpMain').innerHTML = helpText;
        $("#helpText").show();
    }
}

function HideHelp(objRow, helpText) {
    $("#helpText").hide();
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}

/* 
Updates the quantity of items in the basket. 
Called from code behind ShopingBasket and ProductDetails controls.
*/
function SetBasketItems(count, basketTable) {
    if (count == "") count = 0;
	if ("#shoppingIndicator .shoppingIndicatorItemCount") {
		$("#shoppingIndicator .shoppingIndicatorItemCount").html(count);
	  
		if (basketTable != "") {
			$("#CartContents .popupShoppingBasketTable").html(basketTable);
			showBasket();
		}
	}
}

function showBasket() {
    jQuery.each(jQuery.browser, function(i) {
        if ($.browser.msie) {
            $("#CartContents").show();
            setTimeout(function() { $("#CartContents").hide(); }, 5000);
        } else {
            $("#CartContents").fadeIn("slow");
            setTimeout(function() { $("#CartContents").fadeOut("slow"); }, 5000);
        }
    });
}

function hideBasket() {
    $("#CartContents").hide();
}

/*
$(document).ready(function() {
    $("#fancyright").mouseover(function() {
        $("#CartContents").fadeIn("slow");
    }).mouseout(function() {
        //$("#CartContents").fadeOut("slow");
    });

    $("#CartContents").hover(function() {
        $("#CartContents").stop().show();
    }, function() {
        $("#CartContents").fadeOut("slow");
    });
});
*/

// Use to detect if cookie ar enabled
function OpenPrintOrderForm(url) {
    window.open(url, "PrintOrderForm", "", "");
}

function GetCookie() {
    var strName = "varCook";
    if (document.cookie.indexOf(strName) == -1) {
        return false;
    }
    else {
        cookieStart = document.cookie.indexOf(strName);
        cookieValStart = (document.cookie.indexOf("=", cookieStart) + 1);
        cookieValEnd = document.cookie.indexOf(";", cookieStart);
        if (cookieValEnd == -1) {
            cookieValEnd = document.cookie.length;
        }
        cookieValue = document.cookie.substring(cookieValStart, cookieValEnd);
    }
    if (cookieValue = "True") {
        return ("True");
    }
}

function SetCookie(name, value, expires, path, domain, secure) {
    var strDNS = GetDNS();
    document.cookie = name + "=" + escape(value) +
	        ((expires) ? ";expires=" + expires.toGMTString() + 1000 * 60 * 20 : "") +
        	((path) ? ";path=" + path : "") +
    //( (domain) ? ";domain=" + domain : "") +
        	((domain) ? ";domain=" + strDNS : "") +
	        ((secure) ? ";secure" : "");
    return true
}

function GetDNS() {
    cookieDomain = document.location.hostname;
}
