
/* JavaScript Validations in Link Module */

/*  Submitted by-  "Mohit Saxena"     */ 

// 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 FootballFansValidation()
{	
	var flag=true;
	st="Please provide the value for ::";
	if(document.getElementById('UcFansRegistrationForm1_txtFirstName').value=="")
	{
	st=st + "\n - First Name";
	flag=false;
	}
	if(document.getElementById('UcFansRegistrationForm1_txtLastName').value=="")
	{
	st=st + "\n - Last Name";
	flag=false;
	}
	if(document.getElementById('UcFansRegistrationForm1_txtCity').value=="")
	{
	st=st + "\n - City";
	flag=false;
	}
	if(document.getElementById('UcFansRegistrationForm1_ddlCountry').selectedIndex=="0")
	{
	st=st + "\n - Country.";
	flag=false;
	}
	if(document.getElementById('UcFansRegistrationForm1_txtPinCode').value=="")
	{
	st=st + "\n - Pin Code";
	flag=false;
	}
	if(document.getElementById('UcFansRegistrationForm1_ChkBoxTermConditions').checked==false)
	{
	alert("Please accept terms/conditions");
	return false;
	}
	if (flag==false)
	{
		alert(st);
		return false;
	}
	else
	{ 
		return true;
	}
}
function FansCommentsValidation()
{	
	var flag=true;
	st="Please provide the value for ::";
	if(document.getElementById('UcFansComments1_txtName').value=="")
	{
	st=st + "\n - Your Name";
	flag=false;
	}
	if(document.getElementById('UcFansComments1_txtEMail').value=="")
	{
	st=st + "\n - E-Mail Address";
	flag=false;
	}
	if(document.getElementById('UcFansComments1_txtComments').value=="")
	{
	st=st + "\n - Your Comments";
	flag=false;
	}
	if (flag==false)
	{
		alert(st);
		return false;
	}
	else
	{ 
		return true;
	}
}
function ValidateDate()
{

	if(document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').value!="" && document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').value!=null)
	{
		dateStr=document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').value;
		// Checks for the following valid date formats:
		// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
		// Also separates date into month, day, and year variables
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
		// To require a 4 digit year entry, use this line instead:
		// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null)
		{
			alert("Date is not in a valid format.")
			document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').value="";
		    document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').focus();
			return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		if (month < 1 || month > 12)
		{
			// check month range
			alert("Month must be between 1 and 12.");
			document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').value="";
		    document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').focus();
			return false;
		}
		if (day < 1 || day > 31)
		{
			alert("Day must be between 1 and 31.");
			document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').value="";
		    document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').focus();
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31)
		{
			alert("Month "+month+" doesn't have 31 days!")
			document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').value="";
		    document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').focus();
			return false
		}
		if (month == 2) 
		{
			// check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) 
			{
				alert("February " + year + " doesn't have " + day + " days!");
				document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').value="";
		        document.getElementById('UcFansRegistrationForm1_txtDateOfBirth').focus();
				return false;
			}	
		}
	}
}

<!-- 
function checkDecimal(str) {
if (!str) return 0;
var ok = "";
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i+1);
if ((ch < "0" || "9" < ch) && ch != '.') {
alert("Only numeric input is allowed!");
document.getElementById('UcFansRegistrationForm1_txtPinCode').value="";
document.getElementById('UcFansRegistrationForm1_txtPinCode').focus();
return parseFloat(ok);
}
else ok += ch;
}
return str;
}

