// JavaScript Document

<!--
	///  Email validation
	function checkEMail(strng) {
		var emailFilter=/^.+@.+\..{2,3}$/;
		var error = "";
		if (!(emailFilter.test(strng))) { 
			error = "Email\n";
		}
		return error;	   
	}
	
	///  Phone Number Validation (Inter National Phone Number Too can Validate)
	function checkPhone(strng) {
		var Phone=strng;
		var error = "";	

		if ((Phone==null)||(Phone=="")){
			error = "Phone\n";
		}
		else if (checkInternationalPhone(Phone)==false){
			error = "Phone\n";
		}
		return error

	}


	function checkInternationalPhone(strPhone) {
		var phoneNumberDelimiters = "()- ext.";
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
		var minDigitsInIPhoneNumber = 10;
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}

	
	function stripCharsInBag(s, bag) {
		var i;
		var returnString = "";
	    for (i = 0; i < s.length; i++) {   
	        var c = s.charAt(i);
	        if (bag.indexOf(c) == -1) returnString += c;
	    }
	    return returnString;
	}
	
	
	function isInteger(s) {
		var i;
	    for (i = 0; i < s.length; i++) {   
	        var c = s.charAt(i);
	        if (((c < "0") || (c > "9"))) return false;
	    }
	    return true;
	}
	
	
	/// First Name Validation	
	function checkFName (strng) {
		var error = "";
		if (strng == "") {
			error = "First Name\n";		
		} else if(!strng.match(/[A-Za-z]/)) {
			error = "First Name\n"; 
		}
		return error;
	}

	/// Last Name Validation 	
	function checkLName (strng) { 
		var error = "";
		if (strng == "") {
			error = "Last Name\n";		
		} else if(!strng.match(/[A-Za-z]/)) {
			error = "Last Name\n"; 
		}
		return error;
	}
	
	/// Company Validation
	function checkcomp (strng) { 
		var error = "";
		if (strng == "") {
			error = "Company\n";		
		} else if(!strng.match(/[A-Za-z]/)) {
			error = "Company\n"; 
		}
		return error;
	}
	
	/// State Validation
	function checkState (strng) {
		var error = "";
		if (strng == "") {
			error = "State";		
		} else if(!strng.match(/[A-Za-z]/)) {
			error = "State\n"; 
		}
		return error;
	}
	
	function checkplayeroption () {
		
		var found_it

		for (var i=0; i<document.form.Player1.length; i++)  {
		if (document.form.Player1[i].checked)  {

		found_it = document.form.Player1[i].value

		}
		} 
		if (found_it == ""){
			error = "Please choose one option\n";
			}else{
				
			error =  found_it;
			}
		
	return error;
		
	}
	
	
	function inquiryFormValidation_step1(obj) {
			why ="";		
			why += checkFName (obj.first_name.value);
			why += checkLName (obj.last_name.value);
			why += checkcomp (obj.company.value);
			why += checkEMail (obj.email.value);
			why += checkPhone (obj.phone.value);
			why += checkState (obj.state.value);
			
			if (why != "") {
				var errorText = "Please check to make sure your entries for the following fields are valid: \n\n";
				errorText += why;
				alert(errorText);
				return false;
			}
			setRec('inquiry_form1',0,'page1')
			document.forms["inquiry_form1"].submit()
	}
	
	function inquiryFormValidation_step2(obj,his) {
			why ="";		
			why += isValidURL (obj.URL.value)
			why += checkContent (document.getElementById('00N50000001Yh6T').value);
			why += checkVideoStream (document.getElementById('00N50000001Yh4g').value);
			why += checkMonUni (document.getElementById('00N50000001Ye6M').value); 
			why += checkCategory (document.getElementById('industry').value); 	
			why += checkTrafic (document.getElementById('00N50000001pHpn').value);
			if (why != "") {
				var errorText = "Please check to make sure your entries for the following fields are valid: \n\n";
				errorText += why;
				alert(errorText);
				return false;
			}
			setRec('inquiry_form2',0,'page2')
			document.forms["inquiry_form2"].submit()
	}

	function valButton(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 btn[cnt].value;
    else return null;
	}
	
	function inquiryFormValidation_step3(obj,his) {
		var btn = valButton(document.getElementsByName('group1'));
		if (btn == null){ 
			alert('Please select the player option')
		} else { 
			setRec('inquiry_form3',0,'page3')
			document.forms["inquiry_form3"].submit();
		}
	}
	
	function inquiryFormValidation_step4(obj,his) {
		why ="";		
		why += verify_image (document.getElementById('verify_text').value,document.getElementById('hidden_verify').value);
		if (why != "") {
			var errorText = "Please check to make sure your entries for the following fields are valid: \n\n";
			errorText += why;
			alert(errorText);
			return false;
		}	
		setRec('inquiry_form4',0,'page4');
		document.forms["inquiry_form4"].submit()		
	}
	
	/// Inquery Form Validation 
	function inquiryFormValidation(obj) {
	
		why ="";		
			why += checkFName (obj.first_name.value);
			why += checkLName (obj.last_name.value);  
			why += checkcomp (obj.company.value);
			why += isValidURL (obj.URL.value)
			why += checkEMail (obj.email.value);

			why += checkEMailDomain (obj.email.value);
			
			why += checkPhone (obj.phone.value);
			why += checkState (obj.state.value);
			why += checkCategory (document.getElementById('industry').value); 			
			why += checkVideoStream (document.getElementById('00N50000001Yh4g').value);
			why += checkMonUni (document.getElementById('00N50000001Ye6M').value); 
			why += checkContent (document.getElementById('00N50000001Yh6T').value);
			why += checkTrafic (document.getElementById('00N50000001pHpn').value);
			why += checkVideoContent (document.getElementById('00N50000001pHpv').value);
			why += checkAccess (document.getElementById('00N50000001pHps').value);			
			why += verify_image (document.getElementById('verify_text').value,document.getElementById('hidden_verify').value);
			
			if (why != "") {
				var errorText = "Please check to make sure your entries for the following fields are valid: \n\n";
				    errorText += why;

		   alert(errorText);
		   return false;
		}			
		return true;
	}
	
	
	function checkEMailDomain(emailAddress) {
		var error = "";
		var blockedEmailDomains = new Array("gmail", "hotmail", "yahoo", "aol");
		var emailDomain = emailAddress.substr(emailAddress.indexOf('@')).toLowerCase();
		var x=0;
		var fail=0;
		do {
			if (emailDomain.indexOf(blockedEmailDomains[x]) > 0) {
				fail=1;
			}
			x++;
		} while (x<blockedEmailDomains.length && fail==0);
		if(fail == 1) {
			error = "Please re-submit using your company's email domain.";
		}
	     return error;
	}
	
	
	function checkCategory (strng) {
		var error = "";
		if (strng == "") {
			error = "Primary Content Category.\n";		
		} 
		return error;
	}
	function verify_image (strng1,strng2) {
		var error = "";
		if (strng1.toLowerCase() != ""){
			if (strng1.toLowerCase() != strng2.toLowerCase()) {
			error = "Invalid Image Verification Code.\n";		
			} 
		}else {
			error = "Please enter the Image verification Code\n"
			}
		return error;
	}	
	function checkVideoStream (strng) {
		var error = "";
		if (strng == "") {
			error = "Estimated Monthly Streams.\n";		
		} 
		return error;
	}
	
	function checkMonUni (strng) {
		var error = "";
		if (strng == "") {
			error = "Estimated Monthly Unique Visitors.\n";		
		} 
		return error;
	}
	
	function checkContent (strng) {
		var error = "";
		if (strng == "") {
			error = "Video Content Type.\n";		
		} 
		return error;
	}
	
	function checkTrafic (strng) {
		var error = "";
		if (strng == "") {
			error = "Estimated Monthly US Audience (% of total traffic).\n";		 
		} 
		return error;
	}
	
	function checkVideoContent (strng) {
		var error = "";
		if (strng == "") {
			error = "Select Video Content.\n";		
		} 
		return error;
	}
	
	function checkAccess (strng) {
		var error = "";
		if (strng == "") {
			error = "Select Video Access.\n";		
		} 
		return error;
	}
	


