<!--
// <script type="text/javascript" src="/www/common/client_scripts/utils.js"></script>


function IsIE()
{
	var ua = navigator.userAgent.toLowerCase();
	return (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
	//return ( navigator.appName=="Microsoft Internet Explorer" ); 
}

function IsIE6()
{
	var ua = navigator.userAgent.toLowerCase();
	return (ua.indexOf('msie 6.0') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
	//return ( navigator.appName=="Microsoft Internet Explorer" ); 
}

function IsMAC()
{
	var ua = navigator.userAgent.toLowerCase();
	return ( (ua.indexOf('safari') != -1 || ua.indexOf('mac') != -1));
	//return ( navigator.appName=="Microsoft Internet Explorer" ); 
}

function Round(num, numTens)
{
	if (numTens == 0)
		return Math.round(num);
	else
	{
		var mult = Math.pow(10, numTens);
		var result =  Math.round(num/mult)*mult;
		if (numTens < 0)
			return result.toFixed(-numTens);
		else
			return result;
	}
}

function RoundToMultiple(num, multBase)
{
    if(num % multBase == 0)     // if already a multiple
    {
        return num;
    }
    else
    {
        return Math.round(num/multBase) * multBase;
    }
}

function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 } 

function IsNumeric(sText)
{
	if (sText == '')
		return false;

	var ValidChars = "0123456789.-";
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
			IsNumber = false;
	}
	return IsNumber;
}

function showObj(objCtrl)
{
	objCtrl.style.visibility = '';
	objCtrl.style.display = '';
}

function showByID(objID)
{
    var obj = document.getElementById(objID);
    if (obj != null)
        showObj(obj);
}

function hideByID(objID)
{
    var obj = document.getElementById(objID);
    if (obj != null)
        hideObj(obj);
}

function hideObj(objCtrl)
{
	objCtrl.style.visibility = 'hidden';
	objCtrl.style.display = 'none';
}

 // Find both positions at once
function getBothPos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    return [curleft,curtop];
}
        


function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	
	
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}

function getBothAbsolutePos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    return [curleft,curtop];
}

function subtractDatesInDays(date1, date2)
{
	var one_day = 1000*60*60*24;
	
	return Math.ceil(date1.getTime()-date2.getTime())/(one_day);
}

function dateToString(date)
{
	var month = date.getMonth() + 1;
	var day = date.getDate();
	var year = date.getFullYear();
	
	return month+'/'+day+'/'+year;
}

function pausecomp(millis)
{
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while(curDate-date < millis);
} 

// Convert rgb string (ex. rgb(244, 244, 243) to #F4F4F3
function rgbConvert(str) {
   str = str.toLowerCase();
   if (str.indexOf("rgb") > -1)
   {
       str = str.replace(/rgb\(|\)/g, "").split(",");
       str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
       str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
       str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
       str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
       str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
       str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
       return ('#' + str.join(""));
   }
   else if (str == "white")
       return "#FFFFFF";
   else
        return str;
}

/* ************************ COOKIE READING ********************* */


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);
}

/* ************************ focus/click when pressing enter Button  ********************* */
// Use it 'onkeydown' event of textbox, EX: onkeydown="focusBtn('btnID', event)"
function focusBtn(btn, e)
{
	// if 'enter' key is pressed (ascii 13) change focus to search btn next to textBox
	// (e.which?e.which:e.keyCode) done for cross browser 
	// e = keyUp event
	if ((e.which?e.which:e.keyCode) == 13)
    {
		var a = document.getElementById(btn);
		if(null != a){a.focus();}
	}
}	

function clickBtn(btn, e) {
    focusBtn(btn, e);
}

function DisableBtnAfterClick(btn){
    if(typeof(Page_ClientValidate)=='function')
    {
        if(!Page_ClientValidate())
        {
            return false;
        }
        else
        {
            btn.disabled = true;
            return true;
        }
    } 
}

/*************** CLIENT VALIDATION ******************/

