//General site scripts

//Function to 'trim' whitespace from strings.
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}



//Email Validation Class
function EmailCheck(email){
  this.email=email;
  }

    function getEmail(){
      return this.email;
      }

    function validate(){
      var pattern=/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/;
        if(pattern.test(this.email)){
        return true;
        }
        else{
        return false;
        }
    } 

  
    EmailCheck.prototype.getEmail=getEmail;
    EmailCheck.prototype.validate=validate;
    
//End Email Validation Class


//AJAX Class
function Ajax(){
  this.handle=false;
  //Check for IE
  try{
    this.handle=new ActiveXObject("Msxml2.XMLHTTP");
    this.browser="IE7";
  }
  catch(e){
    try{
      this.handle=new ActiveXObject("Microsoft.XMLHTTP");
      this.browser="IE6";
      }
      catch(e){
        this.handle=false;
        }
      }
  if(!this.handle && typeof XMLHttpRequest!="undefined"){
    this.handle=new XMLHttpRequest();
    this.browser="Mozilla";
  }
}

//End AJAX CLASS




//Preload Images
function loadImages(){

//Define variables
var i;
var jpgs=new Array();
var gifs=new Array();
var pngs=new Array();


  if(document.images){
    var jpegs=new Array();
    var gfs=new Array("butShop","butTreatments","butPress","butStudio");
    var png=new Array();
    
    
    //JPEGS
    if(jpegs.length){
      for(i=0;i<jpegs.length;i++){
        jpgs[i]=new Image();
        jpgs[i].src="images/"+jpegs[i]+"_over.jpg";
      }
    }
    
    //GIFS
    if(gfs.length){
      for(i=0;i<gfs.length;i++){
        gifs[i]=new Image();
        gifs[i].src="images/"+gfs[i]+"_over.jpg";
      }
    }
    
    //PNGS
    if(png.length){
      for(i=0;i<png.length;i++){
        pngs[i]=new Image();
        pngs[i].src="images/"+png[i]+"_over.jpg";
      }
    }
    
  }
}
  
  
  
function rollOn(id,ext){
  //handles rollover for buttons
  alert("ON");
  
  var extn;
  if(ext=="j"){
    extn=".jpg";
  }
  if(ext=="g"){
    extn=".gif";
  }
  if(ext=="p"){
    extn=".png";
  }
  
  document.getElementById(id).src="images/"+id+"_over"+extn;
    
  }

function rollOff(id,ext){
  //handles rollover for buttons
  var extn;
  if(ext=="j"){
    extn=".jpg";
  }
  if(ext=="g"){
    extn=".gif";
  }
  if(ext=="p"){
    extn=".png";
  }
  
  document.getElementById(id).src="images/"+id+extn;
    
  }
  
  
function cancelApp(app){
  var choice=confirm("If you cancel this application, all information relating to this application will be deleted.  Are you sure you want to cancel it and delete all information?");
  if(choice){
    //remove last 9 chars from url
    var full_url=window.location.href;
    //find last position of "/" slash
    var last_slash=full_url.lastIndexOf("/");
    //truncated URL
    var trun_url=full_url.substring(0,(last_slash+1));
    trun_url+="app_delete.php?id="+app;
    window.location.href=trun_url;
  }
  else{
    return;
  }
}
    
    
      
        
        