function IsNumeric() {
num = (checkDecimal(document.getElementById('UcFansRegistrationForm1_txtPinCode').value)); // validates input
if (num) {
form.result.value = parseInt(num);
   num -= parseInt(num); num *= 60;
   }
}
function EMailValidation()
{
	if(document.getElementById('UcFansRegistrationForm1_txtEMail').value!="")
	{
    	var str=document.getElementById('UcFansRegistrationForm1_txtEMail').value;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansRegistrationForm1_txtEMail').value="";
		   document.getElementById('UcFansRegistrationForm1_txtEMail').focus();
		   return false;
		}
		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansRegistrationForm1_txtEMail').value="";
		   document.getElementById('UcFansRegistrationForm1_txtEMail').focus();
		   return false;
		}
		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansRegistrationForm1_txtEMail').value="";
		   document.getElementById('UcFansRegistrationForm1_txtEMail').focus();
		   return false;
		}
		else if (str.indexOf(at,(lat+1))!=-1)
		 {
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansRegistrationForm1_txtEMail').value="";
		   document.getElementById('UcFansRegistrationForm1_txtEMail').focus();
		   return false;
		 }
		else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansRegistrationForm1_txtEMail').value="";
		   document.getElementById('UcFansRegistrationForm1_txtEMail').focus();
		   return false;
		 }
		else if (str.indexOf(dot,(lat+2))==-1)
		 {
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansRegistrationForm1_txtEMail').value="";
		   document.getElementById('UcFansRegistrationForm1_txtEMail').focus();
		   return false;
		 }
		else if (str.indexOf(" ")!=-1)
		 {
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansRegistrationForm1_txtEMail').value="";
		   document.getElementById('UcFansRegistrationForm1_txtEMail').focus();
		   return false;
		 }
		else
		{
			return true;
		}
	}
}
function EMailValidation1()
{
	if(document.getElementById('UcFansComments1_txtEMail').value!="")
	{
    	var str=document.getElementById('UcFansComments1_txtEMail').value;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansComments1_txtEMail').value="";
		   document.getElementById('UcFansComments1_txtEMail').focus();
		   return false;
		}
		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansComments1_txtEMail').value="";
		   document.getElementById('UcFansComments1_txtEMail').focus();
		   return false;
		}
		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansComments1_txtEMail').value="";
		   document.getElementById('UcFansComments1_txtEMail').focus();
		   return false;
		}
		else if (str.indexOf(at,(lat+1))!=-1)
		 {
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansComments1_txtEMail').value="";
		   document.getElementById('UcFansComments1_txtEMail').focus();
		   return false;
		 }
		else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		   alert("Invalid E-mail ID");


		   document.getElementById('UcFansComments1_txtEMail').value="";
		   document.getElementById('UcFansComments1_txtEMail').focus();
		   return false;
		 }
		else if (str.indexOf(dot,(lat+2))==-1)
		 {
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansComments1_txtEMail').value="";
		   document.getElementById('UcFansComments1_txtEMail').focus();
		   return false;
		 }
		else if (str.indexOf(" ")!=-1)
		 {
		   alert("Invalid E-mail ID");
		   document.getElementById('UcFansComments1_txtEMail').value="";
		   document.getElementById('UcFansComments1_txtEMail').focus();
		   return false;
		 }
		else
		{
			return true;
		}
	}
}

function isEmptyFirstName()
{
	val=document.getElementById('UcFansRegistrationForm1_txtFirstName').value;
		for(var i=0; i<val.length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid First Name");
			 document.getElementById('UcFansRegistrationForm1_txtFirstName').value="";
			 return false;
			}
		}
}
function isEmptyName()
{
	val=document.getElementById('UcFansComments1_txtName').value;
		for(var i=0; i<val.length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid Name");
			 document.getElementById('UcFansComments1_txtName').value="";
			 return false;
			}
		}
}
function isEmptyMiddleName()
{
	val=document.getElementById('UcFansRegistrationForm1_txtMiddleName').value;
		for(var i=0; i<val.length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid Middle Name");
			 document.getElementById('UcFansRegistrationForm1_txtMiddleName').value="";
			 return false;
			}
		}
}

function isEmptyLastName()
{
	val=document.getElementById('UcFansRegistrationForm1_txtLastName').value;
		for(var i=0; i<val.length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid Last Name");
			 document.getElementById('UcFansRegistrationForm1_txtLastName').value="";
			 return false;
			}
		}
}

function isEmptyAddress1()
{
	val=document.getElementById('UcFansRegistrationForm1_txtAddress1').value;
		for(var i=0; i<val.length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid Address1");
			 document.getElementById('UcFansRegistrationForm1_txtAddress1').value="";
			 return false;
			}
		}
}

function isEmptyCity()
{
	val=document.getElementById('UcFansRegistrationForm1_txtCity').value;
		for(var i=0; i<val.length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid City");
			 document.getElementById('UcFansRegistrationForm1_txtCity').value="";
			 return false;
			}
		}
}

function isEmptyState()
{
	val=document.getElementById('UcFansRegistrationForm1_txtState').value;
		for(var i=0; i<val.length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid State");
			 document.getElementById('UcFansRegistrationForm1_txtState').value="";
			 return false;
			}
		}
}

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 PhoneValidation()
{alert("Hello");
	var Phone=document.getElementById('UcFansRegistrationForm1_txtPhoneNo').value;
	if(document.getElementById('UcFansRegistrationForm1_txtPhoneNo').value!="" && document.getElementById('UcFansRegistrationForm1_txtPhoneNo').value!=null)
	{
		if (checkInternationalPhone(document.getElementById('UcFansRegistrationForm1_txtPhoneNo').value)==false)
			{
				alert("Please Enter a Valid Phone Number");
				document.getElementById('UcFansRegistrationForm1_txtPhoneNo').value="";
				document.getElementById('UcFansRegistrationForm1_txtPhoneNo').focus();
				return false;
			}
	}
	return true;
 }
 
 function isEmptyProfession()
{
	val=document.getElementById('UcFansRegistrationForm1_txtProfession').value;
		for(var i=0; i<val.Length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid Subject");
			 document.getElementById('UcFansRegistrationForm1_txtProfession').value="";
			 return false;
			}
		}
}

 function isEmptyFansComments()
{
	val=document.getElementById('UcFansComments1_txtComments').value;
		for(var i=0; i<val.Length; i++) 
		{
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
			{
				return true;
			}
			else
			{
			 alert("Please Enter a Valid Subject");
			 document.getElementById('UcFansComments1_txtComments').value="";
			 return false;
			}
		}
}

