var captchavalid=false;
function validate(form)
{
	
	if(isEmpty(form.full_name))
	{ 
		alert("Please enter full name");form.full_name.focus();
		return false; 
	}
	/*if(!isAlpha1(form.full_name))
	{ 
		alert("Please enter valid full name");form.full_name.focus();
		return false; 
	}*/
	
	
	noc = form.elements["name_on_the_card[]"].length;
	noc_empty	=	0;
	for(i=0;i<noc;i++)
	{
		if(form.elements["name_on_the_card[]"][i].value == "")
		{
			noc_empty += 1;
		}
	}
	if(noc_empty == 20) { alert("Please enter your name on card to be appeared"); return false;}

	if(isEmpty(form.address))
	{ 
		alert("Please enter address");form.address.focus();
		return false; 
	}
//	alert(document.clubform.city.value);
	if(document.clubform.city.value=="-")
	{ 
		alert("Please enter city");
		document.clubform.city.focus();
		return false; 
	}
	if(form.pincode.value!="")
	{
		if(!isNumeric(form.pincode))
		{
			alert("Please enter valid pincode");
			form.pincode.focus();
			form.pincode.select();
			return false;
		}
	}


	if(isEmpty(form.phone_number))
	{ 
		alert("Please enter phone number");form.phone_number.focus();
		return false; 
	}
	if(!isNumeric(form.phone_number))
	{ 
		alert("Please enter valid phone number");form.phone_number.focus();
		return false; 
	}
	
	if(isEmpty(form.email))
	{ 
		alert("Please enter email address");form.email.focus();
		return false; 
	}
	if(!isEmail(form.email))
	{ 
		alert("Please enter valid email address");form.email.focus();
		return false; 
	}
	if(isEmpty(form.confirm_email))
	{ 
		alert("Please confirm email address");form.confirm_email.focus();
		return false; 
	}

	if(!isEmail(form.confirm_email))
	{ 
		alert("Please enter valid confirm email address");form.confirm_email.focus();
		return false; 
	}
	
	if(form.email.value != form.confirm_email.value)
	{
		alert("Emails mismatch");form.email.focus();
		return false; 
	}

	if(!chkListbox(form.dob, 'Date of birth')) {return false;}
	if(!chkListbox(form.mob, 'Month of birth')) {return false;}
	if(!chkListbox(form.yob, 'Year of birth')) {return false;}
	
	sexChk	=	RadioCheck(form,"sex");
	if(sexChk	==	0) { alert('Please select your gender'); return false; }


	if(isEmpty(form.occupation))
	{ 
		alert("Please enter occupation");form.occupation.focus();
		return false; 
	}

	/*if(!chkListbox(form.occupation, 'Occupation')) {return false;}

	if(form.occupation.value == "Employed" && isEmpty(form.employer_name))
	{
		alert("Please enter employer name");form.employer_name.focus();
		return false; 
	}*/

	cameraChk	=	RadioCheck(form,"own_camera");
	if(cameraChk ==	0) { alert('Do you own a camera?'); return false; }

	cameraValue	=	getRadioValue(form.own_camera);
	if(cameraValue == "Yes" && isEmpty(form.camera_brand_model))
	{
		alert("Please enter camera/brand model");form.camera_brand_model.focus();
		return false; 
	}

	pgTrainingChk	=	RadioCheck(form,"any_photography_training");
	if(pgTrainingChk ==	0) { alert('Have you atteneded any photography training?'); return false; }

	aptValue	=	getRadioValue(form.any_photography_training);
	if(aptValue == "Yes" && isEmpty(form.photography_training_details))
	{
		alert("Please enter your photography training details");form.photography_training_details.focus();
		return false; 
	}

/*	hcrChk	=	RadioCheck(form,"member_of_holiday_club_resort");
	if(hcrChk ==	0) { alert('Are you a member of any holiday club resort?'); return false; }

	hcrValue	=	getRadioValue(form.member_of_holiday_club_resort);
	if(hcrValue == "Yes" && isEmpty(form.name_of_holiday_club_resort))
	{
		alert("Please enter the name of club/resort");form.name_of_holiday_club_resort.focus();
		return false; 
	}*/

	/*cmwChk	=	RadioCheck(form,"member_of_any_club_in_work");
	if(cmwChk ==	0) { alert('Are you a member of any club in your place of work?'); return false; }

	cmwValue	=	getRadioValue(form.member_of_any_club_in_work);
	if(hcrValue == "Yes" && isEmpty(form.name_of_the_club_in_work))
	{
		alert("Please enter the name of club");form.name_of_the_club_in_work.focus();
		return false; 
	}

	hobbies	= BoxesChecked(form, "favourite_hobby[]");
	if(hobbies == 0) { alert('Please select atleast one hobby'); return false; }

	*/
	if(isEmpty(form.heard_through))
	{ 
		alert("Please enter how you heard about pixetra?");form.heard_through.focus();
		return false; 
	}
	
	/*agree	= BoxesChecked(form, "agree");
	if(agree == 0) { alert('Please agree to the terms and conditions'); return false; }*/
	
	return true;
	
}

function frm_action()
{
	//alert(process_order);
	if(captchavalid == false)
	{
		alert("Invalid code");
		document.clubform.captcha.focus();		
		return false;
	}
	else
	{
		agree	= BoxesChecked(document.clubform, "agree");
		if(agree == 0) { alert('Please agree to the terms and conditions'); return false; }
		
	}
	document.clubform.submit();
}
function moveCursor(element)
{
	//alert(element.value);	
	if(lTrim(element.value)!="")
	{
		//alert(element.tabIndex);
		var nextEl = element.form.elements[element.tabIndex];
		//alert(nextEl.tabIndex);
		nextEl.focus();
	}
	//else
	//	alert("try again");
}
var http   = createRequestObject(); 
var tno ;
function checkCaptcha()
{
	var frm = document.clubform;
	var URL = getPath()+"/club/captcha/";
	var fields		=	new Array();
	tno = frm.captcha.value;
	qs =	fields.join('&');
	desturl = noCache(URL);
	if(validate(frm))
	{
		http.open('POST', URL);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.onreadystatechange = getCaptcha; 
		http.send(qs);	
	}
	else
	{
		return false;
	}
}
function getCaptcha()
{
	if(http.readyState == 4)
	{ 
		var resp = http.responseText;
		if(trimAll(tno) != trimAll(resp))
		{
			//alert("Please Enter Valid code");
			document.getElementById("captcha1").src =getPath()+"/lib/turing.php?"+ (new
			Date()).getMilliseconds();

			captchavalid = false;
		}
		else
		{
			captchavalid = true;
		}
		frm_action();
	}
}

function getPath()
{
	url		=	document.location.href;
	x		=	url.indexOf(".");
	x		=	url.indexOf("/",x);
	return url.substring(0,x);
}

var http   = createRequestObject(); 
/*------------------------------------------------------------------------------*/
function createRequestObject()
{
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer")
		{
			request_o = new ActiveXObject("Microsoft.XMLHTTP");
		}
	else
		{
			request_o = new XMLHttpRequest();
		}
	return request_o; //return the object
}
/*------------------------------------------------------------------------------*/
function noCache(url)
{
	var sep = (-1 < url.indexOf("?")) ? "&" : "?"	
	url = url + sep + "__=" + encodeURIComponent((new Date()).getTime());	
	return url;
}
//*------------------------------------------------------------------------------*/
function trimAll(strValue)
{
   var objRegExp = /^(\s*)$/;

   //check for all spaces
   if(objRegExp.test(strValue)) 
   {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
   }
    
   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) 
   {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
   }
   return strValue;
}
