function Trim(str) 
{ 
 
  return LTrim(RTrim(str)); 
 
} 
 
 
function LTrim(str) 
{ 
 
  for (var i=0; str.charAt(i)==" "; i++) 
  { 
    str =  str.substring(i,str.length-1); 
  } 
  return str; 
} 
 
 
function RTrim(str) 
{ 
 
  for (var i=str.length-1; str.charAt(i)==" "; i--) 
  {   
    str = str.substring(0,i); 
  } 
  return str; 
} 
 
function enterRTrim(str) 
{ 
var whitespace = new String(" \t\n\r"); 
 
   var s = new String(str); 
 
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { 
      // We have a string with trailing blank(s)... 
 
      var i = s.length - 1;       // Get length of string 
 
      // Iterate from the far right of string until we 
      // don't have any more whitespace... 
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) 
         i--; 
 
 
      // Get the substring from the front of the string to 
      // where the last non-whitespace character is... 
      s = s.substring(0, i+1); 
   } 
 
   return s; 
 
} 
function enterLTrim(str) 
{ 
 var whitespace = new String(" \t\n\r"); 
 
   var s = new String(str); 
 
   if (whitespace.indexOf(s.charAt(0)) != -1) { 
      // We have a string with leading blank(s)... 
 
      var j=0, i = s.length; 
 
      // Iterate from the far left of string until we 
      // don't have any more whitespace... 
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1) 
         j++; 
 
      // Get the substring from the first non-whitespace 
      // character to the end of the string... 
      s = s.substring(j, i); 
   } 
   return s; 
 
} 
function enterTrim(str) 
{ 
return enterRTrim(enterLTrim(str)); 
 
} 
 
function isNum(phone) 
{ 
 var reNum=/^[0-9\-]+$/; 
	if(!reNum.test(phone)) 
	{ 
		return false; 
	} 
		return true; 
} 
function ispriceval(phone) 
{ 
 var reNum=/^[0-9\.]+$/; 
	if(!reNum.test(phone)) 
	{ 
		return false; 
	} 
		return true; 
} 
function isNumeric(elem){ 
	var reNum=/^[0-9]+$/; 
	if(!reNum.test(elem)) 
	{ 
		return false; 
	} 
		return true; 
} 
 
function isqty(elem){ 
	var reNum=/^[1-9]+$/; 
	if(!reNum.test(elem)) 
	{ 
		return false; 
	} 
		return true; 
} 
 
function isusername(usename) 
{ 
 var reNum=/^[a-zA-Z0-9\._@]+$/; 
	if(!reNum.test(usename)) 
	{ 
		return false; 
	} 
		return true; 
} 
function isAlphabet(elem){ 
	var alphaExp = /^[a-zA-Z]+$/; 
	 
	if(!alphaExp.test(elem)) 
	{ 
	    return false; 
		 
	} 
		return true; 
	 
} 
 
function ismaxlength_textarea(obj){ 
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "" 
if (obj.getAttribute && obj.value.length>mlength) 
obj.value=obj.value.substring(0,mlength) 
} 
 
function ismaxlength(obj){ 
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "" 
if (obj.getAttribute && obj.value.length>mlength) 
obj.value=obj.value.substring(0,mlength) 
} 
 
function numbersonly(myfield, e, dec) 
{ 
   var unicode=e.charCode? e.charCode : e.keyCode     
    if (unicode!=8 && unicode!=9) 
    { //if the key isn't the backspace key (which we should allow) 
    
        if (unicode<48||unicode>57)  //if not a number 
        return false //disable key press 
    }  
    return true;    
} 
function containsblanks(s) 
{ 
  for(var i = 0; i < s.value.length; i++)   
  {  
	   var charCode = (s.which) ? s.which : event.keyCode 
      var c = s.value.charAt(i); 
      if ((c == ' ') || (c == '\n') || (c == '\t')) 
      { 
          alert('The field must not contain whitespace'); 
          return false; 
      } 
	  
  } 
  return true; 
} 
 
function containsblanks(s) 
{ 
  for(var i = 0; i < s.value.length; i++)   
  { 	   
      var c = s.value.charAt(i); 
      if ((c == ' ') || (c == '\n') || (c == '\t')) 
      {    
          return false; 
      } 
	  
  } 
  return true; 
} 
function numbersonly_withde(myfield, e, dec) 
{ 
   var unicode=e.charCode? e.charCode : e.keyCode   
    if (unicode!=8) 
    { //if the key isn't the backspace key (which we should allow) 
        if ((unicode<48||unicode>57) && (unicode==45)) //if not a number 
        return false //disable key press 
    } 
} 
function popitup(url) {
	newwindow=window.open(url,'name','height=255,width=520,top=2,left=2');
	if (window.focus) {newwindow.focus()}
	return false;
}
 