function validateListValidators(valList) /* valList : '|' separated list of cientIDs */
{
    var thisIsValid = true;
    var valArr = valList.split('|');
    for (var i=0; i < valArr.length; i++)
    {
        var val = $get(valArr[i]);
        if (val != null && typeof yourFunctionName == 'function')
        {
            ValidatorEnable(val, true);
            if (!val.isvalid)
                thisIsValid = false;
        }
    }
    return thisIsValid;
}

/* QTY VALIDATORS */

function validate_qty(oSrc, args)
{
    args.IsValid = false;
    var qty = args.Value;
   
    if(qty)
        args.IsValid = validate_newqty(qty, false);    
    else
        args.IsValid = false;
       
   setErrorCss(oSrc, args);
}

function validate_qty_allow_zero(oSrc, args)
{
    args.IsValid = false;
    var qty = args.Value;
   
    if(qty)
        args.IsValid = validate_newqty(qty, true);    
    else
        args.IsValid = false;
  
   setErrorCss(oSrc, args);
}

function setErrorCss(oSrc, args)
{
    var className = oSrc.getAttribute('class');
    if (className != null)
    {
        var arrClass = className.split(' ');
        var tbID = arrClass[arrClass.length-1];
        
        var tb = document.getElementById(tbID);
        if (tb != null)
        {
            if(args.IsValid)
                tb.style.borderColor = ''; 
            else
                tb.style.borderColor = 'red'; 
        }
    }

   
}

function validate_qty_optional(oSrc, args)
{
    if(args.Value)
    {
        validate_qty(oSrc, args);
    }
    else
    {
        args.IsValid = true;        
    }    
}

function validate_newqty(qty, allowZero)
{     
   if(qty > 0 && qty < 10000)
       return true;
   else if (allowZero && qty == 0)
        return true;
   else if(qty <= 0){
       return false;
   }
   else
   {
       qty = qty.trim();
       
       var parts = qty.split('/');
       if (parts.length != 2)
            return false;
        
       var denominator = parts[1];
       if (!isInt(denominator) || denominator <= 0) // if denominator is zero or negative then false.
            return false;
       
       var firstPart = parts[0];
       if (firstPart.indexOf('-') > 0)
            nomParts = firstPart.split('-');
       else
            nomParts = firstPart.split(' ');
            
       if (nomParts.length > 2)
            return false;
      
       for (var i = 0; i < nomParts.length; i++) { 
            if (!isInt(nomParts[i]) || nomParts[i] < 0)
                return false;
       }
        
      
       return true;
 
   }
}

function validate_not_past_date(oSrc, args) {  
     
    var val = document.getElementById(oSrc.id); 
    if (args.Value.trim() == "")
    {
        args.IsValid = false;
        val.innerHTML = "Date cannot be empty";
    }
    else
    {
        var date=Date.parse(args.Value);
        if (isNaN(date))            
            args.IsValid = false;
        else
        {
            var minDateStr = val.getAttribute("minDate");
            var minDate =Date.parse(minDateStr);
            if (date < minDate)
            {
                args.IsValid = false;
                val.innerHTML = "Date cannot be in the past";
            }
            else
                args.IsValid = true;
        }
    }
}

function setDropDownBorder(dropDownID, borderID)
{
    var borderDIV = document.getElementById(borderID); 
    if (borderDIV == null)
        return;
        
    //borderDIV.style.top = getAbsoluteTop(dropDownID;
    borderDIV.style.left = getAbsoluteLeft(dropDownID);
    borderDIV.style.display = '';
}

function replaceDegreeKey(dirs,e)
{
    if ((e.which?e.which:e.keyCode) == 56) // keyCode 56 is *
    {
        dirs.value = dirs.value.replace('*', '\u00BA'); // degree sign 'º'
	}
}	

function getFileNameFromPath(path)
{ 
   var m = path.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
  
   if (m == null)
        return path;
   else
        return m[2];
   
}

/**** HACK TO FIX ModalPopupExtenders *****/

