function ajaxObject(){
	var xmlhttp=false;
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }   catch (E) {
                xmlhttp = false;
            }
        }

        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
    }

function ltrim(s) {
     return s.replace(/^\s+/, "");
}
function rtrim(s) {
       return s.replace(/\s+$/, "");
}
function trim(s) {
     return rtrim(ltrim(s));
}
function changeClass(id,nuevaclase){
               var objeto = document.getElementById(id);
               //alert(id);
               //alert(objeto.innerHTML);
               objeto.className = nuevaclase;
}

function Validate_String(string, return_invalid_chars)
         {
         valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         invalid_chars = '';
         
         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++)
            {
            char = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(char) == -1)
              {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(char) == -1)
                {
                //If it's not, add it.
                if(invalid_chars == '')
                   invalid_chars += char;
                else
                   invalid_chars += ', ' + char;
                }
              }
            }                     
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '')
           {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1)
              invalid_chars = invalid_chars.substr(0, $last_comma) + 
              ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
                      
           return(invalid_chars);
           }
         else
           return(invalid_chars == ''); 
         }


function Validate_Email_Address(valor){
         if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
			return (true)
		}else{
			return (false);
	}
}
         
         
function cleanField(field){
	field.value=trim(field.value);
}




var originalEmail = "example[@]yahoo.com";
var originalZip = "zip code";
function sendSignUp(){
            var mail = document.getElementById('signUpMail');
            var zip = document.getElementById('signUpZipcode');
            document.getElementById('emailSignUpDiv').className = 'signAlert0';
            document.getElementById('zipSignUpDiv').className = 'signAlert0';
            mail.value=trim(mail.value);
            zip.value=trim(zip.value);
            signUpAjax = new ajaxObject();
            var pageCall="/caller/suscribe.php?email="+mail.value+"&zip="+zip.value;
            signUpAjax.open("GET",pageCall,true);
            signUpAjax.onreadystatechange=function() {
                          if (signUpAjax.readyState==4) {
                                 var id=signUpAjax.responseText;
                                 if(id == "0" || id==0){//No errors occured
                                       var sPath="/index.php/modals/thanksSignUp/";
					        Shadowbox.open({
						        content:    sPath,
						        player:     "iframe",
						        height:     550,
						        width:      754
					    	});
                                       mail.value=originalEmail;;
                                       zip.value=originalZip;
                                 }else{
                                          switch(id){
                                                 case 2: case 3:
                                                          document.getElementById('emailSignUpDiv').className = 'signAlert';
          						  document.getElementById('zipSignUpDiv').className = 'signAlert';
                                                 break;
                                                 case 5: 
                                                      document.getElementById('emailSignUpDiv').className = 'signAlert';
                                                 break;
                                                 case 4: 
                                                      document.getElementById('zipSignUpDiv').className = 'signAlert';
                                                 break;
                                                 default: 
                                                      document.getElementById('emailSignUpDiv').className = 'signAlert';
          					      document.getElementById('zipSignUpDiv').className = 'signAlert';
                                                 break;
                                         }
                                 }
                          }
            }
            signUpAjax.send(null);
}

function sendSignUpPage(){
            var mail = document.getElementById('signUpMail1');
            var zip = document.getElementById('signUpZipcode1');
            document.getElementById('emailSignUpDiv1').className = 'signAlert0';
            document.getElementById('zipSignUpDiv1').className = 'signAlert0';
            mail.value=trim(mail.value);
            zip.value=trim(zip.value);
            signUpAjax = new ajaxObject();
            var pageCall="/caller/suscribe.php?email="+mail.value+"&zip="+zip.value;
            signUpAjax.open("GET",pageCall,true);
            signUpAjax.onreadystatechange=function() {
                          if (signUpAjax.readyState==4) {
                                 var id=signUpAjax.responseText;
                                 if(id == "0" || id==0){//No errors occured
                                       var sPath="/index.php/modals/thanksSignUp/";
					        Shadowbox.open({
						        content:    sPath,
						        player:     "iframe",
						        height:     550,
						        width:      754
					    	});
                                       mail.value=originalEmail;
                                       zip.value=originalZip;
                                 }else{
                                           if(id == "5" || id==5){
                                           	document.getElementById('emailSignUpDiv1').className = 'signAlert';
                                           }
                                           if(id == "4" || id==4){
                                           	document.getElementById('zipSignUpDiv1').className = 'signAlert';
                                           }
                                 }
                          }
            }
            signUpAjax.send(null);
}


function checkExampleEmail(field){
	var actual = trim(field.value);
	if(actual == ""){
		field.value = originalEmail;
	}
	if(actual == originalEmail){
		field.value="";
	}
}
function checkExampleZip(field){
	var actual = trim(field.value);
	if(actual == ""){
		field.value = originalZip;
	}
	if(actual == originalZip){
		field.value="";
	}
}
