preloadflag = true;

// opacity syntax
// filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); -moz-opacity:0.00; opacity:0.00;
//  - - uncomment for changing opacity
//	var CHANGE_SPEED = 40;
//	var CHANGE_STEP = 1;
	
// Browser Detection
var V = navigator.appVersion.substring(0,1);
var brsr = 0;
var pngOk = true;

if (V < 4) {
	top.alert("This site uses java to support its major navigation.\n You may have trouble viewing the site");
} else if (navigator.appName.indexOf("Netscape") > -1) {

} else if (navigator.appName.indexOf("Explorer") > -1) {
	pngOk = false;
	var T = navigator.appVersion.indexOf("MSIE");
	T += 5;
	V = navigator.appVersion.substring(T,eval(T+1));
	if (V >= 7) pngOk = true;
}

if (navigator.appName.indexOf("Netscape") > -1) {
	brsr = 1;
} else if (navigator.appName.indexOf("Explorer") > -1) {
	if (V < 5) {

	} else {
		brsr = 2;
	}
}


// Shared popup windows

function showContactUs() {
	contactUsWin = window.open('/include/popup_contactForm.php','contactUsWin','width=550,height=475,top=150,left=150,resizable=0,menubar=0,location=0,scrollbars=1,status=1,toolbar=0'); 
	contactUsWin.focus();
}

function showExtraInfo(textKey) {
	extraInfoWin = window.open('/include/popup_extraInfo.php?id='+ textKey,'extraInfoWin','width=550,height=350,top=150,left=150,resizable=0,menubar=0,location=0,scrollbars=1,status=1,toolbar=0'); 
	extraInfoWin.focus();
}



function centerPop(page,w,h,args){
	if (w > 0) {
	} else {
		w = 650
	}
	if (h > 0) {
	} else {
		h = 550
	}
	var width
	var height
	var leftdist
	var topdist
	width = screen.width;
	height = screen.height;
	leftdist = Math.round((width - w) / 2);
	topdist = Math.round((height - h) / 2);
	if (args = '') {
		args = 'resizable=1,menubar=0,location=0,scrollbars=1,status=1,toolbar=0';
	}
	cpw = window.open(page,'cpw','width='+ w +',height='+ h +',top='+topdist+',left='+leftdist+','+ args);
	cpw.focus();
}

// on load

	function addOnLoadEvent(func) {

	  var oldonload = window.onload;

	  if (typeof window.onload != 'function') {

		window.onload = func;

	  } else {

	//	top.alert(oldonload)
	//	top.alert(func)

		window.onload = function() {

		  if (oldonload) {
			oldonload();
		  }
		  eval (func +'()');

		}

	  }

	}


function PopWin(HEIGHT,WIDTH,URL) {
	var PopWin = window.open(URL,'PopWin',"width="+ WIDTH +",height="+ HEIGHT +",scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
	PopWin.focus()
}

// Email Spam hiding.
function popMail(host,user) {
	var acct = user +'@'+ host;
	self.location.href = 'mailto:'+ acct;
}
function linkMail(host,user,cls) {
	document.write('<a href="javascript:popMail(\''+ host +'\',\''+ user +'\');"');
	if (cls) {
		document.write(' class="'+ cls +'"');
	}
	document.write('>');
	showMail(host,user);
	document.write('</a>');
}
function showMail(host,user) {
	var acct = user +'@'+ host;
	document.write(acct);
}
	

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}


// DOM Manipulation

function getElementById(id){ 
	var el = null; 

	if (document.getElementById) {
		// isMozilla || isIE5
		el = document.getElementById(id) 
	} else if (document.layers) {
		// isNetscape4
		el = document.layers[id] 
	} else if (document.all) {
		// isIE4
		el = document.all[id]; 
	}

	return el; 
} 


function changeImages() {
//	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=3) {
		//  top.alert (document.layers[i].document[changeImages.arguments[i+1]].name)
		//document.layers[changeImages.arguments[i]].document[changeImages.arguments[i+1]].src = eval(changeImages.arguments[i+2]+".src");
			if (brsr == 1) {
		//		if (changeImages.arguments[i] != '') {
		//			document[changeImages.arguments[i+1]].src = eval(changeImages.arguments[i+2]+".src")
		//		} else {
					if (document[changeImages.arguments[i+1]]) document[changeImages.arguments[i+1]].src = eval(changeImages.arguments[i+2]+".src")
		//		}
			}
			if (brsr == 2) {
				if (document[changeImages.arguments[i+1]]) document[changeImages.arguments[i+1]].src = eval(changeImages.arguments[i+2]+".src")
			}
		}
//	}
}


function rollOver (item,state) {
	if (state) {
		changeImages('','i'+item,'i'+item+'_on');
	} else {
		changeImages('','i'+item,'i'+item+'_off');
	}
}


