// JavaScript Document
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 1500";
			
		}else if(document.form1.adults.value==1 && document.form1.kids.value==2)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 2000";
			
		}else if(document.form1.adults.value==1 && 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.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 2500";
			
		}else if(document.form1.adults.value==2 && document.form1.kids.value==3)
		{
			document.form1.f_amount.disabled=false;
			document.form1.f_amount.value="Rs 3000";
			
		}		
	}
}

//*********************************************************************
// ################################################################################################################
 // form validation function //
function validate(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 option = document.form1.option.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(option.length==0) {
    inlineMsg('option','You must choose one 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;
}

//******************Volunteer validation*****************************//

function validate1(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 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(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;
	  }
	  
  }

  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 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;
  }
  return true;
}

//==============================Feedback Form=============================//
function validate_fbk(form) {
  var firstName = document.form1.firstName.value;
  var emailId = document.form1.emailId.value;
  var lastName = document.form1.lastName.value;
  var role = document.form1.role.value;  
  var radio1 = document.form1.radio1.value; 
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  
   if(firstName.length==0 || firstName=="First Name") {
    inlineMsg('firstName','You must enter your First Name.',4);
    return false;
  }
 
  if(lastName.length==0 || lastName=="Last Name") {
    inlineMsg('lastName','You must enter your Last Name.',4);
    return false;
  }
   if(emailId == "") {
    inlineMsg('emailId','You must enter your email.',4);
    return false;
  }
  if(!emailId.match(emailRegex)) {
    inlineMsg('emailId','<strong>Error</strong><br />You have entered an invalid email.',4);
    return false;
  }
  if(role == "") {
    inlineMsg('role','You must select your role.',4);
    return false;
  }
  if(radio1 == "") {
    inlineMsg('radio1','You must select your role.',4);
    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="";
}

