function trim(sStr)
{
   var s;
   sStr = sStr.toString();
   sStr = sStr.replace(/(^\s*)|(\s*$)/g,"");
   sStr = sStr.replace(/\s{2,}/g," "); /*----- Removes the unwanted spaces(more than one)-----*/
   return(sStr);
}/*---- Regular expression functions for clearing the spaces ----*/



function clear_spaces(formName)
{
	var element_all =  formName.elements;
	var i;
	for(i=0;i<element_all.length;++i)
	{
			if ((element_all[i].type == "text")||(element_all[i].type == "textarea"))
				element_all[i].value = trim(element_all[i].value);
	}
}/*----- Trim all the text boxes Only-----*/

function checkText(obj)
{
/*-----The trim function has to be called before calling this function -----*/
/*---- Later , type will be passed as a parameter so that the type will be like email, phone no , numeric, character ---*/

if(obj.value == "")
	{
		return false;
	}
else
	return true;
}/*---- Checks the text box for empty string -----*/

function checkConfPassword(obj1,obj2)
{
	//alert(obj1+"&"+obj2);
/*-----The trim function has to be called before calling this function -----*/

if(obj1.value != "" && obj2.value != "")
	{
		if(trim(obj1.value) != trim(obj2.value))
		return false;
		else
		return true;
	}
else
	return false;
}/*---- Checks the cofirm password and password are same -----*/

function checkCombo(obj)
{
/*-----The trim function has to be called before calling this function -----*/
/*---- Later , type will be passed as a parameter so that the type will be like email, phone no , numeric, character ---*/
if(trim(obj.value) == "0")
	{
//		alert("Please enter the "+name);
		//obj.focus();
		return false;
	}
else
	return true;
}/*---- Checks the text box for empty string -----*/


function checkEqual(string1,string2)
{
	var retVal = (string1 === string2) ? true : false;
	return retVal;
}/*-----checkEqual()----*/

function checkSelected(obj)
{
	//alert(obj);
	/*if(obj.options[obj.selectedIndex].value == 0 )
		return false;
	else
	return true;*/
return (obj.options[obj.selectedIndex].value == 0 ) ? false : true;
//alert(obj.selectedIndex);
//return (obj.selectedIndex == -1 ) ? false : true;
}/*----checkSelected()-----*/

function checkMSelected(obj)
{
	//alert(obj);
var i = 0;
for( i =0 ;i< obj.length; i++)
	{
	 if ((obj[i].selected) || (obj[i].checked)) 
		 return true;
	}

return false;
}/*----checkSelected()-----*/


 function telephoneCheck(telephoneNum)
 {
 	var validCharRegExp = /^\+?[\d\- ]+$/;
	var isValid = (validCharRegExp.test(telephoneNum));
	
	return isValid;
 }
function PostalCode(postalCode)
  {
  	var validCharRegExp = /^\d[\d\- ]+$/; 
	var isValid = (validCharRegExp.test(postalCode));
	
	return isValid;
  }
 
 function OnlyAlphabetic(string)
 {
 //	if(string == "" ) return false;
 	var invalidCharRegExp = /[^a-z ]/i;
	var isValid = !(invalidCharRegExp.test(string));	
	return isValid;
 }
 //To validate Numbers only .................................
function isOnlyNumeric(string)
 {
 	if(string == "" ) return false;
 	var invalidCharRegExp = /[^\d]/;
	var isValid = !(invalidCharRegExp.test(string));	
	return isValid;
 }
 
 
function emailCheck(email)
  {
	//alert(email);
	var validCharRegExp = /^\w(\.?[-\w])*@\w(\.?[-\w])*\.([a-z]{3}(\.[a-z]{2})?|[a-z]{2}(\.[a-z]{2})?)$/i;
//var validCharRegExp = /^\w(\.?\w)*@\w(\.?[-\w])*\.([a-z]{3}(\.[a-z]{2})?|[a-z]{2}(\.[a-z]{2})?)$/i;
	

	var isValid = (validCharRegExp.test(email));
	
	
	return isValid;
}/*----- Email-----*/

  function openCalendar(element)
  {

  window.open( 'popupCalendar.php?e='+element, 'Calendar', 'top=250,left=250,width=272, height=292' );
  }/*---- openCalendar()-----*/
   
  /*function opencolorwheel(element) 
  {
  window.open('colorwheel.jpg?e='+element, 'select color', 'top=250,left=250,width=260, height=220, scrollbars=false' );
  }*/

