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);
}

function processCallToHidePopUpDiv(elementName){
    return("hidePopUpDiv('" + elementName + "');");
}

function ltrim(argvalue) {
	while (1) {
		if (argvalue.substring(0, 1) != " ")
		break;
		argvalue = argvalue.substring(1, argvalue.length);
	}

	return argvalue;
}

function rtrim(argvalue) {
	while (1) {
		if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
		break;
		argvalue = argvalue.substring(0, argvalue.length - 1);
	}

	return argvalue;
}

function isNumeric(stringExpression){
    for(i=0; i<stringExpression.length; i++){
	    switch(stringExpression.charAt(i)){
		    case "1":
			    break;
		    case "2":
			    break;
		    case "3":
			    break;
		    case "4":
			    break;
		    case "5":
			    break;
		    case "6":
			    break;
		    case "7":
			    break;
		    case "8":
			    break;
		    case "9":
			    break;
		    case "0":
			    break;
		    default:
			    return(false);
		}
	}
		
    return(true);
}

function isEmpty(inputValue){
	if (inputValue.length == 0)
	    return(true);
	else{
		for(var i=0; i<inputValue.length; i++)
			if(inputValue.charAt(i)!=" ")
				return(false);
		
		return(true);
    }
}

function validateEMail(inputValue){
	if(isEmpty(inputValue))
	    return("");
	else{
        inputValue=rtrim(ltrim(inputValue));
    	
	    if(inputValue.indexOf(",")>=0)
		    var inputValueArray=inputValue.split(",");
	    else
		    var inputValueArray=new Array(inputValue);
    	
	    for(var i=0; i<inputValueArray.length; i++){
		    inputValueArray[i]=rtrim(ltrim(inputValueArray[i]));

		    if(!(inputValueArray[i].match("^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$"))){
			    return("Invalid Email");
			    break;
		    }
	    }
	}
	
	return("");
}

function validateSingleEMailAddress(inputValue){
    if(isEmpty(inputValue))
        return("");
    else{
        if(inputValue.indexOf(",")>=0){
            return('Please enter only a single email address.');
        }
        else{
            var eMailErrorMessage=new String(validateEMail(inputValue));

            if(eMailErrorMessage.length>0)
                return(eMailErrorMessage);
            else
                return('');
        }
    }
}

function validateRequiredTextField(inputValue){
    if(isEmpty(inputValue))
        return("<font color='#FF0000'>*</font>");
    else
        return("*");
}

function validateRequiredSelectField(index, hasDefaultValue){
    if(hasDefaultValue){
        if(index>0)
            return("*");
        else
            return("<font color='#FF0000'>*</font>");
    }
    else{
        if(index>=0)
            return("*");
        else
            return("<font color='#FF0000'>*</font>");
    }
}

function validateNumericField(inputValue){
    if(isEmpty(inputValue))
        return("");
    else{    
        if(isNumeric(inputValue))
            return("");
        else
            return("<font color='#FF0000'>Numbers Only</font>");
    }
}

function configureErrorDivAndReturnErrorStatus(errorDiv, errorDivDisplaySetting){
    if(errorDiv.innerHTML.length>0)
        errorDiv.style.display=errorDivDisplaySetting;
    else
        errorDiv.style.display='none';
        
    return((errorDiv.innerHTML.length==0)||(errorDiv.innerHTML=='*'));
}

function validateFieldWithErrorDiv(errorFunctionCall, errorDiv, errorDivDisplaySetting){
    var errorMessage = new String(errorFunctionCall);

    if((arguments.length>3)&&(errorMessage.length>0))
        errorDiv.innerHTML=arguments[3];
    else
        errorDiv.innerHTML=errorMessage;
        
    return(configureErrorDivAndReturnErrorStatus(errorDiv, errorDivDisplaySetting));
}

function getFormErrorStatus(errorStatusArray){
    for(var i=0; i<errorStatusArray.length; i++)
        if(!(errorStatusArray[i]))
            return(false);
    
    return(true);
}



// global variables

var bFixPNGs = true;







// designed to run on pageload

function RunOnLoad()
{
	if (bFixPNGs)
	{
			correctPNG();
	}
}







// corrects PNG images to get PNG transparency to work in IE

// to get this to work within a specific page, simply turn on the global bFixPNGs variable inside a conditional IE comment

function correctPNG()
{
   for(var i=0; i<document.images.length; i++)
   {
          var img = document.images[i];
          var imgName = img.src.toUpperCase();
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
                var imgID = (img.id) ? "id='" + img.id + "' " : "";
                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                var imgStyle = "display:inline-block;" + img.style.cssText;
                if (img.align == "left") imgStyle = "float:left;" + imgStyle;
                if (img.align == "right") imgStyle = "float:right;" + imgStyle;
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
                var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
                img.outerHTML = strNewHTML;
                i = i-1;
          }
   }
}

function resizeImage(){
	var img;
	if (document.getElementById('DefaultHiResImage')){
		img = document.getElementById('DefaultHiResImage');
		alert(img.width + 'x' + img.height);
		if (img.width >= 300){
			var W = img.width;
			img.style.width = ('160px');
			//img.style.width = (W*0.5); //could do it this way too.
		}else if(img.height >= 215){
			var H = img.height;
			img.style.height = '200px';
			//img.style.height = (H*0.5); //could do it this way too.
		}
	}
}







