/*functions for swaping images on mousehover*/
function MM_swapImgRestore() { //v3.0
  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() { //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_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
  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 openpopup(url,popup_name,height,width,other_properties)
{
	var left		= parseInt((screen.width-350)/2);
	var top			= parseInt((screen.height-300)/2)	
	var win_options = 'height='+height+',width='+width+',resizable=yes,' 
	+ 'scrollbars=yes,left=' + left + ',top=' + top;
//	alert(toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=500');
	window.open(url,popup_name,win_options);
//	window.open(url);
}
function checkDate(date_value)
{
	//valid format is DD/MM/YYYY
	
	var val_chk_dt = date_value.split("/");
	new_date = new Date(val_chk_dt[2],val_chk_dt[1]-1,val_chk_dt[0], 00, 00, 00);
	//var dateexpr =/^\([0-9][0-9]\)\\-\([0-9][0-9]\)\\-\([0-9]{4}\)/;
	//var dateexpr =/^\([0-9][0-9]\)\/\([0-9][0-9]\)\/\([0-9]{4}\)/; 

	if(new_date.getFullYear()!=val_chk_dt[2]||new_date.getDate()!=val_chk_dt[0]||new_date.getMonth()!=val_chk_dt[1]-1){
		alert("Please enter valid date in DD/MM/YYYY format!");
			return false;
	}	
	return true;

}
/// Tool Tips

function doTooltip(e, msg) {//alert(msg);
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ){ 
	return; 
  }
  Tooltip.show(e, msg);
}
function hideTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.hide();
}

function IsInt(sText)
{
   var ValidChars = "0123456789";
   var IsInt=true;
   var Char;
   var sText1 = sText.value;
   //alert(sText+sText1);
   for (i = 0; i < sText1.length && IsInt == true; i++) 
   { 
      Char = sText1.charAt (i ); 
      if (ValidChars.indexOf(Char) == -1) 
      {
		 //alert("Enter Integer value.");
		 IsInt = false;
      }
   }
  // alert(IsInt);
   return IsInt;
}
function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function simplePreload()
{ 
	var args = simplePreload.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i < args.length; i++)
	{
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

function checksearch()
{
var obj = document.getElementById('searchtxt');
var objcat_id = document.getElementById('cat_id');
var objprice = document.getElementById('price_range');
var txt = obj.value;
var txtcat_id = objcat_id.value;
var txtprice = objprice.value;
if(txt == '' || txt == 'Search')
{
alert('Please enter keyword to search ');
obj.focus();
return false;
}
else
{
window.location.href="search.php?searchtxt="+txt+"&cat_id="+txtcat_id+"&price_range="+txtprice;
}
return true;
}

function checksearchTop()
{
var obj = document.getElementById('searchtxtTop');
var txt = obj.value;
if(txt == '' || txt == 'Search')
{
alert('Please enter keyword to search ');
obj.focus();
return false;
}
else
{
window.location.href="search.php?searchtxt="+txt;
}
return true;
}