//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;
 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){
   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 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.article_id){
//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.article_about,true,true); 
    errors = errors + changeVal(formObj.body,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.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);
}
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 (errors==0){
      formObj.submit();
  }
  
  if (errors > 0){
    alert("There are errors on your form... please verify the information.");
    return;
  }
}


function imagePreview(imageForm,pixadd){
 var theImg = new Image();
 theImg.src = imageForm.value;
 var remark = '';
 var type = 'pic';
 
 if(picForm.img1_type){
   type = picForm.img1_type.value;
 
 }
 
 if(type == 'imageWarn'){
   if(theImg.width > 280){
    remark='Your picture is wider ('+theImg.width+'px) than our size limit . The image will be resized to 280 pixels wide.\r\n\r\n';
   }
   if(theImg.height > 210){
    remark=remark + 'Your picture is high ('+theImg.height+'px). The image will be resized to 210 pixels high.\r\n\r\n';
  } 
  if(theImg.width < 280){
    remark='Your picture is too narrow ('+theImg.width+'px) than our size limit . The image will be resized to 280 pixels wide.\r\n\r\n';
   }
   if(theImg.height < 210){
    remark=remark + 'Your picture is too low ('+theImg.height+'px). The image will be resized to 210 pixels high.\r\n\r\n';
  } 
 }
  if(type == 'banner'){
   if(theImg.width != 400){
    remark='Your banner ('+theImg.width+'px) is not the proper width. Image must be 400 pixels wide.\r\n\r\n';
   }
   if(theImg.height != 51){
    remark=remark + 'Your banner ('+theImg.height+'px) is not the proper height. Image must be 51 pixels high.\r\n\r\n';
  } 
 }
 if(remark != ''){
    alert(remark+" Your image may not display as you intend on the internet.\r\n\r\nLearn more about resizing and compressing at www.shawnolson.net/a/33/ ."); 

 }

}

function showPic(formObj,pixadd){
  var notice;
  notice = '';
  eval('if(formObj.IMG'+pixadd+'.value != ""){document.images.IMG'+pixadd+'.src = formObj.IMG'+pixadd+'.value; imagePreview(formObj.IMG'+pixadd+','+pixadd+');}');

}


function showPicAS(){
 var filename=document.picFormA.IMGAS.value;

if (navigator.appName == "Netscape")
        {
        alert("Previews do not work in Netscape.");
        }
        else
        {
 
        document.images.IMGAS.src = filename;
        document.pix_srcas = filename;
        }
}

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++;
 }
}


var letterArray = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');

function addLinkBox(){
 found = false;
 num = 0;
 while(found==false && num < 26){
 

    string = 'theDiv = document.getElementById("linkForm'+letterArray[num]+'");';
    eval(string);
	letter=letterArray[num];
	if(! theDiv){
	 found = true;
	} else {num++;}
	
	if(num>25){
	 alert('You cannot add more than 26 links at a time.');
	}
  
 
 
 }
 if(found==true){
  document.getElementById("theLinks").innerHTML+=placeLink(letter);
 }
}

function placeLink(letter){
	  form='<div id="linkForm'+letter+'" style="border-style: solid; padding: 5px"><h4>Company Name</h4><input type="text" name="linkName'+letter+'" maxlength="128"/><h4>Company Url</h4><input type="text" name="linkUrl'+letter+'" maxlength="128"/><h4>Link Type</h4><table class="cent" border="1" style="font-size: 10px"><tr><td class="cent">Advertising Agency<br/><input class="smallCheck" type="checkbox" name="adsite'+letter+'" value="64"/></td><td class="cent">Bank<br/><input class="smallCheck" type="checkbox" name="bank'+letter+'" value="1"/></td><td class="cent">Bill<br/><input class="smallCheck" type="checkbox" name="bill'+letter+'" value="32768"/></td><td class="cent">Electric Company<br/><input class="smallCheck" type="checkbox" name="electricity'+letter+'" value="4"/></td><td class="cent">Gas Company<br/><input class="smallCheck" type="checkbox" name="gas'+letter+'" value="32"/></td><td class="cent">Federal Government<br/><input class="smallCheck" type="checkbox" name="federalGovt'+letter+'" value="2048"/></td><td class="cent">Local Governemt<br/><input class="smallCheck" type="checkbox" name="localGovt'+letter+'" value="512"/></td><td class="cent">Media Outlet<br/><input class="smallCheck" type="checkbox" name="media'+letter+'" value="8192"/></td><td class="cent">Mortgage Broker<br/><input class="smallCheck" type="checkbox" name="mortgage'+letter+'" value="256"/></td><td class="cent">Other Link<br/><input class="smallCheck" type="checkbox" name="other'+letter+'" value="16384"/></td></tr><tr><td class="cent">Phone Company<br/><input class="smallCheck" type="checkbox" name="phone'+letter+'" value="8"/></td><td class="cent">Realtor<br/><input class="smallCheck" type="checkbox" name="realtor'+letter+'" value="128"/></td><td class="cent">Property Resource<br/><input class="smallCheck" type="checkbox" name="resource'+letter+'" value="131072"/></td><td class="cent">State Governemnt Agency<br/><input class="smallCheck" type="checkbox" name="stateGovt'+letter+'" value="1024"/></td><td class="cent">Tax<br/><input class="smallCheck" type="checkbox" name="tax'+letter+'" value="65536"/></td><td class="cent">Tourism Resource<br/><input class="smallCheck" type="checkbox" name="tourism'+letter+'" value="4096"/></td><td class="cent">Cable/Satellite<br/><input class="smallCheck" type="checkbox" name="tv'+letter+'" value="16"/></td><td class="cent">Sewer &amp; Water<br/><input class="smallCheck" type="checkbox" name="water'+letter+'" value="2"/></td></tr></table><input type="hidden" name="linkId'+letter+'"/></div>';
   return form;
}
