var thisbrowser

if(document.layers){ thisbrowser='NN4'; }

if(document.all){ thisbrowser='IE'; }

if(!document.all && document.getElementById){ thisbrowser='NN6'; }



function cleanUrl () {

}

function ddlChangeLanguage (langid, scriptfile) {

    var regex1      = /(i18n=[a-z]+_[a-z]+)/gi;
    var sQuery      = document.location.search;
    var outputstr   = "";
    var redirecturl = "";

    // regex replace langid=xx
    outputstr=sQuery.replace(regex1,"");

    // string replace the ?
    outputstr=outputstr.replace("?","");

    // if we have some query params, forward them
    if (outputstr == "") {
        redirecturl = scriptfile + '?i18n=' + langid;

    // if not, just output a clean ?langid=xx
    } else {
        redirecturl = scriptfile + '?i18n=' + langid + '&' + outputstr;
    }

    // rip out duplicate ampersand (bug between browser types)
    redirecturl=redirecturl.replace("&&","&");

    document.location.href=redirecturl;

}

function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;

}

function isInvoiceKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode

	// allow numbers, uppercase letters, lowercase letters, dash key, number key)
	if ((charCode > 47 && charCode < 58) || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 45)
		return true;

	return false;

}

function isNumberDotKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
		return false;

	return true;

}

function isNumberDashKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 45))
		return false;

	return true;

}


function ValidateQuantity (productid, minqty, maxqty, message)
{

	var FormObject	= document.forms['myQuantity' + productid];
	var quantity	= FormObject.elements['quantity'].value;

	if (quantity > maxqty || quantity < minqty)
	{
		alert (message);
		return false;
	}
	else
	{
		return true;
	}
}


function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
	}
	else
	{
		countfield.value = maxlimit - field.value.length;
	}
}


/*
Accepts the name of a parent control
Sets the visibility of objChildName (based on whether parent control input has a value of 1)
*/
function ShowDivOnOffFancy (objParent, objChildName) {
	var visibility;
	var parentValue;
	var objChild;

	parentValue = objParent.options[objParent.selectedIndex].value;

    //if(thisbrowser=='IE') objChild = document.all[objChildName];
	//if(thisbrowser=='NN6' || thisbrowser=='NN4') objChild = document.getElementById(objChildName);

	objChild = document.getElementById(objChildName);

	if ( parentValue == 1 )
	{
	    new Effect.BlindDown(objChild);
	    new Effect.Highlight(objChild, {duration: 4});
	}
	else
	{
	    new Effect.Highlight(objChild, {duration: 2});
	    new Effect.BlindUp(objChild);
	}
}

/*
Accepts the name of a child control, and sets visibily based on whether display=1 or not
if display=2 then on/off is based on current setting
*/
function ShowDivOnOff(objChildName, display) {
	var visibility;
	var parentValue;
	var objChild;
	var objParent;


    //if(thisbrowser=='IE') objChild = document.all[objChildName];
	//if(thisbrowser=='NN6' || thisbrowser=='NN4') objChild = document.getElementById(objChildName);

    objChild = document.getElementById(objChildName);

	if ( display == 1 )
	{
	    objChild.style.display = '';
	}
	else if ( display == 2 )
	{
	    if ( objChild.style.display == 'none' ) {
	        objChild.style.display = '';
	    } else {
	        objChild.style.display = 'none';
	    }
	}
	else
	{
	    objChild.style.display = 'none';
	}
}