function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function resetFields(whichform) {
  for (var i=0; i<whichform.elements.length; i++) {
    var element = whichform.elements[i];
    if (element.type == "submit") continue;
	
    //if (!element.defaultValue) continue;
	element.onfocus = function() {
		//alert("assa");
	    if ( (this.name == "q") ) {
	      this.value = "";
	    }
    }
    element.onblur = function() {
		//alert("assa");
	    if (this.value == "") {
	      if(this.name == "q") {
		  	this.value = "Enter resort name or city";
		  }
        }
    }
  }
}

function validateForm(whichform) {
  for (var i=0; i<whichform.elements.length; i++) {
    var element = whichform.elements[i];
    if (!isFilled(element)) {
      alert("Enter resort name or city");
      return false;
  	}
  }
  return true;
}

function isFilled(field) {
  if (field.value.length < 1 || field.value == "Enter resort name or city") {
    return false;
  } else {
    return true;
  }
}

function prepareForms() {
  if (!document.getElementById) return false;
  if (!document.getElementById("topsearch")) return false;
  var theSearch = document.getElementById("topsearch");
  theSearch.value = "Enter resort name or city";
  for (var i=0; i<document.forms.length; i++) {
    var thisform = document.forms[i];
  	if(thisform.name == 'quick_search') {
		resetFields(thisform);
	    thisform.onsubmit = function() {
	      return validateForm(this);
	    }
	}
  }
}

function ReloadCat(){
  var hwJsCats = new Array("|9777|","|9755|");
  hwReloadCat('index.php?page=search','327',hwJsCats);
}

function highlightRows() {
  if(!document.getElementsByTagName) return false;
  var rows = document.getElementsByTagName("tr");
  for (var i=0; i<rows.length; i++) {
    rows[i].oldClassName = rows[i].className
    rows[i].onmouseover = function() {
      addClass(this,"highlight");
    }
    rows[i].onmouseout = function() {
      this.className = this.oldClassName
    }
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}


/*var mySlide = new Fx.Slide('pointsContainer');
 
$('toggle').addEvent('click', function(e){
	e = new Event(e);
	mySlide.toggle();
	e.stop();
});*/

addLoadEvent(prepareForms);
//addLoadEvent(ReloadCat);
addLoadEvent(highlightRows);