function setClass() { 
	var args=setClass.arguments;	
	var ston = 0;
	
	if (brsr != 0) {
		for (i = ston; i<(args.length-1); i+=2) {
			var obj = args[i];
			var cls = args[i+1];
			if (brsr == 1 && V >= 5) {
				document.getElementById(obj).className = cls;
			}
			if (brsr == 2) {
				if (document.all[obj]) {
					document.all[obj].className = cls;
				}
			}
		}
	}
}

		function showElm(elm) {
			document.getElementById(elm).style.display = "block";
		}

function showHideLayers() { 
	var args=showHideLayers.arguments;	
	var ston = 1;
	var baser = args[0];
	
	if (brsr != 0) {
		for (i = ston; i<(args.length-1); i+=2) {
			var obj = args[i];
			var vis = args[i+1];	
			if (brsr == 1 && V < 5) {
					if (document.layers[obj]) document.layers[obj].visibility = vis;
			}
			if (brsr == 1 && V >= 5) {
				if (document.getElementById(obj)) {
					document.getElementById(obj).style.visibility = vis;
				}
			}
			if (brsr == 2) {
				if (document.all[obj]) {
					document.all[obj].style.visibility = vis;
				}
			}
		}
	}
}



function delayHide() {
		if (t==0) {
				removeall();
				lCount = 0;
		}
		if (t==2) {
				lCount = 0;
		}
		if (t==1) {
				lCount = lCount + 1;
				if (lDelay <= lCount) {
						t = 0;
				}
				if (lDelay >= lCount) {
						setTimeout('delayHide(' + t + ')',pause);
				}
		}
		return false;
}


function changeOpacity(divId, x) {

	divObj = document.getElementById(divId);
	x += CHANGE_STEP;
	
	if(document.all) {
		//vrp.style.left=newX
		divObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+ parseInt(x) +");";
		
	} else {
		//vrp.style.left=(newX+"px")
		if(x >= 100) {
			divObj.style.opacity = "0.99";
		} else if(x >= 10) {
			divObj.style.opacity = eval("0."+ parseInt(x));
		} else {
			divObj.style.opacity = eval("0.0"+ parseInt(x));
		}
	}
	
	if(x < 100) {
		setTimeout("changeOpacity('"+ divId +"', "+ x +");",CHANGE_SPEED);
	} else {
		// done
	}
}

// SPECIAL

// brown bar

function resizeBrownBar() {
	
	height = document.getElementById('leftCell').offsetHeight;
		
	if (height > 460) { 
		document.getElementById('brownBar').style.height = height + "px";	
	}
}

// home page 

var prevKey = 1;
function changeToHomeIm(key) {
	if (key != prevKey) {  
		var newIm = 'homeIm' + key;
	
		changeImages("", "homeIm", newIm);
		setClass('homeIm' + key, 'home' + key + 'On');
		setClass('homeIm' + prevKey, 'home' + prevKey + 'Off');
		
		prevKey = key;
	}
}


var fields = new Array();
fields['saddle_up_email'] = 'no';
fields['saddle_up_zip'] = 'no';
var field_id;
function clearField(field_id)
{
	//alert('id: ' + field_id + "\nfield: " + fields[field_id]);
	if(fields[field_id] == 'no')
	{
		fields[field_id] = 'yes';
		document.getElementById(field_id).value = '';
	}
}


// quick contact - modality form

var tmpintoDiv;

function postProcess (reqTmp, intoDiv) {

	if (shortTimeout) {
		lastHttpRequestObj = reqTmp;
		tmpintoDiv = intoDiv;
		endShortTimeoutEval = 'postProcess(lastHttpRequestObj, tmpintoDiv)';
		
		//alert('postProcess::continue::'+ req);
		
	} else {
		getElmById(intoDiv).innerHTML = reqTmp.responseText;
		hideProcessing();
		showHideLayers('','utility','visible');
		
		lastHttpRequestObj = null;
		
		//alert('postProcess::execute::'+ req);
	}

}

function endShortTimeout () {
	
	shortTimeout = null;
	if (endShortTimeoutEval) {
		//alert('endshorttimeeval::'+ endShortTimeoutEval);
		
		eval(endShortTimeoutEval);
		endShortTimeoutEval = null;
	}

}

function getPageSizeWithScroll() {
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}

