function Form_Validator(theForm)
{
var alertsay = ""; // define for long lines
//var theForm = theform;

// check if numbers field is blank
//if (theForm.profile.value.length < 4)
if (theForm.profile.value == "")
{
alert("Enter your "+ad_domain+" ID, Enter minimum char Four.");
theForm.profile.focus();
return (false);
}

// allow ONLY alphanumeric keys, no symbols or punctuation
// this can be altered for any "checkOK" string you desire
if (theForm.profile.value != "")
{
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789";
var checkStr = theForm.profile.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("In Profile ID not use special character ÅÄÖåäö or Space.");
theForm.profile.focus();
return (false);
}
}

// require at least 4 characters in the password field
if (theForm.password.value.length < 4)
{
alert("Enter your Password.");
theForm.password.focus();
return (false);
}

// check if both password fields are the same
if (theForm.password.value != theForm.conpassword.value)
{
	alert("Your Confirm Password not same.");
	theForm.conpassword.focus();
	return (false);
}

if (theForm.nameu.value.length == 0)
{
alert("Please Mention your Name.");
theForm.nameu.focus();
return (false);
}




// test if valid email address, must have @ and .
if (theForm.email.value != "")
{
var checkEmail = "@.";
var checkStr = theForm.email.value;
var EmailValid = false;
var EmailAt = false;
var EmailPeriod = false;
for (i = 0;  i < checkStr.length;  i++)
{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
		EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
		EmailPeriod = true;
		if (EmailAt && EmailPeriod)
		break;
		if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
	if (EmailAt && EmailPeriod)
	{
		EmailValid = true
		break;
	}
}
if (!EmailValid)
{
alert("Enter Your E-mail Like name@anyname.com");
theForm.email.focus();
return (false);
}
}



// check if the first drop down is selected, if so, invalid selection
if (theForm.postedby.selectedIndex == 0)
{
alert("Posted By.");
theForm.postedby.focus();
return (false);
}

if (theForm.dob.selectedIndex == 0 || theForm.monthofbirth.selectedIndex == 0 || theForm.yearofbirth.selectedIndex == 0)
{
alert("Specify Your Date of Birth.");
if (theForm.yearofbirth.selectedIndex == 0)
{theForm.yearofbirth.focus();}
if (theForm.monthofbirth.selectedIndex == 0)
{theForm.monthofbirth.focus();}
if (theForm.dob.selectedIndex == 0)
{theForm.dob.focus();}
return  (false);
}

if (!checkRadioArray(theForm.gender))
 {
	alert("Select Your Gender.");
	theForm.gender[0].focus();
	return false; 
 }

if (theForm.martialstatus.selectedIndex == 0)
{
alert("Select your Martial Status.");
theForm.martialstatus.focus();
return (false);
}

martials = theForm.martialstatus.value;
if (martials != "Never Married")
{
	if (theForm.child.selectedIndex == 0)
	{
	alert("Do you have Childrens or Not.");
	theForm.child.focus();
	return (false);
	}
}


if (theForm.religion.selectedIndex == 0)
{
alert("Select Your Religion.");
theForm.religion.focus();
return (false);
}


if (theForm.caste.selectedIndex == 0)
{
alert("Select Your Caste From List.");
theForm.caste.focus();
return  (false);
}

caste = theForm.caste.value;
if (caste == "Other")
{
	if (theForm.subcaste.value == "")
	{
	alert("Please Enter your Sub Caste");
	theForm.subcaste.focus();
	return (false);
	}
}

if (theForm.country.selectedIndex == 0)
{
alert("Specify your Country from the drop down list.");
theForm.country.focus();
return (false);
}

if (theForm.stateofresidence.selectedIndex == 0)
{
alert("Specify your State, IF Not in the List Select Other.");
theForm.stateofresidence.focus();
return (false);
}

if (theForm.residence.selectedIndex == 0)
{
alert("Select your City from the drop down list.");
theForm.residence.focus();
return (false);
}

residence = theForm.residence.value;
if (residence == "Other")
{
	if (theForm.othercity.value == "")
	{
	alert("Please Enter your City");
	theForm.othercity.focus();
	return (false);
	}
}

if (theForm.mobileno.value == "")
{
alert("Specify your Contact No : Mobile.");
theForm.mobileno.focus();
return false;
}

if (!theForm.termcon.checked)
{
confirm("Tick The Check box and confirm that you have read and will abide by this agreement.");
theForm.termcon.focus();
return (false);
}


function checkRadioArray(radioButtons)
{ 
	for (var i=0; i < radioButtons.length; i++) 
	{
		if (radioButtons[i].checked)
		{
			return true;
		}
	}
}


}
function selectmartial()
{
	var martials;
	var formname = document.newuser;

	martials = formname.martialstatus.value;

	if (martials == "Never Married")
	{
		formname.child[0].disabled = true;
		formname.child[1].disabled = true;
		formname.child[2].disabled = true;
		formname.child[3].disabled = true;
	}
	else
	{
		formname.child[0].disabled = false;
		formname.child[1].disabled = false;
		formname.child[2].disabled = false;
		formname.child[3].disabled = false;
	}
}


function selectcity()
{
	var scity;
	var formname = document.newuser;
	
	scity = formname.residence.value;

	if	(scity == "Other")
	  {
	   formname.othercity.disabled = false;
		formname.othercity.focus();
	  }
	else
	  {
	   formname.othercity.disabled = true;
	  }
		return (false);
}

function othercityadd() 
{
	var formname = document.newuser;
    fieldvalue = window.formname.othercity.value;
    window.formname.othercity24.value=fieldvalue;
    window.formname.othercity24.focus();
}
function subcasteadd() 
{
	var formname = document.newuser;
    fieldvalue = window.formname.subcaste.value;
    window.formname.subcaste24.value=fieldvalue;
    window.formname.subcaste24.focus();
}


function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
