/*
COMMON JQUERY FILE
FUNCTIONS DECLARED IN THIS FILE
WIL BE AVAILABLE IN THE ENTIRE SITE.
Developed By: Steve Curry
July 12, 2009
*/

/**
This function will be called as soon as the DOM is ready.
A kind of AutoRun function.
*/

$(document).ready(function()
{
	PEPS.rollover.init();
})

PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();
     
      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/_o\./, '.');
   }
};

function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      alert('Invalid Email Address');
      return false;
   }
}

/**
* Function used to set the value of value of input boxes.
* @param val > current value of the input box.
* @param defval > default value of input box.
*/

function setDefaultVal(element, val, defval)
{
	if (val == defval)
	{
		element.value = "";
	}
	else if (val == "")
	{
		element.value = defval;	
	}
}

/**
* This function is called on pressing the Go button of Search
* If the input field contains "Enter text to search" it will first
* make it blank before submitting otherwise, it will submit with the
* actual form value.
* @param val string (Value of the input box)
*/
function searchOnSubmit(val)
{
	if (val == 'Enter text to search')
	{
		document.frmSearch.query.value = "";	
	}
	return true;
}
