function ActivateTeams(cat_id)
{
	
	if(document.form1.option.value=="team")
	{
		document.form1.team.disabled=false;
		document.form1.adults.disabled=true;
		document.form1.kids.disabled=true;
		document.form1.f_amount.disabled=true;
	}else if(document.form1.option.value=="family")
	{
		
		document.form1.team.disabled=true;
		document.form1.adults.disabled=false;
		document.form1.kids.disabled=false;
		document.form1.f_amount.disabled=true;	
		
    }else
	{	
		document.form1.team.disabled=true;
		document.form1.adults.disabled=true;
		document.form1.kids.disabled=true;
		document.form1.f_amount.disabled=true;	
	}
}

function RestrictRideOption(thisValue)
{
	if(thisValue=="own")
	{
		document.form1.ride_options.options.length=0;
		
		document.form1.ride_options.options[0]=new Option("Select", "", true, false);
		document.form1.ride_options.options[1]=new Option("63 KM Ride", "63", false, false);
		document.form1.ride_options.options[2]=new Option("5 KM Ride", "5", false, false);
		document.form1.ride_options.options[3]=new Option("10 KM Ride", "10", false, false);
		
		
	} else if(thisValue=="rental")
	{
		document.form1.ride_options.options.length=0;
		
		document.form1.ride_options.options[0]=new Option("Select", "", true, false);
		document.form1.ride_options.options[1]=new Option("5 KM Ride", "5", false, false);
	}
}

function calc_amount()
{
	if(document.form1.adults.value.length>0 || document.form1.kids.value.length>0)
	{
		if(document.form1.adults.value==1 && document.form1.kids.value==1)	
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 1250";
			
		}else if(document.form1.adults.value==1 && document.form1.kids.value==2)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 1500";
			
		}else if(document.form1.adults.value==1 && document.form1.kids.value==3)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 1750";
			
		}else if(document.form1.adults.value==2 && document.form1.kids.value==1)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 2000";
			
		}else if(document.form1.adults.value==2 && document.form1.kids.value==2)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 2250";
			
		}else if(document.form1.adults.value==2 && document.form1.kids.value==3)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 2500";
			
		}else if(document.form1.adults.value==2)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 1300";
			
		}else if(document.form1.adults.value==1)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 1000";
			
		}
		
	}
}

// ################################################################################################################
 // form validation function //
function validate1() {
  var firstName = document.form1.firstName.value;
  var emailId = document.form1.emailId.value;
  var lastName = document.form1.lastName.value;
  var pwd1 = document.form1.pwd1.value;
  var pwd2 = document.form1.pwd2.value;
  var organisation = document.form1.organisation.value;
  var option = document.form1.option.value;
 /* if(category_option=="rr2011"){*/
  var ride_options = document.form1.ride_options.value;
  /*}*/
  var team = document.form1.team.value;
  var contactNo = document.form1.contactNo.value;
  var address1 = document.form1.address1.value;
  var gender = document.form1.gender.value;
  var val = 0;
  //var message = form.message.value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  
  if(firstName.length==0 || firstName=="First Name") {
    inlineMsg('firstName','You must enter your First Name.',3);
    return false;
  }
  /*if(!firstName.match(nameRegex)) {
    inlineMsg('firstName','You must enter your First Name.',3);
    return false;
  }*/
  if(lastName.length==0 || lastName=="Last Name") {
    inlineMsg('lastName','You must enter your Last Name.',3);
    return false;
  }
 /* if(!lastName.match(nameRegex)) {
    inlineMsg('lastName','You must enter your Last Name.',3);
    return false;
  }*/ 
  
  if(organisation.length==0) {
    inlineMsg('organisation','You must enter your Organasiation.',3);
    return false;
  }
  /*if(!organisation.match(nameRegex)) {
    inlineMsg('organisation','You have entered an invalid Organasiation.',3);
    return false;
  }*/
  if(emailId == "") {
    inlineMsg('emailId','You must enter your email.',3);

    return false;
  }
  if(!emailId.match(emailRegex)) {
    inlineMsg('emailId','<strong>Error</strong><br />You have entered an invalid email.',3);
    return false;
  }
  
  if(pwd1.length==0 || pwd1=="Last Name") {
    inlineMsg('pwd1','You must enter your Password.',3);
    return false;
  }
  
  if(pwd2.length==0 || pwd2=="Last Name") {
    inlineMsg('pwd2','You must re-enter your Password.',3);
    return false;
  }
  
  if(pwd2!=pwd1) {
    inlineMsg('pwd2','Re-entered password is not same as entered Password.',3);
    return false;
  }
  
  if(option.length==0) {
    inlineMsg('option','You must choose one option.',3);
    return false;
  }
  if(option=="team" && team.length==0) {
	inlineMsg('selected','You must choose your team.',3);
    return false;
  }
 /* if(category_option=="rr2010"){*/
  if(ride_options.length==0) {
  	inlineMsg('ride_options','You must choose the ride option.',3);
  	return false;
  }
  if(gender.length == 0)
  {
	  inlineMsg('gender','You must choose your gender.',3);
  	return false;
  }
  /*}*/
  /*if(!option.match(nameRegex)) {
    inlineMsg('option','You have choosen an invalid option.',3);
    return false;
  }*/
  
 /* if(address1 == "") {
    inlineMsg('address1','You must enter your Address.',3);
    return false;
  }
  if(address2 == "") {
    inlineMsg('address2','You must enter <br>your Street, state, Pincode etc.',3);
    return false;
  }*/
  if(contactNo == "") {
    inlineMsg('contactNo','You must enter your mobile number. e.g: 9177613983',3);
    return false;
  }
  if(contactNo != "")
  {	
	  var check=true;
	  var newKey;
	  for(var i=0; i<contactNo.length; i++)
	  {
		   newKey=contactNo.charAt(i);
		  if(((newKey < "0" ) || (newKey > "9")) && !(newKey == ""))
		  {
			  check=false;
			  break;
		  }
	  }
	  if(!check || contactNo.length != 10)
	  {
		  inlineMsg('contactNo','Please enter a valid mobile number. e.g: 9177613983',3);
   		  return false;
	  }
	  
  }
  
  for(var i=0; i<document.form1.cycle_opt.length; i++) // for validating the radio buttons
  {
	  if(document.form1.cycle_opt[i].checked == true)
	  {
		  val = document.form1.cycle_opt[i].value;
		break;
	  }
  }
	if(val == 0)
	{ 
		inlineMsg('cycle_opt','please choose your cycle option',3);
    	return false;
    }

  return true;
}
//***********************************************************************************************************
function validate2() {
	var ride_options = document.form1.ride_options.value;
	
	if(ride_options.length==0) {
  		inlineMsg('ride_options','You must choose the ride option.',3);
  		return false;
  	}
	return true;
}

