var over = false;

function showsideen(menu,ohoming,where,delay) {
    over = true;
		omenu=document.getElementById(menu);
		omenu.style.visibility='visible';
}

function hidesideen(menu){
		omenu=document.getElementById(menu);
		omenu.style.visibility='hidden';
		over = false;
}

function showside(menu,ohoming,where,delay) {
   	 
		if (typeof delay=="undefined") delay=200;
    // vvvv does not work, ff has no window.event?
    // if (typeof ohoming=="undefined") ohoming=window.event.srcElement;

    omenu=document.getElementById(menu);
    if (!omenu) return; 

    if (omenu.style.visibility=='visible') {
      //this._clear_hide(omenu);
      return;
    }

    //omenu.menu_data={delay: delay, homing:ohoming, otimeout:'none'}
    //omenu.onmouseover=this._onmouseover;
    //omenu.onmouseout=this._onmouseout;
		
    pos=getEdges(ohoming);
   	
		if(ctmenu._browser_type=='ff') {
			omenu.style.left=pos.left + ohoming.offsetWidth;
			omenu.style.top=pos.top;//omenu.style.left=pos.left; omenu.style.top=pos.bottom; 
    } else {
			omenu.style.left=ohoming.offsetWidth;
			omenu.style.top=omenu.parentNode.offsetTop - 3;
		}
		
//    omenu.style.left=0; omenu.style.top=0;

    omenu.style.visibility='visible';
  }

 function getEdges(what){
    var pos={left:what.offsetLeft, top:what.offsetTop}
    var parent=what.offsetParent;
//    var buf='';
    // 2007-01-15 joel: add offsetParent positioning check 
    while (parent && parent.style.position!='absolute'){
      pos.left+=parent.offsetLeft 
      pos.top+=parent.offsetTop 
      parent=parent.offsetParent;
//      buf+=pos.left+','+pos.top+' | ';
    }
    pos.right=pos.left+what.offsetWidth;
    pos.bottom=pos.top+what.offsetHeight;
//    alert(what.shape);
    return pos;
  }

function hideside(menu){
	if(!over){
		omenu=document.getElementById(menu);
		omenu.style.visibility='hidden';
		over = false;
	}
}

function ct_hidesearch(){
	var adsearch_box = document.getElementById('adsearch_box');
	var but = document.getElementById('hidesearch_but');
	
	if(adsearch_box.style.display == "inline") {
		adsearch_box.style.display = "none";
		but.value = "Show";
	}
	else if(adsearch_box.style.display == "none") {
		adsearch_box.style.display = "inline";
		but.value = "Hide";
	}
}

function check_all(field){
		if(field.checked == true) checked = true;
		else checked = false;
		for(a=1;a<(document.pdf_batch.elements.length);a++){
			if(document.pdf_batch.elements[a].type == 'checkbox')
				document.pdf_batch.elements[a].checked = checked;	
		}
	}

	function pdfBatch(){
		checked = false;
		for(a=1;a < (document.pdf_batch.elements.length);a++){
			if(document.pdf_batch.elements[a].type == 'checkbox')
				if(document.pdf_batch.elements[a].checked == true){
					checked = true;
					break;
				}
			}
		
		if(checked){
			if(confirm("Are you sure you want to generate pdf brochure(s) with this selection?"))
				{
					document.pdf_batch.pdfgo.value = 1;
					document.pdf_batch.submit();
				}
		} else alert("Please select at least one technology for E-brochure generation");
}

function adsearch_check(){
	var changed_date = document.adsearch_form.to_day.value + document.adsearch_form.to_month.value + document.adsearch_form.to_year.value + document.adsearch_form.from_day.value + document.adsearch_form.from_month.value + document.adsearch_form.from_year.value;  
	var trimmed_date = changed_date.replace(/^\s+|\s+$/g, '');
	var changed_str = document.adsearch_form.search_str1.value + document.adsearch_form.search_str2.value + document.adsearch_form.search_str3.value + document.adsearch_form.search_str4.value;
	var trimmed_str = changed_str.replace(/^\s+|\s+$/g, '');
	
	var to_date = document.adsearch_form.to_year.value + "" +  document.adsearch_form.to_month.value + "" + document.adsearch_form.to_day.value;
	var from_date = document.adsearch_form.from_year.value + "" + document.adsearch_form.from_month.value + "" + document.adsearch_form.from_day.value;

	if(trimmed_str == ""){
		alert("Please enter data for search");
		return false;
	}
	else if(trimmed_date != "--"){
		if(document.adsearch_form.to_day.value == ""){
			alert("Please complete all fields for the range of publication date");
			return false;
		}
		else if(document.adsearch_form.to_month.value == ""){
			alert("Please complete all fields for the range of publication date");
			return false;
		}
		else if(document.adsearch_form.to_year.value == "-"){
			alert("Please complete all fields for the range of publication date");
			return false;
		}
		else if(document.adsearch_form.from_day.value == ""){
			alert("Please complete all fields for the range of publication date");
			return false;
		}
		else if(document.adsearch_form.from_month.value == ""){
			alert("Please complete all fields for the range of publication date");
			return false;
		}
		else if(document.adsearch_form.from_year.value == "-"){
			alert("Please complete all fields for the range of publication date");
			return false;
		} else if(parseInt(from_date) > parseInt(to_date)) {
			alert("Please make sure the from date is earlier than the to date");
			return false;
		} else document.adsearch_form.submit();
	} else {
		document.adsearch_form.submit();
	}
}
