﻿var callDisableShipping = false;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  newwindow = window.open(theURL,winName,features);
  if(newwindow){
    	newwindow.focus();
  }
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function imageShow(imageIndex) {
	currentImage = imageIndex-1;
	document.picCenter.src=imagesMain[currentImage];
	checkImageNum();

}

function imageNext() {
	if (document.images && currentImage < imageCount-1) {
		currentImage++;
		document.picCenter.src=imagesMain[currentImage];
	}
	checkImageNum();
}

function imagePrevious() {
	if (document.images && currentImage > 0) {
		currentImage--;
		document.picCenter.src=imagesMain[currentImage];
	}
	checkImageNum();

}

function checkImageNum() {
		// alert("image " + currentImage +  " showing!");
		// set all boxes to default state
		resetBoxesToDefault();

		//currentImagePlusOne = currentImage + 1;
		//set the class to the ID which corresponds to current image
		//increase number by 1 because first element of array
		//is equal to zero
		document.getElementById('box' + (currentImage+1)).className='PAjustClickedBox';

}

function resetBoxesToDefault() {
	//for loop to create default box states for each image in the imagesMain array
	for(boxNumber = 1 ; boxNumber <= imageCount ; boxNumber++)

	document.getElementById('box' + boxNumber).className='textSmallestGrayBox';
}

function change(id, newClass) {
	resetBoxesToDefault();
	identity=document.getElementById(id);
	identity.className=newClass;
}


function BrassringWindow(){
	MM_openBrWindow("http://jobs.brassring.com/1033/ASP/TG/cim_home.asp?partnerid=20052&siteid=5022", "BrassRings", "scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no");
}



//pop-up window
function OpenWin(the_window,win_name,args,what_return){
	this[win_name] = window.open(the_window,win_name,args);
	has_pop = SendCommand(win_name);
	if(!has_pop){
		try{
			eval(win_name).focus();
		}catch(e){
			has_pop = true;
		}
	}
	if(what_return);
	else return has_pop;
}
function SendCommand(wn){
	try{
		return(wn)?false:true;
	}catch(e){
		return true;
	}
}
//Gecko Detection
function IsGekko(){
	return(navigator.appName == "Netscape")?true:false
}

function GetTheVersion(gt){
	var gua = navigator.userAgent;
	if(gt == "Mozilla"){
		temp = gua.split("rv:");
		major_version = parseFloat(temp[1]);

	}
	else{
		var marker = gua.lastIndexOf("/");
		var subMe = gua.substr(marker + 1);
		var major_version = parseFloat(subMe);
	}
	return major_version;	
}
function PassVersion(bt,version,req_version){
	defaultAr = new Array(1.2,.1,7,85.8);
	this.strippedAppVersion = version
	if(req_version){
		reqAr = req_version.split(",");
		for(i=0;i<reqAr.length;i++){
			if(reqAr[i] == "" || reqAr[i] == 0) reqAr[i] = defaultAr[i];
			reqAr[i] = parseFloat(reqAr[i]);
		}
	}else{
		reqAr = defaultAr;
	}
	switch(bt){
		case "Mozilla":
			this.browser = "Mozilla";
			return(version >= reqAr[0])?true:false
		case "Firefox":
			this.browser = "Firefox";
			//if(version >= 1 || version == .10) return true;
			return(version >= .1)?true:false;
		case "Netscape":
			this.browser = "Netscape";
			return(version >= reqAr[2])?true:false;
		case "Safari":
			this.browser = "Safari";
			return(version >= reqAr[3])?true:false;
		case "default":
			return false;
		}
	return false;
}
function WhatGecko(){
	var use_agent = navigator.userAgent;
	if(use_agent.indexOf("Netscape") != -1) nua = "Netscape";
	else if(use_agent.indexOf("Safari") != -1) nua = "Safari";
	else if(use_agent.indexOf("Firefox") != -1) nua = "Firefox";
	else if(use_agent.indexOf("Mozilla/5.0") != -1) nua = "Mozilla";
	else return false;
	return nua;
}
function GeckoInterface(page_transition,req_version){
	var myGecko = WhatGecko();
	var theVersion = GetTheVersion(myGecko);
	var passBrowser = this.PassVersion(myGecko,theVersion,req_version);
	if(page_transition)return passBrowser;
	else{
		if(passBrowser)return true;
		else return false;
	}
}
//Service Pack Two Detection
function IsServicePack(){
	var ua = navigator.userAgent;
	if(ua.indexOf("SV1") != -1) return true;
	else return false;
}
//end code instert;

