// Form Validation JS

//

// Purpose: Checks form entries (newsletter, contact us pages etc.)

//

// Author: TheEWord (www.theeword.co.uk)

// Developer: Alan Mackin (alan at theeword.co.uk)





function checkNum(fieldval){

var NumberToTest = fieldval.split(' ').join('');

var IsFound = /^-?\d+$/.test(NumberToTest);

  if((IsFound) && (NumberToTest.length >= 7) && (NumberToTest.length < 12)){

    return false;

  }else{

    return true;

  }

}





function check_linkout_all(limit,id,id2,id3,id4,swid) {



  ida=0;

  fail=0;

  for (ida=0;ida<limit;ida++) {

    j=ida;

    ret=check_linkout(j);

    if (ret==1) {fail=1;}

  }

  if (fail==0) {

  

if (swid) {

      switchPopup = window.open('/php/switch-popup.php?name='+swid,'mywin','width=500,height=500,toolbar=0,resizable=0');

    }    

    

    buyclik2(id,id2,id3,id4);

    outclick(id2,id3,id4);

    //now launch popup

    

        

    





    

    document.linkout.submit();

    }

  else {alert("Please check your details");}





}



function check_linkout(id){



ok=0;

errorcount=0;

var error = new Array (15);

var errormsg= new Array (15);



if (id==1) {tf=0; //name

    if (document.getElementById("fname").value=='') { error[errorcount]=id;tf=1;errorcount++;}

    

    a=document.getElementById("fname").value;

    a=a.toLowerCase();

    sworn=0;

    if (a.indexOf('fuck')>-1) {error[errorcount]=id;tf=1;errorcount++;sworn=1;}

    if (a.indexOf('shit')>-1) {error[errorcount]=id;tf=1;errorcount++;sworn=1;}

    if (a.indexOf('twat')>-1) {error[errorcount]=id;tf=1;errorcount++;sworn=1;}

    if (a.indexOf('bastard')>-1) {error[errorcount]=id;tf=1;errorcount++;sworn=1;}

    if (a.indexOf('cunt')>-1) {error[errorcount]=id;tf=1;errorcount++;sworn=1;}

    if (a.indexOf('piss')>-1) {error[errorcount]=id;tf=1;errorcount++;sworn=1;}

    if (a.indexOf('balls')>-1) {error[errorcount]=id;tf=1;errorcount++;sworn=1;}

    if (tf==0) {ok=id;}



}



if (id==2) { //email

if (document.getElementById("femail").value!='' && checkMail(document.getElementById("femail").value)) {ok=id;} else {

 error[errorcount]=id;errormsg[errorcount]="Please enter your email address";errorcount++;}

}





if (id==3) {tf=0; //telephone

  

  if (checkNum(document.getElementById("ftelephone").value)) {tf=1;error[errorcount]=id;errorcount++;}

  if (document.getElementById("ftelephone").value.substring(0,2)!='07' && document.getElementById("ftelephone").value.substring(0,2)!='01' && document.getElementById("ftelephone").value.substring(0,2)!='02') {tf=1;error[errorcount]=id;errorcount++;}

  if (document.getElementById("ftelephone").value.length<10 && document.getElementById("ftelephone").value.length>14) {tf=1;error[errorcount]=id;errorcount++;}

  

  if (tf==0) {ok=3;}

}



if (ok>0) {document.getElementById("ti"+ok).src="tick.png"; }



doneerror=0;

//now show errors on page

for (i=0;i<errorcount;i++) {

if (error[i]){



if (error[i]>0) {document.getElementById("ti"+error[i]).src="cross.png";

doneerror=1;}



}



}



if (id==1 && sworn==1) {

document.getElementById("lomessage").innerHTML="<div style=\"background-color:#FF0000;color:#FFF;padding:8px;font-weight:bold;\">Hey, don't swear! Enter your real name and you could win a free laptop.</div>";

}



return doneerror;



}





function check_reviews_all(limit) {

  ida=0;

  fail=0;

  for (ida=0;ida<limit;ida++) {

    j=ida;

    ret=check_reviews(j);

    if (ret==1) {fail=1;}

  }

  if (fail==0) { document.review.submit();}

  else {alert("Please check your information");}





}