function FixMPE(mpeName)
{
    // HACK to fix the hiding cursor in textboxes in FireFox.  The modalPopup automatically sets the backgroundElement position to fixed.
	// This causes the cursor to not show up in textboxes inside Search.  Therefore when the page is loaded the position is changed to absolute and this fixes the cursor.			   
    // UPDATE: Removed it because it causes a horizontal bar on Chrome
    //setTimeout("SetMPEpos('"+mpeName+"');", 50);
}

function SetMPEpos(mpeName)
{
    var el = document.getElementById(mpeName+'_backgroundElement');
    if ( el != null) 
	    el.style.position = 'absolute';
}

function CloseMPE(mpeBehaviorID)
{
    var mpe = $find(mpeBehaviorID);
    if (mpe != null)
    {
        mpe.hide();
    }
}

function OpenMPE(mpeBehaviorID)
{
    var mpe = $find(mpeBehaviorID);
    if (mpe != null)
        mpe.show();
}

function LocationAppendQueryString(queryStringArr)
{
    var locHF = location.href;
    var indexOf = locHF.indexOf('#');
    if (indexOf > -1)
        locHF = locHF.substring(0, indexOf);
    
    var indexOf = locHF.indexOf('?');
    if (indexOf == -1) /* doesn't have a query string yet -> just append it */
        locHF += "?"+GetQueryStrDisplay(queryStringArr);
    else
    {
        var oldQueryString = locHF.substring(indexOf+1);
        locHF = locHF.substring(0, indexOf)+"?"+MergeQueryStrings(oldQueryString, queryStringArr)
    }
    return locHF;
}

function LocationRemoveQueryString(locHF, queryStringArr)
{
    var indexOf = locHF.indexOf('#');
    if (indexOf > -1)
        locHF = locHF.substring(0, indexOf);
    
    var indexOf = locHF.indexOf('?');
    if (indexOf != -1) 
    {
        var oldQueryString = locHF.substring(indexOf+1);
        for(var i=0;i < queryStringArr.length; i++)
        {
            oldQueryString = RemoveQueryStringWithKey(oldQueryString, queryStringArr[i]);
        }
        locHF = locHF.substring(0, indexOf)+"?"+oldQueryString;
    }
    return locHF;
}


function MergeQueryStrings(oldQS, newQSArr)
{
    oldQS = oldQS.trim().replace('?', '&');
    if (oldQS == "")
        return GetQueryStrDisplay(newQSArr);
    
    // First remove existing queryStrings from oldQS
    for(var key in newQSArr) {
       oldQS = RemoveQueryStringWithKey(oldQS, key);
    }
    
    oldQS = oldQS.trim();
    if (oldQS == "")
        oldQS = GetQueryStrDisplay(newQSArr);
    else
        oldQS += "&"+GetQueryStrDisplay(newQSArr);

    return oldQS;
}

function GetQueryStrDisplay(queryStringArr)
{
    var i=0;
    var qs= "";
    for(var index in queryStringArr) {
      if (i > 0)
        qs += "&";
      qs += index + "=" + queryStringArr[index];
      i += 1;
    }
    return qs;
}

function RemoveQueryStringWithKey(qs, key)
{
    var altQS = "&"+qs;
    var strKey = "&"+key+"=";
    var indexOf = altQS.indexOf(strKey);
    if (indexOf == -1)
        return qs;
    else /* KEY FOUND */
    {
        var firstPart = "";
        if (indexOf > 0)
            firstPart = altQS.substring(1, indexOf);
        var secondPart = altQS.substring(indexOf+strKey.length);
        var indexOf = secondPart.indexOf('&');
        if (indexOf == -1)
            secondPart = "";
        else
            secondPart = secondPart.substring(indexOf);
        //alert("firstPart='"+firstPart+"', secondPart='"+secondPart);
       
        return firstPart+secondPart;
        
    }
  
}

function isArray(obj) {
    return (obj.constructor.toString().indexOf("Array") != -1);
}






// -->