
function ValidateSearch (form) {
  if(form.q.value == "" || form.q.value == null) {
    alert("Please enter your keywords");
    form.q.focus();
    return false;
  }
  return true;
}

function ajaxinclude(url) {
  var page_request = false
  if (window.XMLHttpRequest)
  page_request = new XMLHttpRequest()
  else if (window.ActiveXObject){
  try {
  page_request = new ActiveXObject("Msxml2.XMLHTTP")
  } 
  catch (e){
  try{
  page_request = new ActiveXObject("Microsoft.XMLHTTP")
  }
  catch (e){}
  }
  }
  else
  return false
  page_request.open('GET', url, false)
  page_request.send(null)
  writecontent(page_request)
}

function writecontent(page_request){
  if (window.location.href.indexOf("http")==-1 || page_request.status==200)
  document.write(page_request.responseText)
}

function BnrClick (id) {

  var d = new Date();

  var purl = "/cgi-bin/searchapp/bcp.cgi?id=" + id + "&t=" + d.getTime();

  var pr = false
  if (window.XMLHttpRequest)
  pr = new XMLHttpRequest()
  else if (window.ActiveXObject){
  try {
  pr = new ActiveXObject("Msxml2.XMLHTTP")
  } 
  catch (e){
  try{
  pr = new ActiveXObject("Microsoft.XMLHTTP")
  }
  catch (e){}
  }
  }
  else
  return false
  pr.open('GET', purl, false)
  pr.send(null)

}
function addEvent(a,b,c){if(a.addEventListener) a.addEventListener(b,c,false);else a.attachEvent("on"+b,c);}
function getById(id){return document.getElementById(id);}
function hiddenDiv(n){if(getById(n)) getById(n).innerHTML=getById(n+"_").innerHTML;}
function previewImg(oFile,oImg,w,h){
	if(oFile.files){//FF
		oImg.innerHTML="<img src='"+oFile.files[0].getAsDataURL()+"' width="+w+" height="+h+" border=0 />";
	}else if(oFile.value.indexOf('\\') > -1 || oFile.value.indexOf('\/') > -1){ //IE6|IE7
		oImg.innerHTML="";//there maybe an default image
		oImg.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
		oImg.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = oFile.value;
		oImg.style.width=w+"px";
		oImg.style.height=h+"px";
	}
}
/**
  maxCount of img/div to rotate to display
  dispCount one time
  idPrefix to find the emlement by id
*/
function rotate(maxCount,dispCount,idPrefix){
	//find last index first
	var lastIndex=0;
	for(;lastIndex<maxCount;++lastIndex) if(getById(idPrefix+lastIndex).style.display=="none") break;
	for(;lastIndex<maxCount;++lastIndex) if(getById(idPrefix+lastIndex).style.display!="none") break;
	if(lastIndex>=maxCount) lastIndex=0;
	var dispStyle=getById(idPrefix+lastIndex).style.display;
	for(var i=0;i<dispCount;++i){
		getById(idPrefix+lastIndex).style.display="none";
		var j=lastIndex+dispCount;
		if(j>=maxCount) j-=maxCount;
		getById(idPrefix+j).style.display=dispStyle;
		++lastIndex;
		if(lastIndex>=maxCount) lastIndex=0;
	}
}

function writeAds(isDisplay,d,width,height){
	if(!isDisplay){return ;}
	document.write("<iframe src=\"http://c5.zedo.com/jsc/c5/ff2.html?n=305;c=2508/1;s=834;d="+d+";w="+width+";h="+height+"\" frameborder=0 marginheight=0 marginwidth=0 scrolling=\"no\" allowTransparency=\"true\" width="+width+" height="+height+"></iframe>");
}
function imgAdjust(img,w,h){
	imgAdjustBase(img, false, true, w, h);
}
function imgAdjustBase(img,zout,nov,w,h){
	if(!w) w=img.width,h=img.height;
	var sizeImg=new Image();
	sizeImg.src=img.src;
	var rate=sizeImg.width/sizeImg.height,hok,wok;//hok to avoid awkard img.height=0
	if(rate>w/h) wok=img.width=zout || sizeImg.width>w?w:sizeImg.width,hok=img.height=wok/rate;
	else hok=img.height=zout || sizeImg.height>h?h:sizeImg.height,img.width=hok*rate;
	//care must use Math.floor(...), because firefox support decimal, that may cause disaster of a pixel.
	if(!nov && h>hok) img.style.marginBottom=Math.floor((h-hok)/2),img.style.marginTop=h-hok-Math.floor((h-hok)/2);
}

