// JavaScript Document
function checkchar(txt)
{
var rt = true;
var iChars = "!@#$%^&*()+=-[]\\\';/{}|\":<>?";

for (var i = 0; i < document.getElementById(txt).value.length; i++)
{
if (iChars.indexOf(document.getElementById(txt).value.charAt(i)) != -1)
{
rt = false;
}
}

return rt;
}

function isValidEmail(strEmail)
{
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = document.getElementById(strEmail).value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      return false;
    } 
    return true; 
}
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
function checkUKLandline (LandlineNumber) 
{
 // Convert into a string and check that we were provided with something
 var Phnum = LandlineNumber + " ";
 if (Phnum.length == 1)  
 {
    PhnumberErrorNo = 1;
    return false
 }
 Phnum.length = Phnum.length - 1;
 
 // Don't allow country codes to be included (assumes a leading "+")
 //var exp = /^(\+)[\s]*(.*)$/;
// if (exp.test(Phnum) == true) 
// {
//    PhnumberErrorNo = 2;
//    return false;
// }
// 
// // Remove spaces from the telephone number to help validation
// while (Phnum.indexOf(" ")!= -1)  
// {
//   Phnum = Phnum.slice (0,Phnum.indexOf(" ")) + Phnum.slice (Phnum.indexOf(" ")+1)
// }
// 
// // Remove hyphens from the telephone number to help validation
// while (Phnum.indexOf("-")!= -1)  
// {
//   Phnum = Phnum.slice (0,Phnum.indexOf("-")) + Phnum.slice (Phnum.indexOf("-")+1)
// }  
 
 // Now check that all the characters are digits
 exp = /^[0-9]{10,11}$/
 if (exp.test(Phnum) != true) 
 {
    PhnumberErrorNo = 2;
    return false;
 }
 
 // Now check that the first digit is 0
 exp = /^0[0-9]{9,10}$/
 if (exp.test(Phnum) != true) 
 {
    PhnumberErrorNo = 3;
    return false;
 }
 
 // Finally check that the telephone number is appropriate.
 exp = /^(01|02)[0-9]+$/;
 if (exp.test(Phnum) != true) 
 {
    PhnumberErrorNo = 4;
    return false;
 }
 
 // Telephone number seems to be valid - return the stripped telehone number  
 return Phnum;
}
var PhnumberErrorNo = 0;
var PhnumberErrors = new Array ();
PhnumberErrors[0] = "Dude, enter a valid UK Telephone Number";
PhnumberErrors[1] = "What's your Telephone number?";
//PhnumberErrors[2] = "Don’t enter COUNTRY CODE in your telephone number!";
PhnumberErrors[2] = "Hmm…you know a valid UK Landline number must be in digits.";
PhnumberErrors[3] = "Hey eagle eye! A valid UK Landline number begins with 0.";
PhnumberErrors[4] = "Mind the Gap! Telephone number is invalid or inappropriate.";


