
// Wrapper functions for cookie getters and setters		
function createCookie(name,value,days) {
	var expires;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	} else {
		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);
}





// These were here before I started, can't find which page needs them as yet.
function show(div) {		
		//alert("show" + div);		
		//var IfrRef = document.getElementById('DivShim');
		var div1 = document.getElementById(div);
		div1.style.visibility = 'visible';	
		//alert("hit else statement");				
}
// This is only for the div that holds all the page content
function hide(div) {
		var div1 = document.getElementById(div);
		div1.style.visibility = 'hidden';	
}


// These are dreamweavers auto-generated code. They are used for the Company Overview page.
function MM_findObj(n, d) 
{
	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() 
{
	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_swapImgRestore() 
{
	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_preloadImages() 
{
	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];}}
}

// Popup window needed by video on index page
function PopUpWindow(url,w,h,scroll)
{
	var sc = scroll;
	var ht = h;
	var wt = w;
	window.open(url,"FileWindow",'height='+ ht +',width='+ wt +',location=no,toolbar=no,menubar=no,scrollbars=' + sc +',resizable=yes');
}


// Needed by GIR>Data Overview page
function submitGIRForm(type, text) {

	sql = "";
	table = "";
	oil_sql = "";
	rock_sql = "";

	if ((document.mainform.rocks.checked == false) && (document.mainform.oil.checked == false)) {
		document.mainform.rocks.checked = true;
		document.mainform.oil.checked = true;
	}
	
	//-check the form values----------------------------------------------------------------------------------------------
	if ((type=="country") && (document.mainform.COUNTRY.options[document.mainform.COUNTRY.selectedIndex].value == "0")) {
		alert("You must select a country to report on!");
		return false;
	} 

	if ((type=="basin") && (document.mainform.BASIN.options[document.mainform.BASIN.selectedIndex].value == "0")) {
		alert("You must select a basin to report on!");
		return false;
	} 
	
	if ((type=="sitename") && (text == "")) {
		alert("You must supply something to search for!");
		return false;
	} 
	//---------------------------------------------------------------------------------------------------------------------
	
	if (type == 'country') {
		sql = " UPPER(country)=UPPER('"+document.mainform.COUNTRY.options[document.mainform.COUNTRY.selectedIndex].value.replace('\'','\'\'') +"')";
		order = " ORDER BY COUNTRY";
	}
	if (type == 'basin') {
		sql = " UPPER(basin)=UPPER('"+document.mainform.BASIN.options[document.mainform.BASIN.selectedIndex].value.replace('\'','\'\'')+"')";
		order = " ORDER BY BASIN";
	}
	if (type == 'sitename') {
		sql = " UPPER(sitename) like '%"+text.toUpperCase()+"%'";
		order = " ORDER BY SITENAME";
	}
	//---------------------------------------------------------------------------------------------------------------------
	if (document.mainform.rocks.checked == true) {
		rock_sql= "SELECT * FROM STATS_REPORT_ROCKS WHERE " + sql + order;
	} else rock_sql = ""; 

	if (document.mainform.oil.checked == true) {
		oil_sql= "SELECT * FROM STATS_REPORT_OILS WHERE " + sql + order;
	} else oil_sql = "";

	document.sendForm.rock_sql.value = rock_sql;
	document.sendForm.oil_sql.value = oil_sql;
	document.sendForm.submit();
	
}

