function validationvoting()
{
	var votinglength = document.votingform.voting1.length;
	var img=document.votingform.uploadimage.value;
	var proimage=img.split('.');
	var pphone=document.getElementById('phonenum').value;


	var i;
	var chosen =0;
	for(i=0; i< votinglength;i++ )
	{
		if(document.votingform.voting1[i].checked==true)
			chosen++;
	}
	if(chosen==0)
	{
		alert("Please choose the bachelor you would like to go on a date with");
		document.votingform.voting1[0].focus();
		return false;
	}
	else
	if(isEmpty("username","Please enter Your Name") || isEmpty("emailadd","Please enter Your Email") || isEmpty("userage","Please enter your age") || isEmpty("userheight","Please enter your height")  || isEmpty("phonenum","Please enter a valid phone number of 10 numbers and no spaces"))
	return false
else	
if(isEmpty("hobbies","Please enter a list of your hobbies","Please enter here list of your hobbies") || isEmpty("choosebachelor","Please explain why you would like to go on a date with the bachelor you chose","Please explain why you would like to go on a date with the bachelor you chose") ||isEmpty("uploadimage","Please upload an image of yourself") )
		return false;
else	
	if(document.getElementById('checkbox').checked==false)
	{
		alert("Please let us know you have read and accepted the terms & conditions by checking the checkbox.");
		document.getElementById('checkbox').focus();
		return false;
	}	
	else
		document.votingform.submit();	
		
		
}

function isEmpty(field,mes)
{	
	var val=document.getElementById(field).value;
	if( val=="")
	{
		alert(mes);
		document.getElementById(field).select();
		document.getElementById(field).focus();
		return true;
	}
	else
		return false;
}

function chkemail(val,id)
{
	var regex = /^[a-zA-Z]{1}[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;	
	if(regex.test(val)==0)
	{
		alert("Please enter valid Email address");
		document.getElementById(id).select();
		document.getElementById(id).focus();
		return true;
	}
	else
		return false;
}
function changedata(idvalue)
{
	document.getElementById(idvalue.name).value="";
}

function chknumeric(id,msg)
{
	if(isNaN(document.getElementById(id).value))
	{
		
		alert(msg);
		document.getElementById(id).focus();
		return true;
	}
	else
		return false;
}
// 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 checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
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 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 votingform()
{
	
	if(isEmpty("yourname","Please enter your first name") || isEmpty("youremail","Please enter your email") ||  isEmpty("age","Please enter your age")  ||  isEmpty("postcode","Please enter your postcode") || isEmpty("lastname","Please enter your last name") || isEmpty("confirmemail","Please enter a confirmation email") )
	return false;
else
if(document.getElementById('confirmemail').value!=document.getElementById('youremail').value)
{
	alert("Sorry, your confirmation email did not match your entered email address. Please check this.");
	document.getElementById('confirmemail').focus();
	return false;
}
else
if(document.getElementById('gender').value=="")
{
	alert("Please select your gender");
	document.getElementById('gender').focus();
	return false;	
}
else
if(document.getElementById('frndname').value!="")
{
	if(isEmpty("frndemail","Please enter a Friend's Email") )
	return false
}

if(document.getElementById('checkbox').checked==false)
{
	alert("Please check the box to show you have read and accept the terms and conditions");
	document.getElementById('checkbox').focus();
	return false
}
else
	document.voteform.submit();
	
}

function referanotherfrnd()
{
	var k =document.getElementById('frndscount').value;
	var t=++k;

	/*if(k.length!="" && !isNaN(k.length))
		var t= 1;
	else
		var t=2;*/
		var divtag = document.createElement("div");
		divtag.className = "colleft";
		divtag.innerHTML = "<label>Friend's Name:</label><input type=\"text\" name='frndname"+t+"' value=\"\" class=\"input sz199 mrb5\" id='frndname"+t+"'>";
		var foo = document.getElementById("fooBar");  
		foo.appendChild(divtag);
		
		var divtag1 = document.createElement("div");
		divtag1.className = "colleft";
		divtag1.innerHTML = "<label>Friend's Email:</label><input type=\"text\" name='frndemail"+t+"' value=\"\" class=\"input sz199 mrb5\" id='frndemail"+t+"' >";
		
		var foo = document.getElementById("fooBar");  
		foo.appendChild(divtag1);
		//alert(document.getElementById('frndscount').value);
		document.getElementById('frndscount').value= t;
		//alert(document.getElementById('frndscount').value);
		
		
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}


function validateZIP(zip)
{

var field=document.getElementById(zip).value;

var valid = "0123456789-";
var hyphencount = 0;
if (field.length!=4 && field.length!=10) 
{
alert("Please enter your 4 digit+4 Postcode.");
document.getElementById(zip).select();
document.getElementById(zip).focus();
return true;
}
for (var i=0; i < field.length; i++) 
{
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") 
{
alert("Invalid characters in your Postcode.  Please try again.");
return true;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
{
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
return true;
}
}
return false;
}

function gobackpage()
{
	window(-1);
}

function maintest()
{
	if(document.getElementById('userage').value.length>2)
	{
		alert("Please enter valid Age");
		document.getElementById('userage').focus();
		return false;
	}
}