//Last Minute Vacation Homes Verification Script
//Copyright 2005 by Shawn Olson
//All Rights Reserved.
//http://www.shawnolson.net 

 var inv = 'Invalid';
//Group Membership
var SITEADMIN=1;

//Organization

var INDIVIDUAL=1;


var myTypes=0;

var restrictWord = new Array('fuck', 'bitch', 'asshole', 'whore', ' slut', 'queer', 'rapist', ' shit ', 'blowjob', ' fag ', 'rogaine', 'viagra', 'levitra', 'vi@gra', 'viagr@', 'vi@gr@', ' penis', ' cialis');

function badWords(word){
//this function keeps new members from choosing inappropriate names

var badword = false;
var word = new String(word);
word = word.toLowerCase();

 for (var i = 0; i<restrictWord.length; i++){
  if (word.match(restrictWord[i])){

  badword = true;
  alert("A label you chose is inappropriate for this site. Please be considerate, as children often visit this site.");
  }
 }
 return badword;
}


function checkEmail(formObj){

  var email_pass = true;
  var email_val = new String(formObj.value);
  ok = "0987654321qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM[].@-_";

  for(i=0; i <= email_val.length ;i++){
   if(ok.indexOf(email_val.charAt(i))<0){ 
    email_pass = false;

   }	
  } 
  re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
  re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  if (!email_val.match(re) && !email_val.match(re_two)) {
   email_pass = false;	
   formObj.style.color = "red";
  } else {formObj.style.color = "black";}
 return email_pass;

}


function changeVal(formObj,need,bad){

 var FnameTest = true;
 var errors;
 errors = 0;
 
 if(need==true){
  if (formObj.value=='' || formObj.value == inv){ 
   FnameTest = false;
   formObj.value = inv;
  }
 }  
  
 if(bad==true){
   badword = badWords(formObj.value);
  if (badword == true){
   FnameTest = false;
  }
 }
 
 if (FnameTest == false){
   formObj.style.color = "red";
   errors = 1;
 }
 if (FnameTest == true){
   formObj.style.color = "black";
 }

return errors;
}

