// form validation function //
var global=0,global1=0;
function change()
{
global1=1;	
}

function validate_forgot(form)
{
	var email = form.emailid.value;
	var rno = form.rollno.value;
	 var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	  if(email == "") {
    inlineMsg('emailid','<strong>Error</strong><br />You must enter your email-id.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('emailid','<strong>Error</strong><br />You have entered an invalid email-id.',2);
    return false;
  }
   if(rno == "" | isNaN(rno)){
  	inlineMsg('rollno','You must enter a roll no');
	return false;
  }
}
function dat()
{
//	alert("ads");
	global=1;
var year = document.register.year.options[document.register.year.selectedIndex].value;
var mon = document.register.month.options[document.register.month.selectedIndex].value

if((mon==4)||(mon==6)||(mon==9)||(mon==11))
 {
	document.register.date.length=30;

 }
 else
if(mon==2){
		if(year%4==0){
			document.register.date.length=29;
		
		}
		else{
		document.register.date.length=28;
	}
}else{
	document.register.date.length=31;
}

var option =Array(32);var i;
var j=document.register.date.length;
document.register.date.length=0
for(i=1;i<=j;i++){
option[i]=document.createElement("OPTION");
option[i].text=i;
option[i].value=i;
try
	{
	document.register.elements["date"].add(option[i],null);
	}
	catch(ex)
	{
	document.register.elements["date"].add(option[i]);
	}
}
}
function adminvalidate(form)
{
	var rno=document.getElementById("start").value;
	if(rno == "" | isNaN(rno)){
  	inlineMsg('start','You must enter a start limit correctly');
	return false;
  }
   
	var end=document.getElementById("end").value;
	if(end == "" | isNaN(end)){
  	inlineMsg('end','You must enter a end limit correctly');
	return false;
  }
  if(end<rno)
  {
	 inlineMsg('end','End limit must be greater than start limit');
	return false;
 
  }
}
function validateupdate(form)
{
		//alert(global);
  var email = form.emailid.value;
    
  var name = form.name.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(name == "") {
    inlineMsg('name','You must enter your name.');
    return false;
  }
   if(!name.match(nameRegex)) {
    inlineMsg('name','You have entered an invalid name.',2);
    return false;
  }		
 
 var nname=form.nname.value;
  if(nname == "") {
    inlineMsg('nname','You must enter your Nick Name.');
    return false;
  }
 
 

  
  
 
   if(email == "") {
    inlineMsg('emailid','<strong>Error</strong><br />You must enter your email-id.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('emailid','<strong>Error</strong><br />You have entered an invalid email-id.',2);
    return false;
  }
   var address = form.paddress.value;
  if (address == "")
  {
	  inlineMsg('paddress','Enter the address here.');
	  return false;
  }
  if(address.length>1024)
  {	  inlineMsg('paddress','Áddress length exceeded.');
	  return false;
  }
  
  var address1 = form.caddress.value;
 
  if(address1.length>1024)
  {
	  inlineMsg('caddress','Áddress length exceeded.');
	  return false;
  }
  
 
   var aboutme = form.aboutme.value;
  
  if(aboutme.length>1024)
  {
	  inlineMsg('aboutme','Ábout you length exceeded.');
	  return false;
  }
var aboutmit = form.aboutmit.value;

if(aboutmit.length>1024)
  {
	  inlineMsg('aboutmit','Ábout MIT length exceeded.');
	  return false;
  }
 


  return true;
}
function loginvalidate(form)
{
	 var password = form.password.value;
	 var rno=form.rollno.value;
	if(rno == ""){
  	inlineMsg('rollno','You must enter a roll no');
	return false;
  }
    
	if(isNaN(rno)){
  	inlineMsg('rollno','You must enter only numbers in roll no');
	return false;
  }

if (password == "")
  {
	  inlineMsg('password','You must specify a password.');
	  return false;
  }
  
  if(password.length<6)
  {
	  inlineMsg('password','Password Length less than 6.');
	  return false;
  }
   
}
/////////////////////
var g=0;

var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();	
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function rollno_validate()
{

if(XMLHttpRequestObject) {
var s='rollno_validate.php?rollno='+document.getElementById('rollno').value+'&&batch='+document.getElementById('batch').value+'&&dept='+document.getElementById('dept').value;

XMLHttpRequestObject.open("GET",s,true);

XMLHttpRequestObject.onreadystatechange = function()
{
if(XMLHttpRequestObject.readyState <4)
{
 //document.getElementById('1').innerHTML='<img src="1.jpg" />';
}

if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) 
{
uid_v(XMLHttpRequestObject.responseText);
delete XMLHttpRequestObject;
}
}
XMLHttpRequestObject.send(null);
}
}
function uid_v(text)
{
var obj = document.getElementById('1');
g=text;
if(text!=0)
{
document.getElementById('rollno').style.background = '#00FFFF';
obj.innerHTML=text;

}
else
{
document.getElementById('rollno').style.background ='#FFFFFF';
obj.innerHTML='';

}
}
////////////////////

function validate(form) {
	//alert("asd");
  var email = form.emailid.value;
    var password = form.password.value;
  var name = form.name.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);
  var rno=form.rollno.value;
  
  if(name == "") {
    inlineMsg('name','You must enter your name.');
    return false;
  }
   if(!name.match(nameRegex)) {
    inlineMsg('name','You have entered an invalid name.',2);
    return false;
  }		
 
 var nname=form.nname.value;
  if(nname == "") {
    inlineMsg('nname','You must enter your Nick Name.');
    return false;
  }
 
/*  if(global==0)
  {
	  inlineMsg('date','Please select your date of birth');
	  return false;
	  }*/
  var dat = form.date.value;
  if(dat=="")
  {
	  inlineMsg('date','Enter the date please.');
	  return false;
  }
  
  var month = form.month.value;
   if(month=="")
  {
	  inlineMsg('date','Enter the month please.');
	  return false;
  }
  var year = form.year.value;
   if(year=="")
  {
	  inlineMsg('date','Enter the year please.');
	  return false;
  }
  
 if(rno == "" | isNaN(rno)){
  	inlineMsg('rollno','You must enter a roll no');
	return false;
  }
   if (password == "")
  {
	  inlineMsg('password','You must specify a password.');
	  return false;
  }
  
  if(password.length<6)
  {
	  inlineMsg('password','Password Length less than 6.');
	  return false;
  }
    var rpassword = form.rpassword.value;

  if (rpassword == "")
  {
	  inlineMsg('rpassword','You must specify a password.');
	  return false;
  }
   if(rpassword.length<6)
  {
	  inlineMsg('rpassword','Password Length less than 6.');
	  return false;
  }
  if (password != rpassword)
  {
	  inlineMsg('rpassword','Password Mismatch.');
	  return false;
  }
  if(document.getElementById("dept").value=="select-one")
  {
	  inlineMsg('dept','select your department');
	  return false;
	  }
	  if(!(form.gender[0].checked ||  form.gender[1].checked))
		{
	  inlineMsg('gender1','select gender');
	  return false;
			
			}
 
 
   if(email == "") {
    inlineMsg('emailid','<strong>Error</strong><br />You must enter your email-id.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('emailid','<strong>Error</strong><br />You have entered an invalid email-id.',2);
    return false;
  }
 

  //var gender=document.getElementById("gender").value;
  
 /* if(gender.checked==FALSE){
    inlineMsg('gender','<strong>Error</strong><br />You must select your gender.',2);
    return false;
  }*/
  var address = form.paddress.value;
  if (address == "")
  {
	  inlineMsg('paddress','Enter the address here.');
	  return false;
  }
  if(address.length>1024)
  {	  inlineMsg('paddress','Áddress length exceeded.');
	  return false;
  }
  
 
  /*  if(global1==0)
  {	
	  inlineMsg('showdetails','Please select an option');
	  return false;
	  }*/
   var aboutme = form.aboutme.value;
  if(aboutme.length>1024)
  {
	  inlineMsg('aboutme','Ábout you length exceeded.');
	  return false;
  }

 


  
  
 
  var captcha = form.captcha.value;
  if (captcha == "")
  {
	  inlineMsg('captcha','Enter the words shown above.');
	  return false;
  }

  return true;
}

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 10;
var targeta;

// 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=50)';
    msg.style.opacity = 50;
    msg.alpha = 50;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  msgcontent.style.background="#ffffff";
  msgcontent.style.border="#000000"
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  var error = document.getElementById("error");
  error.innerHTML=string;
  targetdiv.style.borderColor="#F00";
  targeta=targetdiv;
  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);
	targeta.style.borderColor="#CCC";
  }
}

// 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,80); 
  arrow.src = "images/msg_arrow.gif"; 
}