//============================================Contest Registration Form Validation===========================
function validate3(form) {  
  var firstName = document.form1.firstName.value;
  var emailId = document.form1.emailId.value;
  var lastName = document.form1.lastName.value;
  var organisation = document.form1.organisation.value;   
  var contactNo = document.form1.contactNo.value; 
  var grade = document.form1.grade.value; 
  
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  
  if(firstName.length==0 || firstName=="First Name") {
    inlineMsg('firstName','You must enter your First Name.',3);
    return false;
  }
  
 if(lastName.length==0 || lastName=="Last Name") {
    inlineMsg('lastName','You must enter your Last Name.',3);
    return false;
  }
 
  if(organisation.length==0) {
    inlineMsg('organisation','You must enter your Organasiation.',3);
    return false;
  }
  
   if(emailId == "") {
    inlineMsg('emailId','You must enter your email.',3);
    return false;
  }
  if(!emailId.match(emailRegex)) {
    inlineMsg('emailId','<strong>Error</strong><br />You have entered an invalid email.',3);
    return false;
  }
  
   if(grade.length==0) {
    inlineMsg('grade','You must enter your Grade.',3);
    return false;
  }
  
  if(contactNo.length == 0) {
    inlineMsg('contactNo','You must enter your mobile number.',3);
    return false;
  }
  
   if(contactNo != "")
  {	
	  var check=true;
	  var newKey;
	  for(var i=0; i<contactNo.length; i++)
	  {
		   newKey=contactNo.charAt(i);
		  if(((newKey < "0" ) || (newKey > "9")) && !(newKey == ""))
		  {
			  check=false;
			  break;
		  }
	  }
	  if(!check || contactNo.length != 10)
	  {
		  inlineMsg('contactNo','Please enter a valid mobile number',3);
   		  return false;
	  }
	  
  }
   
  return true;
}

function validateSub(form) {
  var fName = document.lsmgift.fName.value;
  var mailId = document.lsmgift.mailId.value;
  var lName = document.lsmgift.lName.value;  
  var grade = document.lsmgift.grade.value;
  var school = document.lsmgift.school.value; 
  var city = document.lsmgift.city.value;
  var second_lang = document.lsmgift.second_lang.value;
  var third_lang = document.lsmgift.third_lang.value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  
  if(fName.length==0 || fName=="First Name") {
    inlineMsg('fName','You must enter the student\'s First Name.',3);
    return false;
  }
  
  if(lName.length==0 || lName=="Last Name") {
    inlineMsg('lName','You must enter the student\'s Last Name.',3);
    return false;
  }
 
  if(grade.length==0) {
    inlineMsg('grade','Mention the Grade / Standard.',3);
    return false;
  }
  if(school == "") {
    inlineMsg('school','Mention the school name.',3);
    return false;
  }
 if(city == "") {
    inlineMsg('city','You must enter the city.',3);
    return false;
  }
   if(mailId == "") {
    inlineMsg('mailId','Mention the mail id through which we can contact the student.',3);
    return false;
  }
  if(!mailId.match(emailRegex)) {
    inlineMsg('mailId','<strong>Error</strong><br />You have entered an invalid email.',3);
    return false;
  }
  if(second_lang == "") {
    inlineMsg('second_lang','Please choose the second language preference of the student.',3);
    return false;
  }
  if(third_lang == "") {
    inlineMsg('third_lang','Please choose the third language preference of the student.',3);
    return false;
  }
  return true;
}

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,100); 
  arrow.src = "images/msg_arrow.gif"; 
}