function requiredFields(formObj){

 var bandMessage='';
 var errors = 0;

if (formObj.ALIAS){
  formObj.saveName.value = formObj.first_name.value;

  if(changeVal(formObj.first_name,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter your first name.';
  }
  if(changeVal(formObj.LNAME,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter your last name.';
  }
  
  if(changeVal(formObj.ALIAS,true,true)){
    errors++;
	bandMessage+='\n\nYou must choose a username for login.';
  }
  if(changeVal(formObj.BIO,false,true)){
    errors++;
	bandMessage+='\n\nYour optional profile must not contain improper content such as spam, profanity, etc.';
  }
  errors = errors + changeVal(formObj.ZIP,true,true);
  if(changeVal(formObj.ADDR,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter your billing street address.';
  }
  if(changeVal(formObj.CITY,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter your billing city.';
  }
  if(changeVal(formObj.state,true,false)){
     errors++;
     bandMessage+='\n\nYou did not enter a state/province. If you live in a country with no state/province, copy your city name into this field.';
  }
    if(changeVal(formObj.COUNTRY,true,true)){
     errors++;
     bandMessage+='\n\nYou did not select a country from our list. If you reside in a country not listed on our form, please contact us immediately and we will accomodate you.';

  }
  
  errors = errors + changeVal(formObj.company,false,true);
  errors = errors + changeVal(formObj.PHONE,true,true);
}


 if (formObj.billing_first_name){
  errors = errors + changeVal(formObj.billing_first_name,true,true);
  errors = errors + changeVal(formObj.billing_last_name,true,true);
  errors = errors + changeVal(formObj.billing_telephone,true,true);
  errors = errors + changeVal(formObj.billing_email,true,true);
  errors = errors + changeVal(formObj.billing_COUNTRY,true,true);
  errors = errors + changeVal(formObj.billing_zip,true,true);
  errors = errors + changeVal(formObj.billing_state,true,true);
  errors = errors + changeVal(formObj.billing_city,true,true);

  if(formObj.shipForce.value=='true'){
  errors = errors + changeVal(formObj.shipping_first_name,true,true);
  errors = errors + changeVal(formObj.shipping_last_name,true,true);
  errors = errors + changeVal(formObj.shipping_address,true,true);
  errors = errors + changeVal(formObj.shipping_COUNTRY,true,true);
  errors = errors + changeVal(formObj.shipping_zip,true,true);
  errors = errors + changeVal(formObj.shipping_state,true,true);
  errors = errors + changeVal(formObj.shipping_city,true,true);
  }
}
  
 if (formObj.PISSWORD){
    formObj.PISSWORD.style.color = "black";
    formObj.PISSWORDR.style.color = "black";
    if (formObj.PISSWORD.value=="" || formObj.PISSWORD.value == inv){
	 formObj.PISSWORD.style.color = "red";
	 formObj.PISSWORD.value = inv;
	 errors++;
 } 

    if (formObj.PISSWORDR.value=="" || formObj.PISSWORDR.value == inv){
	 formObj.PISSWORDR.style.color = "red";
	 formObj.PISSWORDR.value = inv;
	 errors++;
  } 
    if (formObj.PISSWORD.value != formObj.PISSWORDR.value){
	 formObj.PISSWORD.style.color = "red";
	 formObj.PISSWORD.value = inv;
	 formObj.PISSWORDR.style.color = "red";
	 formObj.PISSWORDR.value = inv;
	 errors++;
	 bandMessage+='\n\nYou did not type in the same password in both password fields.';
  }   

} 

 
 if (formObj.EMAIL){
errors = errors + changeVal(formObj.EMAIL,true,false);
if(checkEmail(formObj.EMAIL)==false){
  bandMessage+='\n\nYou have not entered a valid email address.';
  errors++;
} else{
   formObj.EMAIL.style.color = "black";
  }  
 }  

if (formObj.article_id){
 errors = errors + changeVal(formObj.title,true,true);
 errors = errors + changeVal(formObj.keywords,false,true);
 errors = errors + changeVal(formObj.article_about,true,true);
 errors = errors + changeVal(formObj.body,true,true);
}

if (formObj.INBOX){
 errors = errors + changeVal(formObj.title,false,true);
 errors = errors + changeVal(formObj.keywords,false,true);

 if(changeVal(formObj.street,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter the street address.';
  }
  if(changeVal(formObj.city,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter the city.';
  }
  if(changeVal(formObj.state,true,false)){
     errors++;
     bandMessage+='\n\nYou did not enter a state/province. If the propert is in a country with no state/province, copy the city name into this field.';
  }
    if(changeVal(formObj.COUNTRY,true,true)){
     errors++;
     bandMessage+='\n\nYou did not select a country from our list. If the property is in a country not listed on our form, please contact us immediately and we will accomodate you.';

  }
   if(changeVal(formObj.body,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter a complete description of this property.';
  }
     if(changeVal(formObj.article_about,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter a brief description of this property.';
  }
}

if (formObj.comment){
  errors = errors + changeVal(formObj.fname,true,true);
  errors = errors + changeVal(formObj.lname,true,true);
  errors = errors + changeVal(formObj.comment,true,true);
   
}
if (formObj.vaddress){
  errors = errors + changeVal(formObj.vaddress,true,true);
  errors = errors + changeVal(formObj.venue,true,true);
  errors = errors + changeVal(formObj.info,true,false);
  errors = errors + changeVal(formObj.state,true,true);
  errors = errors + changeVal(formObj.COUNTRY,true,true);
  errors = errors + changeVal(formObj.title,true,true);
  errors = errors + changeVal(formObj.city,true,true);
}
if (formObj.SHIPPED){
prob = '';

			   if (formObj.PENDING.checked && formObj.SHIPPED.checked) {
			       prob += 'An order cannot be both "Pending" and "Shipped"\n\n';
				   errors++;
			   }
			   
			   if (formObj.DENIED.checked && formObj.SHIPPED.checked) {
			       prob += 'An order cannot be both "Denied" and "Shipped"\n\n';
				   errors++;
			   }
			   
			   if (formObj.DENIED.checked && formObj.PENDING.checked) {
			       prob += 'An order cannot be both "Denied" and "Pending"\n\n';
				   errors++;
			   }
			   
			   if (formObj.RETAIL.checked && formObj.WHOLESALE.checked) {
			       prob += 'An order cannot be both "Retail" and "Wholesale"\n\n';
				   errors++;
			   }
			   
			   if (formObj.RETAIL.checked && formObj.PROMO.checked) {
			       prob += 'An order cannot be both "Retail" and "Promo"\n\n';
				   errors++;
			   }
			   
			   if (formObj.WHOLESALE.checked && formObj.PROMO.checked) {
			       prob += 'An order cannot be both "Wholesale" and "Promo"\n\n';
				   errors++;
			   }
			   
			   if ((! formObj.RETAIL.checked) && (! formObj.WHOLESALE.checked) && (! formObj.PROMO.checked)) {
			       prob += 'An order must be either "Retail", "Wholesale" or "Promo"';
				   errors++;
			   }
			   if(prob !=''){alert(prob);}
			   
			   if(formObj.total.value<=0 && formObj.lock.checked && formObj.PROMO.checked==''){errors++; alert('You cannot set the total value to less than or equal to $0 unless the order is set to a promotion.');}
   
}
if (formObj.letter){
  errors = errors + changeVal(formObj.letter,true,true);
  errors = errors + changeVal(formObj.subject,true,true);
  if(formObj.getmail){
    errors = errors + changeVal(formObj.getmail,true,false);
    if(checkEmail(formObj.getmail)==false){
	 errors++;
	}
  
  }
}
if (formObj.ccinfo){
//Credit Card Payment Info
    if(changeVal(formObj.first,true,true)){
      errors++;
	  bandMessage+='\n\nYou must enter a first name.';
    }
    if(changeVal(formObj.last,true,true)){
      errors++;
	  bandMessage+='\n\nYou must enter a last name.';
    }
	
    if(changeVal(formObj.address,true,true)){
      errors++;
	  bandMessage+='\n\nYou must enter a street address.';
    }	
    if(changeVal(formObj.COUNTRY,true,true)){
      errors++;
	  bandMessage+='\n\nYou must select a country.';
    }
    if(changeVal(formObj.state,true,true)){
      errors++;
	  bandMessage+='\n\nYou must enter a state/province. If you live in a country with no states/provinces, copy your city into this field.';
    }	
    if(changeVal(formObj.city,true,true)){
      errors++;
	  bandMessage+='\n\nYou must enter a city.';
    }	
    if(changeVal(formObj.zip,true,true) && formObj.COUNTRY.value=='United_States'){
      errors++;
	  bandMessage+='\n\nYou must enter a zip code.';
    }	
    if(changeVal(formObj.ccinfo,true,true)){
      errors++;
	  bandMessage+='\n\nYou must enter a credit card number.';
    }
    if(changeVal(formObj.ccsecurity,true,true)){
      errors++;
	  bandMessage+='\n\nYou must enter your credit card security number.';
    }
	
if(changeVal(formObj.total_order,true,true) || ((formObj.total_order.value * 1) <0)){

      errors++;
	  bandMessage+='\n\nYou must enter a total value for this order. Do not include currency symbols.';
    }


}
if (formObj.terms){
  if(! formObj.terms.checked){errors++; bandMessage+='\n\nYou must check that you have read and agree to our terms of service to continue.'; }
   
}

if (formObj.web){formObj.web.value=stripCharacter(formObj.web.value,'http://');}
if (formObj.URL){formObj.URL.value=stripCharacter(formObj.URL.value,'http://');}
// 

   if (errors==0){
      formObj.submit();
  }
  
  if (errors >0){
    alert("There are errors on your form... please verify the information. Fields with red text or the word 'Invalid' must be filled out."+bandMessage);
    return;
  }
}


function deleteConfirm(script,id){
 if((script != '') && (id !='')){
  if (script=='usermod.php'){comment = 'your account? Doing so will remove your bio, guestbook, all articles, events, photos, art and music. You will no longer be listed on the artist directory.';}
  if (script=='articlemod.php'){comment = 'this article? Doing so will permanently remove this article.';}
  if (script=='addvilla.php'){comment = 'this home? Doing so will permanently remove this home.';}
  if (script=='shop.php'){comment = 'all the items from your shopping cart?';}
  return confirm("Do you really want to delete " + comment);
  
 }

}

function changeOldState(formObj,name){
  string1='theState = formObj.'+name+'state.value; formObj.'+name+'oldState.value=theState;';
  eval(string1);
  if(theState=='Ohio'){

      string2 = 'if(document.getElementById("'+name+'countyListBox")){document.getElementById("'+name+'countyListBox").style.display="block";}';
    }
    if(theState!='Ohio'){
      string2 = 'if(document.getElementById("'+name+'countyListBox")){document.getElementById("'+name+'countyListBox").style.display="none";}';
    }
    eval(string2);
  
}


function stateList(formObj,element,name){

string = 'var state = formObj.'+name+'oldState.value;';
eval(string);

theCountryString = 'theCountry = formObj.'+name+'COUNTRY.value;';
eval(theCountryString);
 if (theCountry == 'United_States' || theCountry=='Canada'){
 if (theCountry == 'United_States'){
   eval('var states = \'<select name="'+name+'state" class="join" onchange="changeOldState('+formObj.name+',\\\''+name+'\\\')"><option value="Alabama" >Alabama</option><option value="Alaska" >Alaska</option><option value="Arizona" >Arizona</option><option value="Akansas" >Akansas</option><option value="California" >California</option><option value="Colorado" >Colorado</option><option value="Connecticut" >Connecticut</option><option value="Deleware" >Deleware</option><option value="District_of_Columbia" >District of Columbia</option><option value="Florida">Florida</option><option value="Georgia" >Georgia</option><option value="Hawaii">Hawaii</option><option value="Idaho" >Idaho</option><option value="Illinois">Illinois</option><option value="Indiana" >Indiana</option><option value="Iowa">Iowa</option><option value="Kansas" >Kansas</option><option value="Kentucky">Kentucky</option><option value="Louisiana" >Louisiana</option><option value="Maine">Maine</option><option value="Maryland" >Maryland</option><option value="Massachusetts">Massachusetts</option><option value="Michigan">Michigan</option><option value="Minnesota">Minnesota</option><option value="Missippi">Missippi</option><option value="Missouri">Missouri</option><option value="Montana">Montana</option><option value="Nebraska">Nebraska</option><option value="Nevada">Nevada</option><option value="New_Hampshire">New Hampshire</option><option value="New_Jersey" >New Jersey</option><option value="New_Mexico">New Mexico</option><option value="New_York" >New York</option><option value="North_Carolina">North Carolina</option><option value="North_Dakota" >North Dakota</option><option value="Ohio" selected="selected">Ohio</option><option value="Oklahoma">Oklahoma</option><option value="Oregon" >Oregon</option><option value="Pennsylvania" >Pennsylvania</option><option value="Rhode_Island" >Rhode Island</option><option value="South_Carolina" >South Carolina</option><option value="South_Dakota" >South Dakota</option><option value="Tennessee" >Tennessee</option><option value="Texas" >Texas</option><option value="Utah" >Utah</option><option value="Vermont" >Vermont</option><option value="Virginia" >Virginia</option><option value="Washington" >Washington</option><option value="West_Virginia" >West Virginia</option><option value="Wisconsin" >Wisconsin</option><option value="Wyoming" >Wyoming</option></select>\';')
 }
 if (theCountry == 'Canada'){
   eval('var states = \'<select name="'+name+'state" class="join" onchange="changeOldState('+formObj.name+',\\\''+name+'\\\')"><option value="Alberta">Alberta</option><option value="British_Columbia">British Columbia</option><option value="Manitoba">Manitoba</option><option value="New_Brunswick" >New Brunswick</option><option value="Newfoundland">Newfoundland</option><option value="Northwest_Terriotries">Northwest Terriotries</option><option value="Nova_Scotia" >Nova Scotia</option><option value="Ontario">Ontario</option><option value="Prince_Edward_Islands">Prince Edward Islands</option><option value="Quebec">Quebec</option><option value="Saskatchewan">Saskatchewan</option><option value="Yukon_Territory">Yukon Territory</option></select>\';')
}
   eval('document.getElementById("'+element + '").innerHTML = states;');

   eval('formObj.'+name+'state.value=state;');
   

}
 if (theCountry != 'United_States' && theCountry!='Canada'){
   var province = '<input type="text" name="'+name+'state" value="'+state+'" maxlength="36" class="small"/>';
   eval('document.getElementById("'+element+'").innerHTML = province;');
 }

}



function hideCounty(formObj){
  if(document.getElementById("countyListBox")){
  
    if(formObj.state.value=='Ohio'){
      document.getElementById("countyListBox").style.display="block";
	}
	if(formObj.state.value!='Ohio'){
      document.getElementById("countyListBox").style.display="none";
	}
	
  }
}

function showThumb(articleId,newImg){
 changeString = 'document.getElementById("Pic'+articleId+'").src="'+newImg+'";';
 eval(changeString);
}

function getRadioValue(radioObject){
 var value=null;
 for (var i=0; i<radioObject.length; i++){
  if (radioObject[i].checked){
   value = radioObject[i].value;
   break;
  }
 }
return value;
}

function changeSearchType(formObj){

     switch(formObj.searchtype.value){
	   case 'villas':
	      formObj.action = '/vacation_homes/';
		  break;
	   case 'member':
	      formObj.action = '/directory/';
		  break;
	   case 'articles':
	      formObj.action = '/search.php';
		  break;
	   case 'events':
	      formObj.action = '/events.php';
		  break;
	 }
	 

}

function searchType(formObj){
  if(formObj.search.value != ''){
    changeSearchType(formObj)
    formObj.submit();
  
  } else {alert('Enter Search Terms');}

}

function showFile(id,width,height){
  if(window.picWIndow){picWIndow.close();}
  theWidth = ((width*1)+30);
  if(theWidth > 460){theWidth = 460;}
  theHeight = ((height*1)+30); 
  picWIndow = window.open("/show_image.php?id="+id,'imagewindow','toolbar=no,menubar=no,width='+theWidth+',height='+theHeight+',scrollbars=no,status=no');
;}

function myArts(formObj){
  checkNames(formObj);

}

function textCounter(field, maxlimit) {
 if (field.value.length > maxlimit){
  alert("Sorry... but the maximum input for this field is "+ maxlimit +" characters. You have entered " + field.value.length + " characters.");
  field.focus();
 }

}

function checkUncheckAll(box) {
 var currForm = box.form, c = 0;
 while (currForm[c].type == 'checkbox' && currForm[c].name != 'checkall') {
  currForm[c].checked = box.checked;
  c++;
 }
}