function check_reviews(id){



ok=0;

errorcount=0;

var error = new Array (15);

var errormsg= new Array (15);



if (id==1) { //name

if (document.getElementById("fname").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==2) { 

if (checkNum(document.getElementById('ftelephone').value)) { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==3) { //email

if (document.getElementById("femail").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your email address";errorcount++;}

else {ok=id;}

}



if (id==4) {

if (document.getElementById("faddress").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your postal code";errorcount++;}

else {ok=id;}

}



if (id==5) {

if (document.getElementById("fvalue").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your postal code";errorcount++;}

else {ok=id;}

}



if (id==6) {

if (document.getElementById("fdescription").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your postal code";errorcount++;}

else {ok=id;}

}







if (ok>0) {document.getElementById("ti"+ok).src="tick.png"; }





doneerror=0;

//now show errors on page

for (i=0;i<errorcount;i++) {

if (error[i]){



if (error[i]>0) {document.getElementById("ti"+error[i]).src="cross.png";

doneerror=1;}



}



}



return doneerror;



}





function check_news_all(limit){

alert('howdy');





  ida=0;

  fail=0;

  for (ida=0;ida<limit;ida++) {

    j=ida;

    ret=check_news(j);

    if (ret==1) {fail=1;}

  }

  if (fail==0) { document.newsletter.submit();} 

  else {alert("Please check your information");}

}











function check_news(id){



ok=0;

errorcount=0;

var error = new Array (15);

var errormsg= new Array (15);



if (id==1) { //name

if (document.getElementById("fname").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==2) { 

if (checkNum(document.getElementById('ftelephone').value)) { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==3) { //address1

if (document.getElementById("femail").value=='' || 

document.getElementById("femail").value!=document.getElementById("femaila").value

) { error[errorcount]=id;errormsg[errorcount]="Please enter the first line of your address";errorcount++;}

else {ok=id;}

}



if (id==4) { 

if (document.getElementById("faddress").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==5) { 

if (document.getElementById("fvalue").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==6) { 

if (document.getElementById("fdescription").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}











if (ok>0) {document.getElementById("ti"+ok).src="tick.png"; }





doneerror=0;

//now show errors on page

for (i=0;i<errorcount;i++) {

if (error[i]){



if (error[i]>0) {document.getElementById("ti"+error[i]).src="cross.png";

doneerror=1;}



}



}



return doneerror;



}





function check_cont_all(limit){

  ida=0;

  fail=0;

  for (ida=0;ida<limit;ida++) {

    j=ida;

    ret=check_cont(j);

    if (ret==1) {fail=1;}

  }

  if (fail==0) { 

    if(document.getElementById('Fservice').value != ''){

      document.contact.submit();

    }else{

     document.getElementById("ti301").src="cross.png";

      alert("Please check your information.");

    }

  } else {

        

    if(document.getElementById('Fservice').value == ''){

       document.getElementById("ti301").src="cross.png";

    }else{

     document.getElementById("ti301").src="tick.png";

    }



  

    alert("Please check your information.");

  }

}











function check_cont(id){



ok=0;

errorcount=0;

var error = new Array (15);

var errormsg= new Array (15);



if (id==1) { //name

if (document.getElementById("fname").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==2) {

if (checkNum(document.getElementById('ftelephone').value)) { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==3) { //address1

if (document.getElementById("femail").value=='' || 

!checkMail(document.getElementById("femail").value)) { error[errorcount]=id;errormsg[errorcount]="Please enter the first line of your address";errorcount++;}

else {ok=id;}

}



if (id==4) {

if (document.getElementById("faddress").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==5) {

if (document.getElementById("fvalue").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}



if (id==6) {

if (document.getElementById("fdescription").value=='') { error[errorcount]=id;errormsg[errorcount]="Please enter your contact name";errorcount++;}

else {ok=id;}

}





if (ok>0) {document.getElementById("ti"+ok).src="tick.png"; }





doneerror=0;

//now show errors on page

for (i=0;i<errorcount;i++) {

if (error[i]){



if (error[i]>0) {document.getElementById("ti"+error[i]).src="cross.png";

doneerror=1;}



}



}



return doneerror;



}



function check_extra(extnum,someid){

  if(document.getElementById(someid).value==''){

  //  document.getElementById("ti"+extnum).src="/images/cross.png";

  }else{

    document.getElementById("ti"+extnum).src="tick.png";

  }

}









function checkMail(value)

{	var x = value;

	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (filter.test(x)) return 1;

	else return 0;}