function validatePwd(fieldname) { 
      //Initialise variables 
        var errorMsg = ""; 
        var space = " "; 
        //fieldname = document.myform.password; 
        fieldvalue = fieldname; 
        fieldlength = fieldvalue.length; 
 
        //It must not contain a space 
        if (fieldvalue.indexOf(space) > -1) { 
            errorMsg += "\nPasswords cannot include a space.\n"; 
        } 
        //It must contain at least one character      
        if (!((fieldvalue.match(/[A-Z]/)) || (fieldvalue.match(/[a-z]/)))) { 
            errorMsg += "\nStrong passwords must include at least one character.\n"; 
        } 
        //It must contain at least one number 
        if (!(fieldvalue.match(/\d/))) { 
            errorMsg += "\nStrong passwords must include at least one number.\n"; 
        } 
        //It must be at least 7 characters long. 
        if (!((fieldlength >= 7) && (fieldlength <= 16))) { 
            errorMsg += "\nStrong passwords must be between 7-16 characters long.\n"; 
        } 
        //If there is aproblem with the form then display an error 
        if (errorMsg != "") { 
           // msg=""; 
           // msg = "______________________________________________________\n\n"; 
           // msg += "Please correct the problem(s) with your trial password test it again.\n"; 
          //  msg += "______________________________________________________\n"; 
           // errorMsg += alert(msg + errorMsg + "\n\n"); 
           errorMsg += alert(errorMsg); 
            return false; 
        } 
        return true; 
    } 
 
 function validate_reservation() 
{ 
    if(RTrim(document.reservation.name.value)=="") 
        { 
            alert("Please enter name"); 
            document.reservation.name.focus(); 
            document.reservation.name.value=""; 
            return false; 
        } 
        if(RTrim(document.reservation.email.value)=="") 
        { 
            alert("Please enter E-mail address"); 
            document.reservation.email.focus(); 
            document.reservation.email.value=""; 
            return false; 
        } 
		
		if (document.reservation.email.value != "") 
		{ 
		        re=/\w{1,}/; 
		        emailExp= /^\w+(\-\w+)*(\.\w+(\-\w+)*)*@\w+(\-\w+)*(\.\w+(\-\w+)*)+$/ ;  
		        if(!(emailExp.test(document.reservation.email.value))) 
		        { 
		        alert("Please Enter Correct E-mail address"); 
		        document.reservation.email.focus(); 
		        return false; 
		        } 
		} 
		
		 if(RTrim(document.reservation.depart.value)=="") 
        { 
            alert("Please select arrival date"); 
            document.reservation.depart.focus(); 
            document.reservation.depart.value=""; 
            return false; 
        } 
		
		if(document.reservation.depart.value=="mm/dd/yyyy") 
        { 
            alert("Please select arrival date"); 
            document.reservation.depart.focus(); 
            document.reservation.depart.value=""; 
            return false; 
        } 
		if(document.reservation.return1.value=="mm/dd/yyyy") 
        { 
            alert("Please select return date"); 
            document.reservation.return1.focus(); 
            document.reservation.return1.value=""; 
            return false; 
        } 
	
    
	return true; 
}



function cancel_validate() 
{ 
    if(RTrim(document.cancel.name.value)=="") 
        { 
            alert("Please enter name"); 
            document.cancel.name.focus(); 
            document.cancel.name.value=""; 
            return false; 
        } 
		
		
		if(RTrim(document.cancel.phone.value)=="") 
        { 
            alert("Please enter phone"); 
            document.cancel.phone.focus(); 
            document.cancel.phone.value=""; 
            return false; 
        } 
		
		if(RTrim(document.cancel.confirmation.value)=="") 
        { 
            alert("Please enter confirmation number"); 
            document.cancel.confirmation.focus(); 
            document.cancel.confirmation.value=""; 
            return false; 
        }
		


	if(RTrim(document.cancel.arrival_date.value)=="") 
        { 
            alert("Please enter lot arrival date"); 
            document.cancel.arrival_date.focus(); 
            document.cancel.arrival_date.value=""; 
            return false; 
        }
		

       if(document.cancel.arrival_date.value=="mm/dd/yyyy") 
        { 
            alert("Please enter lot arrival date"); 
           document.cancel.arrival_date.focus(); 
            document.cancel.arrival_date.value="";  
            return false; 
        } 


		if(RTrim(document.cancel.return_date.value)=="") 
        { 
            alert("Please enter return date"); 
            document.cancel.return_date.focus(); 
            document.cancel.return_date.value=""; 
            return false; 
        }


       if(document.cancel.return_date.value=="mm/dd/yyyy") 
        { 
            alert("Please enter return date"); 
           document.cancel.return_date.focus(); 
            document.cancel.return_date.value="";  
            return false; 
        } 

		
        if(RTrim(document.cancel.email.value)=="") 
        { 
            alert("Please enter E-mail address"); 
            document.cancel.email.focus(); 
            document.cancel.email.value=""; 
            return false; 
        } 
		
		if (document.cancel.email.value != "") 
		{ 
		        re=/\w{1,}/; 
		        emailExp= /^\w+(\-\w+)*(\.\w+(\-\w+)*)*@\w+(\-\w+)*(\.\w+(\-\w+)*)+$/ ;  
		        if(!(emailExp.test(document.cancel.email.value))) 
		        { 
		        alert("Please Enter Correct E-mail address"); 
		        document.cancel.email.focus(); 
		        return false; 
		        } 
		} 
		
		    
	return true; 
}


function validate_subscribe()
	{
		
		 if(RTrim(document.subscribe.names.value)=="") 
        { 
            alert("Please enter name"); 
            document.subscribe.names.focus(); 
            document.subscribe.names.value=""; 
            return false; 
        } 
		
		 if(RTrim(document.subscribe.emails.value)=="") 
        { 
            alert("Please enter E-mail address"); 
            document.subscribe.emails.focus(); 
            document.subscribe.emails.value=""; 
            return false; 
        } 
		
		if (document.subscribe.emails.value != "") 
		{ 
		        re=/\w{1,}/; 
		        emailExp= /^\w+(\-\w+)*(\.\w+(\-\w+)*)*@\w+(\-\w+)*(\.\w+(\-\w+)*)+$/ ;  
		        if(!(emailExp.test(document.subscribe.emails.value))) 
		        { 
		        alert("Please Enter Correct E-mail address"); 
		        document.subscribe.emails.focus(); 
		        return false; 
		        } 
		} 
		
		
	}