//redirect function
function goURL(url){
	winLoc = window.location.toString();
	SetCookieUtil("detect_cookie","FF|" + winLoc);
	top.location.replace(url);
	}
//sets the cookie
function SetCookieUtil (name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +	((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "; domain=.go.com") +	((secure) ? "; secure" : "");
}
//gets the cookie (Currently not being used)
function GetCookieUtil (name) {
	var result = null;
	var myCookie = " " + document.cookie + ";";
	var searchName = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie;
	if (startOfCookie != -1) {
		startOfCookie += searchName.length;
		endOfCookie = myCookie.indexOf(";", startOfCookie);
		result = unescape(myCookie.substring(startOfCookie, endOfCookie));
	}
	return result;
}
//Pulls IE Version Number
function PullVersionNumber(arg){
	var toReturn = arg.split(" ");
	for(var i=0;i<toReturn.length;i++){
		var num = toReturn[i];
		var num = parseFloat(num);
		if(num >= 1){
			return num;
		}
	
	}
	//return arg;
}
// Initial IE version number function
function FindVersionNumber(){
	var ret;
	var version = navigator.appVersion;
	var versionAr = version.split(";");
	for(i=0;i<versionAr.length;i++){
		if(versionAr[i].indexOf("MSIE") != -1){
			ret = PullVersionNumber(versionAr[i]);
		}
	}
	return ret;
}
// Generic Active X function
function GetAx(ax){
	try{
		oMotion=eval("new  ActiveXObject('"+ax+"');");
		return true;
		}
		catch(e){
			return false;
		}
		return true;
}
//Gets Flash Active X
function GetFlashAx(){
	var flashKey = "ShockwaveFlash.ShockwaveFlash.";
	var version;
	for(i=4;i<9;i++){
		var combo = flashKey + i;
		version = GetAx(combo);
		if(version == false){
			break;
		}
		
	}
	return (i - 1)+",0,0,0";
		
}
//Checks version of Flash.
function CheckFlashVersion(required){
	var output = false;
	userVersion = flashVersion;
	if(userVersion == false) return false;
	else iUserVersion = parseInt(userVersion)
	if(required != null)iRequiredVersion = parseInt(required);
	return (iUserVersion >= iRequiredVersion)?true:false;
}

//argument overrides default version number.
function FlashCheck(version){return (CheckFlashVersion(version)) ? true : false;}
//Initiated Flash Checker, method called by the object.
function DetectFlash(nversion,redirect,override){
	if(!nversion)nversion = "7";
	if(!redirect)redirect = defaultLP;
	gotFlash = FlashCheck(nversion);

	if(!gotFlash){
		if(override == true){
			hasFlash = false;
			return false;
		}
		else{
			retFull = window.location.toString();
			SetCookieUtil("return_path",retFull);
			goURL(redirect + "?flash=false");
		}
	}
	else{
		return true;
	}
}
//END FLASH SCRIPT
//Flash Tag Writer

function FlashObj(swf,width,height,background,version,id,vars,autoplay,base,fit,bToggleScriptAccess){
	//toggle allow ScriptAcceess 11
	//first three required, rest optional
	//builds the Flash Object
	if(background == "" || background == null){
		if(document.bgColor == "")background = "#ffffff";
		else background = document.bgColor;
	}
	try{
		this.hasAutoPlay = autoplay.toString();
		
	}catch(e){
		this.hasAutoPlay = "";
		
	}
	
	if(version == "" || version == null) version = "6";
	if(id == "" || id == null) id = "FlashWindow";
	if(vars == "" || vars == null) vars = "test=true"
	this.swf = swf;
	this.version = version;
	this.width = width;
	this.height = height;
	this.id = id;
	this.render = WriteFlash;
	this.background = background;
	this.flash_var = vars;
	this.bToggleScriptAccess = (!bToggleScriptAccess)?false:true;
	this.scriptAccessValue = "always";
	if(base)this.base = base;
	else this.base = false;
	if(fit)this.fit = fit;
	else this.fit = "";
	this.AddScriptAccess = AddScriptAccess;
	
	

}
//Add in Script Access Support
//Updated 4/18/2006
function AddScriptAccess(value){
	this.scriptAccessValue = value;
	
}

//AKA Render function
function WriteFlash(ob_override,wmode,wmode_override){
	//declares the Flash array.
	flashAr = new Array()
	sAllowAccess = (!this.bToggleScriptAccess)?'<param name="allowScriptAccess" value="'+this.scriptAccessValue+'" />':'';
	sNaAllowAccess = (!this.bToggleScriptAccess)?'allowScriptAccess="'+this.scriptAccessValue+'"':'';
	//determines if it is http or https 
	var prot = location.protocol;
	//defaults winmode parameters
	ob_pram = "";
	ob_pram_g = "";
	if(prot == "https:")prot = "https:";
	else prot = "http:"
	if(!ob_override) {
		ob_pram = "";
		ob_pram_g = "";
	}
	else {
		//if no win mode defaults to noting
		if(wmode == "blank" || wmode == ""){
			ob_pram = "";
			ob_pram_g = "";
		}
		else {
			//if winmode is triggered this will be inserted in the array.
			ob_pram = "<param name=\"wmode\" value=\""+wmode+"\" />";
			ob_pram_g = (!wmode_override || wmode!="opaque")?"wmode='"+wmode+"' ":"";
		}
	}
	
	if(hasActiveX == true){
		flashAr[0] = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\""+prot+"//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+ this.version + ",0,0,0\"";
		flashAr[1] ="width=\"" + this.width + "\" height=\"" + this.height + "\" id=\"" + this.id + "\" align=\"\">";
		flashAr[2] = "<param name=\"movie\" value= \""+this.swf+"\" /> <param name=\"quality\" value=\"high\" /><param name=\"menu\" value=\"false\" /> <param name=\"bgcolor\" value=\"" + this.background + "\" />";
		flashAr[3] = "<param name=\"flashvars\" value=\""+this.flash_var+"\" />";
		flashAr[4] = sAllowAccess;
		flashAr[5] = ob_pram;
		if(this.hasAutoPlay == "true") flashAr[6] = "<param name=\"play\" value=\"true\" />";
		else if(this.hasAutoPlay == "false")flashAr[6] = "<param name=\"play\" value=\"false\" />";
		else flashAr[6] = ""
		flashAr[7] = (this.base)?"<param name=\"base\" value=\""+this.base+"\" />":""; 
		flashAr[8] = (this.fit)?"<param name=\"scale\" value=\""+this.fit+"\" />":"";
		flashAr[9] = "</object>";
	}
	else{
		// netscape
		if(this.hasAutoPlay == "true")embedInsert = " play=\"true\" ";
		else if(this.hasAutoPlay == "false")embedInsert = " play=\"false\"";
		else embedInsert="";
		//base
		base_insert = (this.base)?"base=\"" + this.base + "\" ":"";
		//scale
		scale_insert=(this.fit)?"scale=\""+this.fit+"\"":"";
		flashAr[0] = "<embed src=\""+this.swf+"\" "+sNaAllowAccess+"quality=\"high\" bgcolor=\""+this.background+"\" width=\""+this.width+"\" height=\""+this.height+"\""
		flashAr[1] = embedInsert + " name=\""+this.id+"\" id=\""+this.id+"\""+ob_pram_g+" align=\"middle\" menu=false+"+embedInsert+" FlashVars=\""+this.flash_var+"\" type=\"application/x-shockwave-flash\" pluginspage=\""+prot+"://www.macromedia.com/go/getflashplayer\""
		flashAr[2] = base_insert;
		flashAr[3] = scale_insert + " />";

	}
	for(i=0;i<flashAr.length;i++){
		document.write(flashAr[i])
	}
	
}
//End Flash Tag Writer
function GetFlashVersion(){
var activex_flash;
var na_flash = 0
//Determines if the user is using active x browsers or not
//AX browsers have the appname of Microsoft and platform of Win or CE
if(navigator.userAgent.indexOf("Opera") != -1 ){
	var flashVersion = false;
}
else if(this.d_appName.indexOf("Microsoft") != -1 && ((this.d_platForm.indexOf("Win") != -1) || this.d_platForm.toLowerCase().indexOf("ce") != -1)){
	var flashVersion = GetFlashAx();

}
else{
	var flashVersion = false;
}
if (flashVersion)activex_flash = flashVersion;
//Non AX Flash Detect
if (navigator.plugins) {
	for (var i=0; i < navigator.plugins.length; i++) {
		if (navigator.plugins[i].name.toLowerCase().indexOf("shockwave flash") >= 0) {
			var flash_plug = navigator.plugins[i].description.substring(navigator.plugins[i].description.toLowerCase().lastIndexOf("flash ") + 6, navigator.plugins[i].description.length);
			if(parseFloat(flash_plug) >= parseFloat(na_flash)) na_flash = flash_plug;
			}
		}
}
if(activex_flash){
	return activex_flash;
}
//Simplifies the datea
if(na_flash){
	na_flashHold = na_flash.split("r");
	na_flashHold2 = na_flashHold[0].split(".")
	na_flashHold2[1] = na_flashHold2[1].substring(0,na_flashHold2[1].length - 2)
	//na_flash = na_flashHold2[0] + "," + na_flashHold2[1] + "," + na_flashHold[1] + ",0";
	na_flash = na_flashHold2[0] + ",0,0,0";
    return na_flash
    }
return false
}
//Real Active X Detect
function GetActiveX(){
	
	return(this.d_appName.indexOf("Microsoft") != -1 && (this.d_platForm.indexOf("Win") != -1 || this.d_platForm.toLowerCase().indexOf("ce") != -1))&&navigator.userAgent.indexOf("Opera") == -1?true:false;

}
//Creates the detection object.
function SuperObj(gecko_val,gecko_require){
	this.d_appName = navigator.appName;
	this.d_appVersion = navigator.appVersion;
	this.d_platForm = navigator.platform;
	// addition
	this.hasServicePack = false
	this.passGecko = false;
	// end addition
	this.GetActiveX = GetActiveX;
	
	this.hasActiveX = this.GetActiveX();
	hasActiveX = this.hasActiveX;
	if(this.d_appName.indexOf("Micro") != -1) this.strippedAppVersion = FindVersionNumber();
	//addition 12-01-2004
	this.GeckoInterface = GeckoInterface;
	this.PassVersion = PassVersion
	this.browser = "";
	if(this.d_appName == "Netscape"){
		this.passGecko = this.GeckoInterface(gecko_val,gecko_require);
	}
	else if(this.d_appName.indexOf("Micro") != -1){
		this.hasServicePack = IsServicePack();
		this.browser = "ie";
	}
	//end additon
	this.GetFlashVersion = GetFlashVersion;
	flashVersion = this.GetFlashVersion();
}
//Creates the detection object named browser_object
function CreateInterface(loc,secure,gecko_val,gecko_require){
	if(secure){
		//overrides detection for https
		isSecure = secure;
	}
	else{
		isSecure = false;
	}
	de_prot = window.location.host;

	browser_object = new SuperObj(gecko_val,gecko_require);
}

//Midi Writer Code


function MidiObject(url,autostart,hidden,loop,id,enablejavascript){
	this.url = url;
	this.autostart = (autostart == null || autostart == "")?"true":autostart;
	this.hidden = (hidden != null || hidden == "")?"true":hidden;
	this.loop = (loop != null || loop == "")?"true":loop;
	this.id = (id == null || id == "")?"MidiObject":id;
	this.enablejavascript = (enablejavascript == null || enablejavascript == "")?"true":enablejavascript;
	this.addAdditionalMidiValue = addAdditionalMidiValue;
	this.render = renderMidi;
	this.additionalElements = " ";
	
}

function addAdditionalMidiValue(name,value){
	this.additionalElements += " " + name + "=" + value + " ";
}

function renderMidi(){
	var renderedString = "<embed src=\""+this.url+"\" height=\"1\" "+this.additionalElements+" width=\"1\" autostart=\""+this.autostart+"\" hidden=\""+this.hidden+"\" loop=\""+this.loop+"\" id=\""+this.id+"\"enablejavascript=\""+this.enablejavascript+"\" />"
	document.write(renderedString);
}


// End midi writer code

//---------------------------------------------------
// Toggles the display of the specified control
//---------------------------------------------------
function ToggleDisplay(ctrlId)
{
    var ctrl = document.getElementById(ctrlId);
    if (!ctrl){return;}
    if (ctrl.style.display=='none' || ctrl.style.display==null) {ctrl.style.display='';ctrl.style.height='auto';}
    else {ctrl.style.display='none';}
}
function ToggleBlockDisplay(ctrlId)
{
    var ctrl = document.getElementById(ctrlId);
    if (!ctrl){ return;}
    if (ctrl.style.display=='none'|| ctrl.style.display=='' || ctrl.style.display==null) {ctrl.style.display='block';}
    else {ctrl.style.display='none';}
}

function ToggleLeftNavDisplay(ctrlId, otherCtrls, container, heightValue)
{
	var ctrl;
	var len = otherCtrls.split('~').length;
	for (var i = 0; i < len; i++)
	{
		ctrl = document.getElementById(otherCtrls.split('~')[i]);
		if (ctrl)
			{ctrl.style.display = 'none';}
	}
    ctrl = document.getElementById(ctrlId);
    if (!ctrl){ return;}
    if ( ctrl.style.display == 'none')
		{ctrl.style.display='';}
    else 
		{ctrl.style.display='none';}
	ctrl = document.getElementById(container);
	if (ctrl)
	{
		ctrl.style.height = heightValue;
	}
}



//-----------------------------------------------------
// Start: From Jin
//-----------------------------------------------------

$(document).ready(function(){
	$(".topmenu .topmenuitem").hover(
		function() { $(".submenu", this).css("display", "block"); }, 
		function() { $(".submenu", this).css("display", "none"); }
	);
	
	$(".toggleRed").mouseover(function() {
		toggleRed(this);
	}).mouseout(function() {
		toggleRed(this);
	});		
});

/* IE6 png image fix */
function isIE6() {
	return (jQuery.browser.msie && jQuery.browser.version == "6.0");
}

function correctPNG() {
	if (isIE6()) {
		// correct img tags
		$("img[src$='.png']").each( function (i) {
			correctPNGforObject($(this));
		});
		
		// correct image input
		$("input[src$='.png']").each( function (i) {
			correctPNGforObject($(this));
		});
	}
}

function correctPNGforObject(obj) {
	if (isIE6() && obj.attr("src") != "images/blank.gif") {
		var width = obj.width();
		var height = obj.height();
		var style = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.attr("src") + "', sizingMethod='scale'); width: " + width + "px; height: " + height + "px;";
		obj.attr("style", style);
		obj.attr("src", "images/blank.gif");
	}
}

function toggleRed(anchorObj) {
	var imgTag = $(anchorObj).children("img");

	var imgSrc = imgTag.attr("src");
	if (imgSrc)
	{
	    if (imgSrc.split("_").pop() == "red.png")
		    imgSrc = imgSrc.replace("_red.png", ".png");
	    else
		    imgSrc = imgSrc.replace(".png", "_red.png");
	    imgTag.attr("src", imgSrc);
	}
	else
	{
	    var spanObject = $(anchorObj).children("span")[0];
	    if (spanObject)
	    {
	        var strFilter = spanObject.style.filter;
	        
	        
	        if (strFilter.toLowerCase().indexOf('_red.png') > 0)
	        {
	            strFilter = strFilter.toLowerCase().replace('_red.png', '.png');
	        }
	        else
	        {
	            strFilter = strFilter.toLowerCase().replace('.png', '_red.png');
	        }
	        
	        spanObject.style.filter = strFilter;
	    }
	}
}

function correctPNG4IE6() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5 && version < 7) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var onclickHandler = null;
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var oldObj = null;
            if (img.id.length > 0)
            {
                oldObj = document.getElementById(img.id);
            }
            
            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 || img.href) imgStyle = "cursor:pointer;" + 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='image');\"></span>" 
            
            if (img.getAttribute("onclick", false))
            {
                onclickHandler = img.getAttribute("onclick", false);
            }
            
            img.outerHTML = strNewHTML
            
            if (onclickHandler && oldObj)
            {
                var newObj = document.getElementById(oldObj.id);
                newObj.setAttribute("onclick", onclickHandler);
            }
            
            
            i = i-1
         }
      }
   }    
}