function resetForm()
{
	document.form1.reset();
}
function ClearForm(field)
{
	if(field.value=="First Name" || field.value=="Last Name")
	field.value="";
}
function ClearForm1(field)
{
	if(field.value=="")
	field.value="First Name";	
}
function ClearForm2(field)
{
	if(field.value=="")
	field.value="Last Name";	
}



function validate2(form) {	
  var firstName = document.form1.firstName.value;
  
 var lastName = document.form1.lastName.value;
 var emailId = document.form1.emailId.value;
  var organisation = document.form1.organisation.value;
   var contactNo = document.form1.contactNo.value;
   var PledgeAmount=document.form1.PledgeAmount.value;
  /* var programs=document.form1.pgm.value;  
  var country=document.form1.country.value;
  var city=document.form1.city.value;
  //var message = form.message.value;*/
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  //var numRegex = /^[0-9]$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
   
   if(firstName.length==0 || firstName=="First Name") {
    inlineMsg('firstName','You must enter your First Name.',3);
    return false;
  }
  
  if(lastName.length==0 || lastName=="Last Name") {
    inlineMsg('lastName','You must enter your Last Name.',3);
    return false;
  }
  
   if(organisation.length==0) {
    inlineMsg('organisation','You must enter your Organasiation.',3);
    return false;
  }
  
   if(emailId == "") {
    inlineMsg('emailId','You must enter your email.',3);
    return false;
  }
  if(!emailId.match(emailRegex)) {
    inlineMsg('emailId','<strong>Error</strong><br />You have entered an invalid email.',3);
    return false;
  }
  
   if(contactNo == "") {
    inlineMsg('contactNo','You must enter your Mobile No. e.g: 9177613983',3);
    return false;
  }
  
  if(contactNo != "")
  {	
	  var check=true;
	  var newKey;
	  for(var i=0; i<contactNo.length; i++)
	  {
		   newKey=contactNo.charAt(i);
		  if(((newKey < "0" ) || (newKey > "9")) && !(newKey == ""))
		  {
			  check=false;
			  break;
		  }
	  }
	  if(!check || contactNo.length != 10)
	  {
		  inlineMsg('contactNo','Please enter a valid mobile number',3);
   		  return false;
	  }
	  
  }
    
  if(PledgeAmount == "") {
    inlineMsg('PledgeAmount','<strong>Error</strong><br />You must enter valid amount .',3);
    return false;
  }
 /* if(emailId == "") {
    inlineMsg('emailId','<strong>Error</strong><br />You must enter your email.',3);
    return false;
  }
  if(!emailId.match(emailRegex)) {
    inlineMsg('emailId','<strong>Error</strong><br />You have entered an invalid email.',3);
    return false;
  }   */ 
  /*if(firstName == "") {
    inlineMsg('firstName','You must enter your First name.',3);
    return false;
  }
  if(!firstName.match(nameRegex)) {
    inlineMsg('firstName','You have entered an invalid name.',3);
    return false;
  }
  if(lastName == "") {
    inlineMsg('lastName','You must enter your Last name.',3);
    return false;
  }
  if(!lastName.match(nameRegex)) {
    inlineMsg('lastName','You have entered an invalid name.',3);
    return false;
  }  */
  /*if(organisation == "") {
    inlineMsg('organisation','You must enter your institute/organisation.',3);
    return false;
  }
  if(!organisation.match(nameRegex)) {
    inlineMsg('organisation','You have entered an invalid institute/organisation.',3);
    return false;
  }
  if(programs == "") {
    inlineMsg('programs','You must enter your programs .',3);
    return false;
  }
  
   */
  
 return true;
}


function enable_table(option)
{	
	if(option!="Student")
	{	
		setTable('table1',option);	
		document.form1.grade.disabled=true;
		document.form1.grade.style.background="#E0E0E0";
		return false;		
	}else
	{
		setTable('table1',option);
		document.form1.grade.disabled=false;
	}
	
}

//======== Enable/Disable table=============//
function setTable(what,opt){
	if(opt=="Teacher" || opt=="Guardian" || opt=="Parent" || opt=="Mentor" || opt=="Others")
	{
		if(document.getElementById(what).style.display=="none")
			{
				document.getElementById(what).style.display="block";
			}
  }else if(opt=="Student")
		{
			if(document.getElementById(what).style.display=="block")
			{
				document.getElementById(what).style.display="none";
				document.form1.grade.disabled=false;
				document.form1.grade.style.background="";
			}
		}
}

//=================Capture Enter key and submit the form=======================
function move(e)
{
if(!e) e = window.event;

if( e.keyCode == 13)
	{    
		document.form1.submit();
	}
	
}