function ValidateForm(){
	var dt=document.getElementById('dob')
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

	function disp_alert()
	{
		if(document.getElementById('title').value=="")
		{
			alert("Please Select Your title")
			document.getElementById('title').focus();
			return false;
		}
		if(document.getElementById('fname').value=="")
		{
			alert("Please Enter Your First Name")
			document.getElementById('fname').focus();
			return false;
		}
		else if (!checkchar('fname'))
		{
			alert("Invalid FirstName Please re-enter.");
			document.getElementById('fname').focus();
			return (false)
		}
		//if(document.getElementById('mname').value=="")
//		{
//			alert("Please Enter Your Mname Name")
//			document.getElementById('mname').focus();
//			return false;
//		}
		else if (!checkchar('mname'))
		{
			alert("Invalid Mname Please re-enter.");
			document.getElementById('mname').focus();
			return (false)
		}
		if(document.getElementById('lname').value=="")
		{
			alert("Please Enter Your Last Name")
			document.getElementById('lname').focus();
			return false;
		}
		else if (!checkchar('lname'))
		{
			alert("Invalid LastName Please re-enter.");
			document.getElementById('lname').focus();
			return (false)
		}
		if (document.getElementById('add1').value=="")
		{
			alert("Please Enter Your Address")
			document.getElementById('add1').focus();
			return false;
		}
		else if(!checkchar('add1'))
		{
			alert("Invalid Address Please re-enter.");
			document.getElementById('add1').focus();
			return false;
		}
		
//		else if(!checkchar('add2'))
//		{
//			alert("Invalid Address2 Please re-enter.");
//			document.getElementById('add2').focus();
//			return false;
//		}
		if (document.getElementById('city').value=="")
		{
			alert("Please Enter Your City")
			document.getElementById('city').focus();
			return false;
		}
		else if(!checkchar('city'))
		{
			alert("Invalid City Please re-enter.");
			document.getElementById('city').focus();
			return false;
		}
		if (document.getElementById('postcode').value=="")
		{
			alert("Please Enter Your postcode")
			document.getElementById('postcode').focus();
			return false;
		}
		//if(document.getElementById('postcode').value!="")
//		{
//			var str_value=document.getElementById('postcode').value;
//			var str_len=document.getElementById('postcode').value;
//			var str_comp="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
//			for (var i=0;i<str_len;i++)
//			{
//				var a=str_value.charAt(i);
//				if(str_comp.indexOf(a)!=-1)
//				{
//					alert("Please Enter a vaild PostCode");
//					document.getElementById('postcode').focus();
//					return false;
//					break;
//				}
//			}
//		}
		//if((document.getElementById('postcode').value!="")&&(document.getElementById('postcode').value.length<=9))
//		{
//			alert("Please Enter a vaild PostCode");
//			document.getElementById('postcode').focus();
//			return false;
//		}
//		if((document.getElementById('postcode').value.length>=10)&&(document.getElementById('postcode').value.charAt(0)!=0))
//		{
//			alert("Please Enter a vaild Post Code");
//			document.getElementById('postcode').focus();
//			return false;
//		}
	
		if(document.getElementById('country').value=="")
		{
			alert("Please Enter Your Country Name")
			document.getElementById('country').focus();
			return false;
		}
		else if (!checkchar('country'))
		{
			alert("Invalid Country Name Please re-enter.");
			document.getElementById('country').focus();
			return (false)
		}
		
		if(document.getElementById('affType').value=="")
		{
			alert("Please Select Your Affiliate Type")
			document.getElementById('affType').focus();
			return false;
		}
		
		if(document.getElementById('email').value=="")
			{
		alert("Please  enter your email");
		document.getElementById('email').focus();
		return false;
			}
else if(!isValidEmail('email'))
	    {
	    alert("Please enter valid Email");
		document.getElementById('email').focus();
		return (false)
	    }   
		//if(document.getElementById('ositename').value=="")
//		{
//			alert("Please Enter ExistingWebSite")
//			document.getElementById('ositename').focus();
//			return false;
//		}
//		else if (!checkchar('ositename'))
//		{
//			alert("Invalid Existing WebSite Please re-enter.");
//			document.getElementById('ositename').focus();
//			return (false)
//		}
		if(document.getElementById('dob').value=="")
		{
			alert("Please Enter DOB")
			document.getElementById('dob').focus();
			return false;
		}
		else if (!ValidateForm('dob'))
		{
			//alert("Invalid DOB Please re-enter.");
			document.getElementById('dob').focus();
			return (false)
		}
		if (document.getElementById('telno1').value=="")
		
		{
			alert("Please Enter a valid UkLandline")
			document.getElementById('telno1').focus();
			return false;
		}
				
		if(document.getElementById('refferedfrom').value=="")
		{
			alert("Please Select Reffered From")
			document.getElementById('refferedfrom').focus();
			return false;			
		}		
		
		if(!document.getElementById('Chk').checked)
		{
			alert("Please confirm that you have read the Terms and Conditions by clicking the \‘Checkbox\’.");
			return false;
		}
		//else if(!checkUKLandline(document.getElementById('telno').value))
//		{
//			alert(PhnumberErrors[PhnumberErrorNo]);
//			document.getElementById('telno').focus();
//			return false;
//		}
		if(document.getElementById('FeedBack').value=="")
		{
			alert("Please Enter FeedBack")
			document.getElementById('FeedBack').focus();
			return false;
		}
			else if (!checkchar('FeedBack'))
		{
			alert("Invalid FeedBack Please re-enter.");
			document.getElementById('FeedBack').focus();
			return  false;
		}		
		return true;
	}
	
function displayOther(val) 
{
  if (val == "Others")  
 	{
    	document.getElementById('others').style.display='';
 	}
 else
 	{
	 document.getElementById('others').style.display='none';
 	}
}

function CheckServerName(val) 
{
  if (val == "Yes")  
 	{
    	document.getElementById('CheckServer').style.display='';		
 	}
 else
 	{
	 document.getElementById('CheckServer').style.display='none';	 
 	}
}

function CheckDomain(){
	<!--document.form1.action = "http://order.1and1.co.uk/xml/order/domaincheck";-->
	document.form1.action = "http://clkde.tradedoubler.com/click?p=19622&a=1274264&g=17622168&url=http://oneandone.co.uk/xml/order/domaincheck";
	document.form1.target = "_blank";
	document.form1.submit();
	
}

//function check(){
////	alert("hi");
//    document.getElementById("checkbox").checked = false;
//	//document.getElementById("checkbox").disabled = true;
//}
function check()
{	 

	if(document.getElementById('ositename').value =="")
	{
    document.getElementById("checkbox").checked = false;
	
	}
	else 
	{
	document.getElementById("checkbox").checked = true;	
	}

	
}