function hideImagesOnError(thisObj) {
	var parentNode = $(thisObj).parent();
	$("img", parentNode).hide();
}

//-----------------------------------------------------
// End: From Jin
//-----------------------------------------------------
/*-----------------------------------------------------------------------------
 * ClickOnEnter
 *
 * This checks to see if the event was fired by a click on the ENTER key
 * if so, attempts to fire the onclick event of a button, or redirects to
 * the HREF of an imageButton
 *-----------------------------------------------------------------------------
 */
function ClickOnEnter(e, ctrlId){ 
	var characterCode;
	if(e && e.which){ //if which property of event object is supported (NN4)
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	var returnCode = false;
	var handled = false;

	if(characterCode == 13) //if generated character code is equal to ascii 13 (if enter key)
	{ 
		var btn = document.getElementById( ctrlId);
		if (btn)
	    {
	        try
	        {
	            var atr;
	            // see if we have an HREF attribute on this button (like a ASP.LinkButton)
	            if (!handled)
	            {
	                atr = btn.getAttribute("href");
	                if (atr)
	                {
	                    document.location.href=atr;
	                    handled = true;
	                }
    		    }
    		    // Not handled. See if we have an onclick handler
    		    if (!handled)
    		    {
    		        atr = btn.getAttribute("onclick");
    		        if (atr)
    		        {
    		            btn.onclick();
    		            handled=true;
    		        }
    		    }
    		    if (handled)
    		    {
    		        returnCode = false;
	            }
	        }
            catch(error)
            {
	            alert(error);
            }
	    }
	}
	else{
		returnCode = true;
	}
	
	//alert(returnCode);
	return returnCode;
}

function isNumeric(e) {
	var returnValue = false;
	if(e == null){
		e = window.event;
		}
	var keyCode = (e.which) ? e.which : e.keyCode? e.keyCode : e.charCode;
	var shiftKey =  e.shiftKey;
	if ( ((keyCode >= 48) && (keyCode <= 57) && shiftKey==false) || // All numerics
		((keyCode >= 96) && (keyCode <= 105)) || // all Num Lock pad Numaricc
		((keyCode >= 33) && (keyCode <= 40)) || // all Num Lock pad Numaricc
		(keyCode == 8) || // Backspace
		(keyCode == 9) || // Tab Button
		(keyCode == 46) || // Delete Button
		(keyCode == 190) ||
		(keyCode == 13) ) // Carriage Return
	{
	    returnValue = true;
	}

	if ( e.returnValue )
	{
		e.returnValue = returnValue;
	}
	return returnValue;
}

function ValidateQuantity(ctrl)
{
	if (ctrl.value.length == 1 || ctrl.value == '10')
	{
		var qty = parseInt(ctrl.value);
		if (qty)
		{
			var passes = EnsureMinMax(qty, 1, 10);
			if (passes)
			{
				return passes;
			}
		}
	}
	ctrl.value = "1";
	/*alert('Please enter a quantity between 1 and 10');*/
	ShowJQAlert(350,300);
	ctrl.focus();
   return false;
}
// function to ensure that the value is between (inclusive)
// the min and max values provided
function EnsureMinMax(val, min, max)
{
    return ( (val >= min) && (val <= max));
}

function ValidateEnteredQuantity(ctrl)
{
    var passesTest = false;
    var qty = parseInt(ctrl.value);
    if(!( (qty >= 1) && (qty <= 10)))
    {
        alert('Enter a quantity between 1 and 10');
    }
    else
    {
        passesTest = true;
    }
    return passesTest;
}

/*-----------------------------------------------------------------------------
 * Functions to show a JQuery-based popup/ message box.
 * Usage: call JQAlert.ShowAlert(callingPage, width, height, InnerHTML); from
 * your UI code
 *-----------------------------------------------------------------------------
 */
var jqDivToClose;
var spco = false;
function ShowJQAlertLoading(popupWidth, popupHeight, divName)
{
var alertDivName;
    if (divName)
    {
       alertDivName = divName;
    }
    else
    {
        alertDivName = "JQAlert";
    }
    
    var docWidth = $(document).width();
	var docHeight = $(document).height();
	
	var bodyWidth = $("body").width();
	var bodyHeight = $("body").height();
	if(spco==true) bodyHeight = 0;
	var leftOffset = (bodyWidth - popupWidth)/2;
	var topOffset = (bodyHeight - popupHeight)/2;
	if (topOffset < 0)
		topOffset = 250;
	
	var jqa = document.getElementById(alertDivName);
	$("body").prepend(jqa);
	
	$("#" + alertDivName).css({position: "absolute",width: 1,height: 1,left: bodyWidth/2,top: bodyHeight/2,display: ""});
	$("#" + alertDivName).addClass("loading");
	$("#" + alertDivName).animate({width:popupWidth,height:popupHeight,left:leftOffset,top:topOffset}
        , "fast"
        , function(){
           $("#" + alertDivName).removeClass("loading");
            }
        );
	$("#" + alertDivName + "OK").focus();
}
function CloseJQAlertLoading()
{
    $("#loading2").css({display: "none"});
}


function ShowJQAlertTopOffset(popupWidth, popupHeight, topOffset)
{
    var alertDivName = "JQAlert";
   
    jqDivToClose = alertDivName;
    
	var docWidth = $(document).width();
	var docHeight = $(document).height();
	$("body").prepend('<div id="overlayBG"></div>');
	$("#overlayBG").bgiframe({width:930, height:parseInt(docHeight)});
	$("#overlayBG").css({opacity: 0.6,position: "absolute", "z-index":500,width: docWidth, height: docHeight,"background-color": "black"});
	
	var bodyWidth = $("body").width();
	var bodyHeight = $("body").height();
	if(spco==true) bodyHeight = 0;
	var leftOffset = (bodyWidth - popupWidth)/2;
	
	var jqa = document.getElementById(alertDivName);
	$("body").prepend(jqa);
	
	$("#" + alertDivName).css({position: "absolute",width: 1,height: 1,left: bodyWidth/2,top: bodyHeight/2,display: ""});
	$("#" + alertDivName).addClass("loading");
	$("#" + alertDivName).animate({width:popupWidth,height:popupHeight,left:leftOffset,top:topOffset}
        , "fast"
        , function(){
           $("#" + alertDivName).removeClass("loading");
            }
        );
	$("#" + alertDivName + "OK").focus();
}


function ShowJQAlert(popupWidth, popupHeight, divName)
{
    var alertDivName;
    if (divName)
    {
       alertDivName = divName;
    }
    else
    {
        alertDivName = "JQAlert";
    }
    
    jqDivToClose = alertDivName;
    
	var docWidth = $(document).width();
	var docHeight = $(document).height();
	$("body").prepend('<div id="overlayBG"></div>');
	$("#overlayBG").bgiframe({width:930, height:parseInt(docHeight)});
	$("#overlayBG").css({opacity: 0.6,position: "absolute", "z-index":500,width: docWidth, height: docHeight,"background-color": "black"});
	
	var bodyWidth = $("body").width();
	var bodyHeight = $("body").height();
	if(spco==true) bodyHeight = 0;
	var leftOffset = (bodyWidth - popupWidth)/2;
	var topOffset = (bodyHeight - popupHeight)/2;
	if (topOffset < 0)
		topOffset = 250;
	
	var jqa = document.getElementById(alertDivName);
	$("body").prepend(jqa);
	
	$("#" + alertDivName).css({position: "absolute",width: 1,height: 1,left: bodyWidth/2,top: bodyHeight/2,display: ""});
	$("#" + alertDivName).addClass("loading");
	$("#" + alertDivName).animate({width:popupWidth,height:popupHeight,left:leftOffset,top:topOffset}
        , "fast"
        , function(){
           $("#" + alertDivName).removeClass("loading");
            }
        );
	$("#" + alertDivName + "OK").focus();

}

function CloseJQAlert()
{
	var bodyWidth = $("body").width();
	var bodyHeight = $("body").height();
	$("#" + jqDivToClose).animate({height:1,width:1,left:bodyWidth/2,top:bodyHeight/2}
		, function() {
			if ($.browser.msie && $.browser.version < 7) $("select").show();
			$("#overlayBG").remove();
			$("#" + jqDivToClose).css({display: "none"});
			}
		);
}
/* 
 *Checks to make sure that that checkID control is not selected
 * when testID control is selected
 */
function EnsureSingleSelection(selectedID, testID)
{
    var sel = document.getElementById(selectedID);
    if (!sel)
    {
        return false;
    }
    var test = document.getElementById(testID);
    if (test)
    {
        if (sel.checked)
        {
            test.checked = false;
        }
    }
}

function ValidateEmail(emailAddress)
{
    var reEmail = /^.+\@.+\..+$/
    return reEmail.test(emailAddress);
}
function ValidateNumeric(inputString)
{
    var reNumeric = /^\d+$/
    return reNumeric.test(inputString);
}
/* Evaluates an expression to make sure it is in the
 * dd/MM/yyyy format. Will accept:
 * dd/MM/yyyy or dd-MM-yyyy or dd.mm.yyyy
 */
function ValidateEuroDate(dateString)
{
    var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    var isValid = false;
    var reDate = /^\d{1,2}[-\.\/]\d{1,2}[-\.\/]\d{4}/
    var reDelimiters = /[-\.\/]/
    var dateIsValid = false;
    if (!reDate.test(dateString))
    {
        isValid = false;
    }
    else // the string passed the format test. now check the values
    {
        dateIsValid = true;
        var datePieces = dateString.split(reDelimiters);
        if (datePieces.length != 3)
        {
            isValid = false;
        }
        else
        {   // we have 3 pieces. evaluate them
            var month = (+datePieces[1]);
            var day = (+datePieces[0]);
            var year = (+datePieces[2]);
            dateIsValid = (year > 1900) && (year < 2050);
            if (dateIsValid) { dateIsValid = (month >= 1) && (month <= 12); }
            if (dateIsValid){ dateIsValid = (day <= monthDays[month -1]);}
            isValid = dateIsValid;
        }
    }
    return isValid;
}