//Shawn Olson Artistic Network Member Join Verification Script
//Copyright 2003 by Shawn Olson
//All Rights Reserved.
// http://www.shawnolson.net 

 var inv= "Invalid";

	function stripCharacter(words,character) {
	//documentation for this script at http://www.shawnolson.net/a/499/
	  var spaces = words.length;
	  for(var x = 1; x<spaces; ++x){
	   words = words.replace(character, "");   
	 }
	 return words;
    }


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++){
 //var matchString = new Array(word.match(restrictWord[i]));
  //if (matchString.length>0){
  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 verfiyEmail(formObj){
  mailError = 0;
  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;	

  } 
  
  if (! email_val.match("@")) {
    email_pass = false;	

  }  
    if (! email_val.match(".")) {
    email_pass = false;	

  }  
  if (formObj.value=="" || formObj.value == inv){
	 formObj.value = inv;
	 email_pass = false;	
  } 
  if (email_pass == false){
     alert("You have not entered a valid email address.");
     formObj.style.color = "red";
     mailError++;
  }
 
   if (mailError == 0){
   formObj.style.color = "black";
  }  

  return mailError;

}

function changeVal(formObj,need,bad){
 var inv;
 var FnameTest;
 var errors;
 errors = 0;
 if (formObj){
  FnameTest = true;
 inv = "Invalid";
 if(need==true){
  if (formObj.value=='' || formObj.value == inv){ 
   FnameTest = false;
   
   var formType = new String(formObj.type);
		  if(formType.match('select')){
		    formObj.value = '';
		  
		  }
   if(! formType.match('select')){
		    formObj.value = inv;
		  
		  }
  }
 }  
  
 if(bad==true){
   if(formObj.value){
   badword = badWords(formObj.value);}
   else {badword=false;}
  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 passtest;
 var failures;
 var errors;
 var FnameTest = true;
 errors = 0;
 failures = "";
 passtest = true;

if (formObj.FNAME){
//Step 1 stuff 
//NAME
  errors = errors + changeVal(formObj.FNAME,true,true);
  errors = errors + changeVal(formObj.LNAME,true,true);
  errors = errors + changeVal(formObj.ALIAS,true,true);
  errors = errors + changeVal(formObj.ZIP,true,true);
  errors = errors + changeVal(formObj.ADDR,true,false);
  errors = errors + changeVal(formObj.CITY,true,true);
  errors = errors + changeVal(formObj.STATE,true,true);
  errors = errors + changeVal(formObj.COUNTRY,true,true);  
}

FnameTest = true;  
   
 if (formObj.PISSWORD){
 
    if (formObj.PISSWORD.value=="" || formObj.PISSWORD.value == inv){
	 formObj.PISSWORD.style.color = "red";
	 formObj.PISSWORD.value = inv;
	 failures = failures + "Password, ";
	 errors++;
     passtest = false;
 } 
  
    if (formObj.PISSWORDR.value=="" || formObj.PISSWORDR.value == inv){
	 formObj.PISSWORDR.style.color = "red";
	 formObj.PISSWORDR.value = inv;
	 failures = failures + "Password Retype, ";
	 errors++;
     passtest = false;
     FnameTest = false;
  } 
  
    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;
	 failures = failures + "Passwords not same, ";
	 errors++;
     passtest = false;
	 FnameTest = false;
	 alert("You did not type in the same password in both password fields.");
  }   

   if (FnameTest == true){
   formObj.PISSWORD.style.color = "black";
   formObj.PISSWORDR.style.color = "black";
  }
} 
  FnameTest = true;
//
if (formObj.body){
//Step 1 stuff 
//Title
    errors = errors + changeVal(formObj.keywords,false,true);
    errors = errors + changeVal(formObj.article_about,true,true); 
    errors = errors + changeVal(formObj.body,true,true);
	errors = errors + changeVal(formObj.title,true,true);
}

if (formObj.title && formObj.sub){
//Step 1 stuff 
//Title

    errors = errors + changeVal(formObj.city,true,true);
    errors = errors + changeVal(formObj.street,true,true); 
    errors = errors + changeVal(formObj.zip,true,true);
	errors = errors + changeVal(formObj.sub,true,true);
}

if (formObj.ccinfo){
//Credit Card Payment Info

    errors = errors + changeVal(formObj.first,true,true);
	errors = errors + changeVal(formObj.last,true,true);
    errors = errors + changeVal(formObj.ccinfo,true,true);
	errors = errors + changeVal(formObj.state,true,true);
    errors = errors + changeVal(formObj.city,true,true);
    errors = errors + changeVal(formObj.address,true,true); 
    errors = errors + changeVal(formObj.zip,true,true);
	
	if(formObj.cctype.value == 'Switch' ){errors = errors + changeVal(formObj.switch_extra,true,true);}
	
	if(formObj.cctype.value != 'Switch' ){errors = errors + changeVal(formObj.ccsecurity,true,true);}
	if(formObj.total_order){errors = errors + changeVal(formObj.total_order,true,true);}
	if(formObj.Agree_Terms && !formObj.ignoreTerms){
	if ((! formObj.Agree_Terms.checked) && (! formObj.order_status)){errors = errors + 1; alert('You did not agree to the Site Terms.');}
}
	if(formObj.terms && !formObj.ignoreTerms){
	if ((! formObj.terms.checked) && (! formObj.order_status)){errors = errors + 1; alert('You did not agree to the Site Terms.');}
}
	if (formObj.Front_Page_Feature){
	if ((! formObj.Front_Page_Feature.checked) && (! formObj.Listing_Page_Feature.checked) && (! formObj.purchase.checked) ){ errors = errors +1; alert('You did not select a service option (annual listing, feature, etc).');}}

}

 if (formObj.email){
   errors = errors + verfiyEmail(formObj.email);
 }
 if (formObj.EMAIL){
   errors = errors + verfiyEmail(formObj.EMAIL);
 } 
 if (formObj.arrival_year){
    errors = errors + changeVal(formObj.fullname,true,true);
	errors = errors + changeVal(formObj.arrival_year,true,true);
	errors = errors + changeVal(formObj.arrival_date,true,true);
	errors = errors + changeVal(formObj.arrival_month,true,true);
	errors = errors + changeVal(formObj.departure_year,true,true);
	errors = errors + changeVal(formObj.departure_date,true,true);
	errors = errors + changeVal(formObj.departure_month,true,true);
	errors = errors + changeVal(formObj.currency,true,false);
	if(formObj.topic){
	   errors = errors + changeVal(formObj.topic,true,true);
	   if(formObj.type){
	     if(formObj.topic.value=='1' && formObj.type.value=='2'){ 
	       errors = errors+1;
	       alert('Sorry, but unfortunately there are no 2 bedroom villas in the Orlando-Kissimmee area.');
         }
	   }
	 }
	if(formObj.strictRoom){
	   errors = errors + changeVal(formObj.strictRoom,true,true);
	}
}
if (formObj.web){formObj.web.value=stripCharacter(formObj.web.value,'http://');}
if (formObj.URL){formObj.URL.value=stripCharacter(formObj.URL.value,'http://');}
if (formObj.calendar){formObj.calendar.value=stripCharacter(formObj.calendar.value,'http://');}
if (formObj.url){formObj.url.value=stripCharacter(formObj.url.value,'http://');}
// 

if(formObj.required){
  formArray= new Array();
  theFields  = formObj.required.value;
  formArray = theFields.split(',');
  for(x=0;x<formArray.length;x++){
     
	 string = 'errors = errors + changeVal(formObj.'+formArray[x]+',true,false);';
     eval(string);
  
  }
}

   if (errors==0){

         formObj.submit();
  }
  
  if (errors > 0){
    alert("There are errors on your form... please verify the information. Fields in Red and/or filled with 'Invalid' must be completed.");
    return;
  }
}


function deleteConfirm(script,id){
 if((script != '') && (id !='')){
  if (script=='usermod.php'){comment = 'your account? Doing so will remove your bio, guestbook, all articles and all photos.';}
  if (script=='articlemod.php'){comment = 'this article? Doing so will permanently remove this article.';}
  return confirm("Do you really want to delete " + comment);
  
 }

}

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++;
 }
}


function roomCheck(formObj){

   var estimation;
   var kids = formObj.children.value * 1;
   var adults = formObj.adults.value * 1;
   var total = kids + adults;
   
   estimation = Math.ceil((total)/2);
   
   rooms = formObj.type.value * 1;
   
   if (rooms != estimation){
      var message = 'You have selected a home with '+rooms+' bedrooms; however, you have also said your vacation will have '+total+' people. We wanted to let you know that the estimated number of rooms for this amount of people is '+estimation+' rooms.\n\r\n\rThe general rule is two (2) people per room.\n\r\n\rIs this still the number of rooms you want to submit?';
      return confirm(message);
   } else {return true;}


}

function showFile(id,width,height){
  if(window.picWIndow){picWIndow.close();}
  width = (width *1)+30;
  height = (height *1)+60;
  if(width > 440){
    width = 440;
  }
  picWIndow = window.open("/show_image.php?id="+id,'imagewindow','toolbar=no,menubar=no,width='+width+',height='+height*1+',scrollbars=yes,status=yes,resizable=yes');
;
if(! window.picWIndow){
  alert('Your browser of security settings are set to block pop-ups; this is stopping the browser from showing you the image.');
}

}