var leftOffset = 15;
var topOffset = 158;
var suspendImgRestore = false;
var menu_is_opening = false;
var is_swapping_image = false;

//function go()
//{
//	box = document.forms[0].WebHeader_selproject;
//	destination = box.options[box.selectedIndex].value;
//	if (destination) location.href = destination;
//}

//function gotoBasicSearch()
//{
//	location.href = "/CIFORWEB/Search/";
//}



function ValidateBasicSearch(searchId) {

	var txtSearch=document.getElementById(searchId);	
	
	if (txtSearch.value=='')
	{
		window.alert('Box(es) still empty!');
		return false;
	}
}

function PostPage(formName,page)
{
	document(formName).action = page;
	document(formName).method = "POST";
	document(formName).submit();
}

function ValidateAdvSearch(titleId,authorId,subjectId,dateId) {

	var txtTitle=document.getElementById(titleId);
	var txtAuthor=document.getElementById(authorId);
	var txtSubject=document.getElementById(subjectId);
	var txtDate=document.getElementById(dateId);

	if ((txtTitle.value=='')&& (txtAuthor.value=='')&&(txtSubject.value=='')&&(txtDate.value==''))
	{
 		window.alert('Box(es) still empty!');
		return false;
	}

}

function CheckTextBoxes(source){
	var children = document.all(source).all;
	var bolCheck=true;
	
	for (var i = 0; i < children.length; i++){
	
	var input = children(i);
	
	if (input.tagName == "INPUT" && input.type == "checkbox")
		if(input.checked == false){
			bolCheck=false;
			break;
		}
	}
	document.all("chkSelectAll").checked=bolCheck;
}
			
				
function CheckAllBoxes(source ) { 
	var children = source.all 

	for (var i = 0; i < children.length; i++) 
	{ 
		var input = children(i) 
		if (input.tagName == "INPUT" && input.type == "checkbox") 
		input.checked = document.all("chkSelectAll").checked;   
	} 
} 

function setClientDate(){

	var arrMonth = new Array();
	
	arrMonth[0]="January";
	arrMonth[1]="February";
	arrMonth[2]="March";
	arrMonth[3]="April";
	arrMonth[4]="May";
	arrMonth[5]="June";
	arrMonth[6]="July";
	arrMonth[7]="August";
	arrMonth[8]="September";
	arrMonth[9]="October";
	arrMonth[10]="November";
	arrMonth[11]="December";
	
	var arrDay = new Array();
	arrDay[0]="Sunday";
	arrDay[1]="Monday";
	arrDay[2]="Tuesday";
	arrDay[3]="Wednesday";
	arrDay[4]="Thursday";
	arrDay[5]="Friday";
	arrDay[6]="Saturday";	
	
	var currDate= new Date();
			
	document.write(arrDay[currDate.getDay()].toString()   +", " + arrMonth[currDate.getMonth()].toString()   +" "+ currDate.getDate() +", "+ currDate.getFullYear()  );		
}

var windowEnlarger = null;
function enlargeImage(fname,w,h) {
	var l = (screen.width-w)/2;
	var t = (screen.height-h)/2;

	if (!windowEnlarger || windowEnlarger.close) {
		windowEnlarger = window.open("","","width="+w+",height="+h+",top="+t+",left="+l);
		var content = "<html><head><title>Large Display</title></head>";
		content += "<body><img src=" + fname + "></body></html>";
		windowEnlarger.document.write(content);
		windowEnlarger.document.close();		
	}
}

function FileTypesCheckTextBoxes(source,index,length){
	
	var childId=source+"_"+index;
	var AllFiletype=document.all(source+"_0");
	
	if (index==0){
		if (AllFiletype.checked){
			for (var i = 1; i < length; i++){
				var child = source+"_"+i;
				document.all(child).checked=true;
			}
		}
	}
	else{
		if (document.all(childId).checked==false) 
			AllFiletype.checked=false;
		
		var checkAllFalse=false;
		//window.alert(checkAllFalse);
		for (i = 1; i < length; i++){
			var child = source+"_"+i;
				 if (document.all(child).checked){
						checkAllFalse=true;
						break;		
				 }
			}
			
		if (checkAllFalse==false) {
			AllFiletype.checked=true;
			for (i = 0; i < length; i++){
				var child = source+"_"+i;
				 document.all(child).checked=true;
			}
		}
		
	}
	
	
}


	
function TrackEnterPoint(o,e) {
	var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if (charCode==13) {
		//alert('hello');
		if (document.forms[0].WebHeader_enterPoint !=null)	{
			document.location='/Search?srcText=' + o.value + '&submit=1';
		 //document.forms[0].WebHeader_enterPoint.value=o.name;
		}
	}
}

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(forced_to_restore) { //v3.0
	if (((!suspendImgRestore || forced_to_restore) && !is_swapping_image) || (is_swapping_image && menu_is_opening)) {
		//alert('restoring');
		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
	is_swapping_image = true;
	if (menu_is_opening) {
		//alert('restoring when menu is opening');		
		MM_swapImgRestore(true);
		menu_is_opening = false;		
	}
	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];}	
	is_swapping_image=false;
}

function cacheImages () {
	var host = "http://"+window.location.host;
	var imageDir = "/images/new/buttons/";
	var i,x,pic,imgList;
	
	imgList = "btn-home.jpg|btn-research.jpg|btn-regions.jpg|btn-publications.jpg|btn-events.jpg|btn-about-cifor.jpg|btn-careers.jpg|btn-contact-us.jpg|btn-site-map.jpg|";
	imgList += "btn-home-active.jpg|btn-research-active.jpg|btn-regions-active.jpg|btn-publications-active.jpg|btn-events-active.jpg|btn-about-cifor-active.jpg|btn-careers-active.jpg|btn-contact-us-active.jpg|btn-site-map-active.jpg";

	//alert('-> ' + document.referrer + ' | ' + host);
	
	//if (document.referrer.match(/\.cifor\..+\/pen\//)) return false;
	
	x = imgList.split("|");
	
	for(i=0;i<x.length;i++) {
		pic = new Image();
		pic.src = host + imageDir + x[i];
	}
	
	ImageBuffered=true;
}

window.onload = cacheImages;