function getPagePosition () {
  var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function repositionDiv(objId,plusDistance) {
	page_pos = getPagePosition();
	document.getElementById(objId).style.top = (page_pos[1] + plusDistance) +'px';
}

function resizeCover (objId) {

	page_dims = getPageSizeWithScroll();
	document.getElementById(objId).style.height = page_dims[1]+'px';

}

var shortTimeoutLength = 1500; // 1.5 seconds
var shortTimeout = null;

var endShortTimeoutEval = null;
var lastHttpRequestObj = null;

function hideCover(id) {
	resizeCover('cover');
	//showHideLayers('','cover','hidden');
	setClass('cover','coverOff');
}

function showCover(id) { 
	resizeCover('cover'); 
	repositionDiv("utility",100); 
	setClass('cover','coverOn'); 
}

function showLayerBlock(id) {
		document.getElementById(id).style.display = 'block';
		document.getElementById(id).style.visibility = 'visible';

}

function hideLayerBlock(id) {
		document.getElementById(id).style.visibility = 'hidden';
		document.getElementById(id).style.display = 'none';
}

function showProcessing(strMsg) {	
	if (!strMsg) {
		strMsg = 'Loading...';
	}

	resizeCover('processing');
	repositionDiv('processingInfo',125);
	setClass('processing','processOn');
	document.getElementById('processingInfo').innerHTML = "<center><div id='processingWait'><div id='processingWaitInfo'>"+ strMsg +"<br><img src='/images/gen/loading_40x40.gif' width='40' height='40' vspace='5'></div></div></center>";
	
	showHideLayers('','processingInfo','visible');
	shortTimeout = setTimeout('endShortTimeout()',shortTimeoutLength)
}

function hideProcessing() {
	resizeCover('processing');
	document.getElementById('processingInfo').innerHTML = "";
	showHideLayers('','processingInfo','hidden');
	setClass('processing','coverOff');
}

function displayStandardSuccessResult() {
	hideLayerBlock('utilWinFormBlock');
	
	showLayerBlock('utilWinSuccessMsg');
	
	hideProcessing();
}

function parseForm (frm) {
	var string = '';

	for (i = 0; i < frm.elements.length; i++) {
		elm = frm.elements[i]
		
		if (elm.type == 'checkbox') {
			if (elm.checked) {
				string += '&'+ frm.elements[i].name +'='+ encodeURIComponent(frm.elements[i].value);
			}
		} else if (elm.type == 'radio') {
			if (elm.checked) {
				string += '&'+ frm.elements[i].name +'='+ encodeURIComponent(frm.elements[i].value);
			}
		} else if (elm.type == 'select') {
			if (elm.selectedindex >= 0) {
				string += '&'+ frm.elements[i].name +'='+ encodeURIComponent(frm.elements[i].options[elm.selectedIndex].value);
			}
		} else {
			string += '&'+ frm.elements[i].name +'='+ encodeURIComponent(frm.elements[i].value);
		}
	
	}

	return string

}

function showQuickContact (id) {
	showCover(); 
	showProcessing();
	
	externalFileName = '/include/utility/formQuickContact.php';
	externalFileName += '?resource_id=' + id;
	
	loadExternalFile('utility',externalFileName);
}

function validateEmailField(str) {
	if (str == '' || str.indexOf('@',1) == -1) {
		return false;
	} else {
		return true;
	}
}

function validateQuickContactForm (frm, urchinTrackerEntityKey) {
	// hide all possible visible errors - reset
	hideLayerBlock('utilWinErrorMsg');
	
	hideLayerBlock('utilWinFrmErrorName');
	hideLayerBlock('utilWinFrmErrorEmail');
	hideLayerBlock('utilWinFrmErrorComments');
	
	rtn = true;
	
	if (frm.elements['znzazmzez'].value == '') {
		showLayerBlock('utilWinErrorMsg');
		
		rtn = false;		
	}
	
	if (!validateEmailField(frm.elements['zezmzazizlz'].value)) {
		showLayerBlock('utilWinErrorMsg');
		
		rtn = false;
	}
	
	if (frm.elements['zczozmzmzeznztzsz'].value.length > 350) {
		showLayerBlock('utilWinFrmErrorComments');
		
		rtn = false;

	}
	
	if (!rtn) {
		showLayerBlock('utilWinErrorMsg');
	}
	
	return rtn;
}


function processQuickContact (frm) {
	
	showCover();
	
	endShortTimeoutEval = 'displayStandardSuccessResult()';
	showProcessing('Sending your request...');
	
	// asynchronous email handling
	externalFileName = '/include/utility/formQuickContact.php';
	externalFileName += '?'+  parseForm(frm);
	
	executeExternalFile(externalFileName);
	
}	

function closeWin() {
	hideCover();
	clearExternalFile('utility');
	showHideLayers('','utility','hidden');
}

// LOGGING CLICKS

function Click(adId, url) {
	externalFileName = '/include/utility/logging.php';
	externalFileName += '?adId='+  adId;
	
	window.open(url);
	window.focus;
	executeExternalFile(externalFileName);
}
