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 showProduct(productId) {
	if (window.opener) {
		self.opener.location.href = "/product/"+ productId +"/";
		self.close();
	} else {
		self.location.href = "/product/"+ productId +"/";
	}
}

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; 
} 



// Email Spam hiding.
function popMail(host,user) {
	var acct = user +'@'+ host;
	self.location.href = 'mailto:'+ acct;
}

function popMailAdvanced(host,user,subj,copy) {
	var string = user + '@' + host + '?subject=' + subj + '&body=' + copy;

	self.location.href = 'mailto:'+ string;
}

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 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();
}


function centerPopMenu(page,w,h){

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);

gwin = window.open(page,'gwin','width='+ w +',height='+ h +',top='+topdist+',left='+leftdist+',resizable=1,menubar=1,location=0,scrollbars=1,status=1,toolbar=0');
gwin.focus();

}

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

		//img_on	= newImage("/pics/index_nav/index_con.gif");
		//img_off	= newImage("/pics/index_nav/index_con.gif");
	}

	
	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 changeImagesStr() {
			for (var i=0; i<changeImagesStr.arguments.length; i+=3) {
				if (brsr == 1) {
						document[changeImagesStr.arguments[i+1]].src = changeImagesStr.arguments[i+2]
				}
				if (brsr == 2) {
					document[changeImagesStr.arguments[i+1]].src = changeImagesStr.arguments[i+2]
				}
			}
	}

	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;
	}


var fields = new Array();
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 = '';
	}
}

//MODAL

var close_modal = '<div id="close_modal"><a href="javascript:clear_modal()">Close</a></div>';

function display_modal(content,container)
{
	page_dims = getPageSizeWithScroll();
	var height = page_dims[1] + 300;
	//alert(height+'px');
	page_pos = getPagePosition();
	document.getElementById('OuterContainer').style.top = (page_pos[1] < 99 ? 99 : page_pos[1] + 99) + 'px';
	document.getElementById('blackOut').style.display = 'inline';
	document.getElementById('blackOut').style.height = height+'px';
	document.getElementById('OuterContainer').style.display = 'inline';
	document.getElementById('InnerContainer').innerHTML = content + close_modal;
}

function clear_modal()
{
	document.getElementById('blackOut').style.display = 'none';
	document.getElementById('OuterContainer').style.display = 'none';
	document.getElementById('InnerContainer').innerHTML = '';
	document.getElementById('InnerContainer').style.width = '600px';
}

function getPageSizeWithScroll()
{
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY + 100;
		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 launchVideoModal(id)
{
	display_modal('<div id="videoSpot"></div>');
	var FO = { movie:"http://www.circumerrovideo.com/v/c/projectid=32321&programid=" + id,
			   width:"510",
			   height:"330",
			   majorversion:"8",
			   build:"0",
			   wmode:"transparent",
			   bgcolor: "none",
			   quality: "high",
			   allowFullScreen: "true",
			   align: "middle" };
	UFO.create(	FO, "videoSpot");
}

// GOOGLE MAP

function googleMapIframe(iframe_src,link_href)
{
var iframe = '<iframe width="445" height="275" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' + iframe_src + '"></iframe><br /><small><a href="' + link_href + '" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
document.write(iframe);
}

// ADDING TO PROTOTYPE 

var MyUtils = {
	showDD: function (element) {
		element = $(element);
		// getElementById('newsList').appendChild(element);
		return element.show();
	},

	hideDD: function (element) {
		element = $(element);
		return element.hide();
	},
	
	ddDown: function (element) {
		element = $(element);
		return element.blindDown();
	},
	
	ddUp: function (element) {
		element = $(element);
		return element.blindUp({ duration: 1 });
	}
}

Element.addMethods(MyUtils);


// CHANGING HEIGHT OF MAIN BLOCKS ON LOAD
function resizeMainBlocks () {
	// first find height of all blocks 
	var blockArray = new Array();
	blockArray[0] = 'sidebarLeft';
	blockArray[1] = 'sidebarMiddle';
	blockArray[2] = 'sidebar';
	blockArray[3] = 'content';
	
	var heightArray = new Array();
	
	var len = blockArray.length;
	
	for(var i=0; i<len; i++) {
		if (document.getElementById(blockArray[i])) {
			var height = $(blockArray[i]).getHeight(); 
			if (height > 0) {
				heightArray.push(height);
			}	
		}	
	}
	
	// figure out which one is taller
	function sortfunction(a, b){
		return (a - b) //causes an array to be sorted numerically and ascending
	}
	
	heightArray.sort(function(a,b){return a - b});
	heightArray.reverse();
	var newHeight = heightArray[0]; 
	
	for(var i=0; i<len; i++) {
		if (document.getElementById(blockArray[i])) {
			var elm = blockArray[i]; 
			document.getElementById(elm).style.height = newHeight + 'px';
		}	
	}
}
	

// FEEDING ADS IN ARTICLE
function writeAdCode(adskey) {
//	document.write('<script type="text/javascript" src="http://ahs2.adhostingsolutions.com/oasisi-j.php?s=1253&w=420&h=96&u=ahs2.adhostingsolutions.com&t=_blank&k='+adskey+'"><\/script>');
}	
	