function isValidURL(strng) {
		//alert("inside url check")
		var error = "";		
		var urlregex1 = /^([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$/;
		//var urlregex1 = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.)+[a-zA-Z0-9\-]\.+.[a-zA-Z\.]{2,5}$");  !urlregex1.test(strng)
		var urlregex2 = new RegExp("^(http:\/\/|https:\/\/|ftp:\/\/)+[a-zA-Z0-9\-]\.+.{2,5}[a-zA-Z\.]{3,5}$");
		if(strng =="") {
			error = "WebSite Address \n";
		} else if(!(strng.toLowerCase()).match(/^(http:\/\/|https:\/\/|ftp:\/\/)+([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,3}$/)) {	
			if(!(strng.toLowerCase()).match(/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.)+([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,3}$/)) {
				if(!(strng.toLowerCase()).match(/^([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,3}$/)) {
					error = "Enter proper Web Site Address \n"; 
				}
			}
		}
		return error;	
	}
	


/*function isValidURL(strng){
	var error = "";	
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{3,3})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;

	if(strng =="") {
		error = "WebSite Address \n";
	}else{
		if(RegExp.test(strng)){
      	 	 return error;
   		 }else{
        	error = "Enter proper Web Site Address \n"; 
			return error;
   		 }
	}
	return error;
} 

function isValidURL(strng) {
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(strng))
     {
         window.alert("URL OK.");
         return true;
     }
     else
     {
         window.alert("URL invalid. Try again.");
         return false; 
     }
}
*/	

