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 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(category_option) {
  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 address2 = document.form1.address2.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 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(category_option=="rr2010"){
	 if(ride_options.length==0) {
    inlineMsg('ride_options','You must choose the ride option.',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 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(!Address.match(messageRegex)) {
    inlineMsg('Address','You have entered an invalid Address.',2);
    return false;
  }*/
  
 // if(message == "") {
 //   inlineMsg('message','You must enter a message.');
//    return false;
//  }
//  if(message.match(messageRegex)) {
//    inlineMsg('message','You have entered an invalid message.');
//    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;
}

// 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)
{
	field.value="";
}



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();
	}
	
}
