function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

//Elist Validation

function checkForm()
{
   var cname, cemail;
   with(window.document.elistform)
   {
      cemail   = email;
   }

   if(trim(cemail.value) == '')
   {
      alert('Please enter your email');
      cemail.focus();
      return false;
   }
   else if(!isEmail(trim(cemail.value)))
   {
      alert('Email address is not valid');
      cemail.focus();
      return false;
   }
      else
   {
      cemail.value   = trim(cemail.value);
      return true;
   }
}

//Application Validation

function checkForm1()
{
   var cpname, ccname, cfname, clname, caddress1, caddress2, ccity, cstate, czip, ccountry, cphone, cfax, cemail, cvemail, cowner, cproxy;
   with(window.document.applyForm)
   {
	   cpname = pname;
	   ccname = cname;
	   cfname = fname;
	   clname = lname;
	   caddress1 = add1;
	   caddress2 = add2;
	   ccity = city;
	   cstate = state;
	   czip = zip;
	   ccountry = country;
	   cphone = phone;
	   cfax = fax;
       cemail = email;
	   cvemail = vemail;
	   cowner = owner;
	   cproxy = proxy;
   }

   if(trim(cpname.value) == '')
   {
      alert('Please enter a name for your project.');
      cpname.focus();
      return false;
   }
   else if(trim(cfname.value) == '')
   {
      alert('Please enter your first name.');
      cfname.focus();
      return false;
   }
   else if(trim(clname.value) == '')
   {
      alert('Please enter your last name.');
      clname.focus();
      return false;
   }
   else if(trim(caddress1.value) == '')
   {
      alert('Please enter a valid mailing address.');
      caddress1.focus();
      return false;
   }
   else if(trim(ccity.value) == '')
   {
      alert('Please enter your complete mailing address.');
      ccity.focus();
      return false;
   }
    else if(trim(cstate.value) == '')
      {
      alert('Please enter your complete mailing address.');
      cstate.focus();
      return false;
   }
   else if(trim(czip.value) == '')
   {
      alert('Please enter a valid postal code.');
      czip.focus();
      return false;
   }
   else if(trim(ccountry.value) == '')
   {
      alert('Please enter your complete mailing address.');
      ccountry.focus();
      return false;
   }
   else if(trim(cphone.value) == '')
   {
      alert('Please enter a valid phone number.');
      cphone.focus();
      return false;
   }
   else if(!isEmail(trim(cemail.value)))
   {
      alert('Email address is not valid');
      cemail.focus();
      return false;
   }
      else if(trim(cemail.value.toLowerCase) != trim(cvemail.value.toLowerCase))
   {
      alert('Email addresses do not match.');
      cemail.focus();
      return false;
   }
      else if(validateRadio(cowner)==false)
   {
      alert('Please select Yes or No if you are the Sole Owner/Decision Maker of the project.');
      cowner.focus();
      return false;
   }
      else if(cproxy.checked==false && getCheckedValue(cowner)==2)
   {
      alert('You must have permission to act as proxy for all owners of this project.');
      cproxy.focus();
      return false;
   }
      else
   {
      return true;
   }
}

function checkForm2()
{
   var ccreator, csubtype, cotherexp, cpermission, chear;
   with(window.document.applyForm)
   {
	   ccreator = creator;
	   csubtype = subtype;
	   cotherexp = otherexp;
	   cpermission = permission;
	   chear = hear;
   }

   if(trim(ccreator.value) == '')
   {
      alert('Please enter a name for the creator of the project.');
      ccreator.focus();
      return false;
   }
   else if(csubtype.value=="Other" && trim(cotherexp.value) == '')
   {
      alert('Please describe the type of submission.');
      cotherexp.focus();
      return false;
   }
   else if(cpermission.checked==false)
   {
      alert('You must agree to permit us to show your video in order to proceed with the application.');
      cpermission.focus();
      return false;
   }
   else if(trim(chear.value) == '')
   {
      alert('Please tell us how you found us (i.e. Google, Facebook etc..)');
      chear.focus();
      return false;
   }
         else
   {
      return true;
   }
}

function checkForm3()
{
   var cdisclaim;
   with(window.document.applyForm)
   {
	   cdisclaim = disclaimer;
   }

   if(cdisclaim.checked==false)
   {
      alert('You must agree to the terms and conditions of this competition to continue.');
      cdisclaim.focus();
      return false;
   }
            else
   {
      return true;
   }
}

function checkForm4()
{
   var cpaytype;
   with(window.document.applyForm)
   {
	   cpaytype = paytype;
   }

   if(!validateRadio(cpaytype))
   {
      alert('You must select a form of payment.');
      cpaytype.focus();
      return false;
   }
            else
   {
      return true;
   }
}

function checkForm5()
{
   var csubmittype, curlsubmit;
   with(window.document.applyForm)
   {
	   csubmittype = submittype;
	   curlsubmit = urlsubmit;
   }

   if(!validateRadio(csubmittype))
   {
      alert('You must select a submission method.');
      csubmittype.focus();
      return false;
   }
      else if(getCheckedValue(csubmittype)=="link" && !validateURL(curlsubmit.value))
   {
      alert('You must enter a valid url.  Please use this format: http://www.url.com');
      curlsubmit.focus();
      return false;
   }
            else
   {
      return true;
   }
}