function checkDate(fromDate, toDate) 
{
	var from = fromDate.value;
	var to = toDate.value;
	if(from != "" && to != "")
	{
		from = from.substr(0,2)+from.substr(3,1)+from.substr(5,4);
		to = to.substr(0,2)+to.substr(3,1)+to.substr(5,4);
		//alert(" from date "+ from +"\n To date :"+to);
		//alert(Date.parse(from));
		if (from <= to) 
		{
			 return true;
		}
	
	}
	else
		return true;// here if the from date or to date is empty ... no error message should be thrown
	return false;
}/*----CheckDate()-----*/

 function numbersonly(e)
{

	//alert(e);
	var unicode=e.charCode? e.charCode : e.keyCode
	//alert(unicode)
	if (unicode!=8 && unicode != 46){ //if the key isn't the backspace key (which we should allow)
	if (unicode<48||unicode>57) //if not a number
		{
			if(unicode==8 || unicode==9 || unicode==44 || unicode==32 || unicode==37 || unicode==39 || unicode==46 || unicode==45 || unicode==43)//To  enable tab index in firefox and mac.(TAB, Backspace and DEL from the keyboard)
			return true
				else
            return false //disable key press
		}
	}
}

 
 function numbersonlyYears(e)
{

//	alert(e);
	var unicode=e.charCode? e.charCode : e.keyCode
	//alert(unicode)
	if (unicode!=8 && unicode != 46){ //if the key isn't the backspace key (which we should allow)
	if (unicode<48||unicode>57) //if not a number
		{
			if(unicode==8 || unicode==9)//To  enable tab index in firefox and mac.(TAB, Backspace and DEL from the keyboard)
			return true
				else
            return false //disable key press
		}
	}
}
 function numbersonlyProfile(e)
{

var k;
//alert(e.keyCode);
document.all ? k = e.keyCode : k = e.which;
return ((k > 47 && k < 58) || (k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 9 ||  k == 39 || k == 46 || k == 32 || k == 0);
}

function cancel()
{
window.history.back(-1);
}/*---Cancel()---*/

function isOnlyAlphaNumeric(string)
 {
	if(string == "") return false;
 	var invalidCharRegExp = /([a-zA-Z][0-9])|[0-9]/i;
	var isValid = (invalidCharRegExp.test(string));
	if(isValid){
	  var invalidCharRegExp1 = /[\W]/i;
	  var isValid1 = !(invalidCharRegExp1.test(string));
	  return isValid1;
	 } else {
		 return isValid;
	 }
 }

function alphaOnly(e) {
	var k;
	document.all ? k = e.keyCode : k = e.which;
	return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 9 || k == 32 || k == 0 || k == 95);
}

function validate(obj)
{
	obj1 = trim(obj.value)
	if(obj1 == "")
	{		
		alert("Search Text is Empty");
		obj.focus();
		return false;
	}
	else
	return true;
}/*----- Validate Search Text is empty or not-----*/

	function ValidateDate(CtrlSDate,CtrlEDate)   {
		var SDate = CtrlSDate;    	
		var EDate =  CtrlEDate;
		var endDate = new Date(EDate);    	
		var startDate= new Date(SDate);
		 alert(startDate);
		if(SDate != '' && EDate != '' && startDate > endDate)   {	   
			return false;
		}        
	}

	function clearSearch(val){
		
		if(document.getElementById(val).value=='Search'){
			document.getElementById(val).value='';
		}
	}
	function getSearchVal(val){
		
		if(document.getElementById(val).value==""){
			document.getElementById(val).value='Search';
		}
	}
	
	
	
	function clearEmaill(val){
		
		if(document.getElementById(val).value==val){
			document.getElementById(val).value='';
		}
	}
	function getEmailVal(val){
		
		if(document.getElementById(val).value==""){
			document.getElementById(val).value=val;
		}
	}
/* ++++++++++++++++++ Phone Number Validation +++++++++++++++++++++++++ */
	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;

	function isInteger(s)
	{   var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	function trim(s)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
	function stripCharsInBag(s, bag)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}

	function checkInternationalPhone(strPhone){
		var bracket=3
		strPhone=trim(strPhone)
		if(strPhone.indexOf("+")>1) return false
		if(strPhone.indexOf("-")!=-1)bracket=bracket+1
		if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
		var brchr=strPhone.indexOf("(")
		if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
		if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}
	function popup(url) 
	{
		 var width  = 700;
		 var height = 575;
		 var left   = (screen.width  - width)/2;
		 var top    = (screen.height - height)/2;
		 var params = 'width='+width+', height='+height;
		 params += ', top='+top+', left='+left;
		 params += ', directories=no';
		 params += ', location=no';
		 params += ', menubar=no';
		 params += ', resizable=yes';
		 params += ', scrollbars=yes';
		 params += ', status=no';
		 params += ', toolbar=no';
		 newwin=window.open(url,'windowname5', params);
		 if (window.focus) {newwin.focus()}
		 return false;
	}
	
	
	
	/* Time Display */
	function startclock()
	{
		var thetime=new Date();

		var nhours=thetime.getHours();
		var nmins=thetime.getMinutes();
		var nsecn=thetime.getSeconds();
		var nday=thetime.getDay();
		var nmonth=thetime.getMonth();
		var ntoday=thetime.getDate();
		var nyear=thetime.getYear();
		var AorP=" ";

		if (nhours>=12)
			AorP="PM";
		else
			AorP="AM";

		if (nhours>=13)
			nhours-=12;

		if (nhours==0)
		   nhours=12;

		if (nsecn<10)
		 nsecn="0"+nsecn;

		if (nmins<10)
		 nmins="0"+nmins;

		if (nday==0)
		  nday="Sunday";
		if (nday==1)
		  nday="Monday";
		if (nday==2)
		  nday="Tuesday";
		if (nday==3)
		  nday="Wednesday";
		if (nday==4)
		  nday="Thursday";
		if (nday==5)
		  nday="Friday";
		if (nday==6)
		  nday="Saturday";

		nmonth+=1;

		if (nyear<=99)
		  nyear= "19"+nyear;

		if ((nyear>99) && (nyear<2000))
		 nyear+=1900;

		document.getElementById('clockspot').innerHTML=nday+", "+ntoday+"-"+nmonth+"-"+nyear+" "+nhours+": "+nmins+": "+nsecn+" "+AorP;

		setTimeout('startclock()',1000);
		//calcTime('Australia', '+5.5');
	}

	function calcTime(city, offset) {

		// create Date object for current location
		d = new Date();
		alert(d.getHours());
		// convert to msec
		// add local time zone offset
		// get UTC time in msec
		utc = d.getTime() + (d.getTimezoneOffset() * 60000);

		// create new Date object for different city
		// using supplied offset
		nd = new Date(utc + (3600000*offset));
		
		// return time as a string
		//alert("The local time in " + city + " is " + nd.toLocaleString());

	}
