function IsNumber(strString)
{
    var mNumRegex = new RegExp(/^[\d]+$/)
    var blnResult = true;
    if (!mNumRegex.test(strString)) { blnResult = false; }
    return blnResult;
}

function goSetHeight() {

	if (parent == window) {

		return;
		
	}
	// arg: id of iframe element this doc is to be loaded into
	else {
		if (parent.setIframeHeightinCMDefault != null) {

			parent.setIframeHeightinCMDefault('AnotherWebsiteFrame');


		}
		if (parent.setIframeHeight != null) {
			parent.setIframeHeight('ifrm');
		}

		//get the parent of the parent window (ie. default.aspx, if there is one)
		var pp = parent.parent;
		if (pp != null) {
			if (pp.setIframeHeightinCMDefault != null) {
				pp.setIframeHeightinCMDefault('AnotherWebsiteFrame');
			}

		}

		
	}

}
//taken from cmdotnet common.js
/*
function encodeMyHtml(strValue)
{
var  encodedHtml = strValue; 
encodedHtml = stringreplace(encodedHtml, "=", "%3F");
encodedHtml = stringreplace(encodedHtml, "+", "%2B");
encodedHtml = stringreplace(encodedHtml, "?", "%3F");
encodedHtml = stringreplace(encodedHtml, "&", "%26");
encodedHtml = stringreplace(encodedHtml, "@", "%40");
return encodedHtml;
}
*/
//taken from cmdotnet common.js
/*
function stringreplace(checkMe,toberep,repwith)
{

	var temp = checkMe;
	var i = temp.indexOf(toberep);
	while(i > -1)
	{
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep, i + repwith.length + 1);
	}
	return temp;
}		
*/
//based on cmdotnet common.js
/*
function HandleSearch(evt, keywordtxtBox)
{
	if (evt.keyCode == 13)
	{
		
		if (!document.all && document.getElementById) {
			evt.preventDefault();
			evt.stopPropagation();
		}
		evt.cancelBubble = true;
		evt.returnValue = false;
		window.location = window.location.protocol + '//' + '<%=Session("SiteUrlName")%>' + '/search.aspx?Keyword=' +  escape(encodeMyHtml(keywordtxtBox.value)) + '';
		return false;
	}
}
*/
function is_checked_using_array(cbarray){
    //this function checks the array of checkboxes (whose names are in cbarray) if any are ticked.
    //Parameter: cbarray is an array of strings containing the checkbox names/ids to check
    //Returns true if at least 1 is ticked.
    //Returns false if none are ticked.
    
    if (cbarray != null){
        for (var i = 0; i < cbarray.length; i++){
            var cb = document.getElementById(cbarray[i]);
            if (cb.checked){
                return true;
            }
        }
        return false;
    }
}

function checkbox_items_exist(cbarray) {
    //this function checks if there is an array of checkboxes
    //Parameter: cbarray is an array of strings containing the checkbox names/ids to check
    //Returns true if at there is least 1 checkbox item
    //Returns false if no checkboxes exist
    
    if (cbarray != null) {
        if (cbarray.length > 0) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
       return false;    
    }
}

function UpdateSelectedOnClick(CheckBoxIDs) {
    if (checkbox_items_exist(CheckBoxIDs)) {
        if(is_checked_using_array(CheckBoxIDs)) {
            if(!UpdateConfirm()) {
                return false;
            }
        } 
        else {
            alert('Please select an item to update');
            return false;
        }
    }
    else {
        alert('There are no items to update');
        return false;
    }
    return true;
}
function UpdateConfirm(){
    if(confirm("Are you sure you want to update?"))
    {
        return true;
    }
    else
    {
        return false;
    }
}
function SetAllCheckBoxes(CheckBoxIDs, checkbox) {
    if (checkbox_items_exist(CheckBoxIDs)) {
        var cb =document.getElementById(checkbox);
        SetCheckBoxArray(CheckBoxIDs, cb.checked);
    }
}
function SetCheckBoxArray(cbarray, value){
    //this function ticks/unticks the array of checkboxes (whose names are in cbarray)
    //Parameter: cbarray is an array of strings containing the checkbox names/ids 
    //value: true - checkboxes will be all ticked
    //       false - checkboxes will be all unticked
    //Returns:none
    
    
    if (cbarray != null){
        for (var i = 0; i < cbarray.length; i++){
            var cb = document.getElementById(cbarray[i]);
            cb.checked=value;
        }
    }
}
function getSelectedButtonValue(buttonGroup) {
    //gets the value of the selected radio button 
    for (var i = 0; i < buttonGroup.length; i++) {
        if (buttonGroup[i].checked) {
            return buttonGroup[i].value
        }
    }
    return 0
}
function IsButtonGroupSelected(buttonGroup) {
    //gets the value of the selected radio button 
    for (var i = 0; i < buttonGroup.length; i++) {
        if (buttonGroup[i].checked) {
            return true
        }
    }
    return false
}

function AddRelatedProductToCart(url, parentProductId, radioButtonGroupName) {
    //function to get the selected product choice in order to add item to the shopping cart
    if (IsButtonGroupSelected(document.getElementsByName(radioButtonGroupName)) == true) {

        var choiceid = getSelectedButtonValue(document.getElementsByName(radioButtonGroupName));
        location.href = url + 'productinfo.aspx?QuickAddProductID=' + parentProductId + '&ChoiceId=' + choiceid;

    }
    else {
        alert('Please make a selection before attempting to add to your cart.');
    }
}
function AddToCartNoRedirect(productId, qty, campaign, radioButtonGroupName) {

    //function to add product to cart without redirecting to the cart.aspx page
    var choiceid;
    var errorMsg='';

    if (qty == '') {
        errorMsg = 'Please enter a quantity';
    }
    else if (IsNumber(qty)==false) {
        errorMsg = 'Please enter a valid quantity';
    }
    
    if (errorMsg == '') {
        if (radioButtonGroupName == '') {
            choiceid = '0';
            errorMsg = '';
        }
        else {
            //function to get the selected product choice in order to add item to the shopping cart
            if (IsButtonGroupSelected(document.getElementsByName(radioButtonGroupName)) == true) {

                choiceid = getSelectedButtonValue(document.getElementsByName(radioButtonGroupName));
                errorMsg = '';
            }
            else {
                errorMsg = 'Please make a selection before attempting to add to your cart.';
            }
        }
    }
    if (errorMsg == '') {
        var theForm = document.forms['Form1'];
        if (!theForm) {
            theForm = document.Form1;
        }
        if (!theForm) {
            theForm = document.forms[0];
        }

        document.getElementById('hidAddToCartProductId').value = productId;
        document.getElementById('hidAddToCartQty').value = qty;
        document.getElementById('hidAddToCartCampaign').value = campaign;
        document.getElementById('hidAddToCartChoiceId').value = choiceid;
        theForm.submit();
    }
    else {
        alert(errorMsg);
    }
}