function checkForm6()
{
   var cpname, ccname, cfname, clname, caddress1, ccity, cstate, czip, ccountry, cphone, cemail, cvemail, ccoemail, cpswd, cvpswd, cproject_type, cother, cgenre, cother_genre, creferral, cdisclaim, centry, csubmit_method, cproject_link, cproject_file, clogline, cdescription;
   with(window.document.applyForm)
   {
	   cpname = pname;
	   ccname = cname;
	   cfname = fname;
	   clname = lname;
	   caddress1 = add1;
	   ccity = city;
	   cstate = state;
	   czip = zip;
	   ccountry = country;
	   cphone = phone;
	   cfax = fax;
       cemail = email;
	   cvemail = vemail;
	   ccoemail = coemail;
	   cpswd = pswd;
	   cvpswd = vpswd;
	   cproject_type = project_type;
	   cother = other;
	   cgenre = genre;
	   cother_genre = other_genre;
	   centry = entry;
	   csubmit_method = submit_method;
	   cproject_link = project_link;
	   cproject_file = project_file;
	   clogline = logline;
	   cdescription = description;
	   creferral = referral;
	   cdisclaim = disclaimer;
   }
   if(trim(cpname.value) == '')
   {
      alert('Please enter a name for your project.');
      cpname.focus();
      return false;
   }
   else if(trim(cfname.value) == '')
   {
      alert('Please enter your first name.');
      cfname.focus();
      return false;
   }
   else if(trim(clname.value) == '')
   {
      alert('Please enter your last name.');
      clname.focus();
      return false;
   }
   else if(trim(caddress1.value) == '')
   {
      alert('Please enter a valid mailing address.');
      caddress1.focus();
      return false;
   }
   else if(trim(ccity.value) == '')
   {
      alert('Please enter your complete mailing address.');
      ccity.focus();
      return false;
   }
    else if(trim(cstate.value) == '')
      {
      alert('Please enter your complete mailing address.');
      cstate.focus();
      return false;
   }
   else if(trim(czip.value) == '')
   {
      alert('Please enter a valid postal code.');
      czip.focus();
      return false;
   }
   else if(trim(ccountry.value) == '')
   {
      alert('Please enter your complete mailing address.');
      ccountry.focus();
      return false;
   }
   else if(trim(cphone.value) == '')
   {
      alert('Please enter a valid phone number.');
      cphone.focus();
      return false;
   }
   else if (!isEmail(trim(cemail.value)))
   {
      alert('Email address is not valid');
      cemail.focus();
      return false;
   }
      else if (cemail.value.toLowerCase() != cvemail.value.toLowerCase())
   {
      alert('Email addresses do not match.');
      cemail.focus();
      return false;
   }
	else if (cpswd.value == "") {
		alert('Please enter a password.');
		cpswd.focus();
		return false;
	}
   else if (cpswd.value != cvpswd.value) 
   {
	   alert('Password does not match.');
	   cpswd.focus();
	   return false;
   }
     else if (ccoemail.value!="" && !isEmail(ccoemail.value))
   {
      alert("Cowriter's email address is not valid");
      ccoemail.focus();
      return false;
   }
      else if(cproject_type.value=="Other" && cother.value == '')
   {
      alert('Please describe the type of submission.');
      cother.focus();
      return false;
   }
      else if(cgenre.value=="other" && cother_genre.value == '')
   {
      alert('Please describe the genre of the submission.');
      cother_genre.focus();
      return false;
   }
      else if(creferral.value == '')
   {
      alert('Please tell us how you found us (i.e. Google, Facebook etc..)');
      creferral.focus();
      return false;
   }
         else if(clogline.value == '')
   {
      alert('Please enter a logline.');
      clogline.focus();
      return false;
   }
   else if(cdescription.value == '')
   {
      alert('Please enter a project description.');
      cdescription.focus();
      return false;
   }
   	else  if(!validateRadio(centry))
   {
      alert('You must select a submission length.');
      return false;
   }
     else if(!validateRadio(csubmit_method))
   {
      alert('You must select a submission method.');
      return false;
   }
      else if(getCheckedValue(csubmit_method)=="link" && !validateURL(cproject_link.value))
   {
      alert('You must enter a valid url.  Please use this format: http://www.url.com');
      cproject_link.focus();
      return false;
   }
    else if (cdisclaim.checked==false)
   {
      alert('You must agree to the terms and conditions of this competition to continue.');
      cdisclaim.focus();
      return false;
   }
      else
   {
      return true;
   }
}

 function trim(str)
{
   return str.replace(/^\s*|\s(?=\s)|\s*$/g, "");
}

function isEmail(str)
{
   var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|ame|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|k|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;

return regex.test(str);
}

function validateRadio(btn) {
	    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return true;
    else return false;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function validateURL(url) {
	var v = new RegExp();
	v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
	if (!v.test(url)) {
	return false;
	}else{
	return true;
	}
	}
// Phone Validation

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10; function isInteger(s)
{ var i;
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
 
function stripCharsInBag(s, bag)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}
 
function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
 
function isPhone(field){
var Phone=document.applyForm.field;

if ((Phone.value==null)||(Phone.value=="")){
alert("Please Enter your Phone Number")
Phone.focus()
return false
}
if (checkInternationalPhone(Phone.value)==false){
alert("Please Enter a Valid Phone Number")
Phone.value=""
Phone.focus()
return false
}
return true
}

