// JavaScript Document


var xmlHttp
//FOR SEARCH best_model.php
function login()
{
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request")
	  return
	  } 
	var url="logdiv.php"
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 

function stateChanged() 
{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 {
		
	   		//alert(xmlHttp.responseText);
			document.getElementById("subcontent").innerHTML=xmlHttp.responseText;
	 	
	 }
	 else
	 {
		document.getElementById("subcontent").innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left"><img src="images/ajax-loader.gif"/></td></tr></table>';
	}
}
function isProper(field)
{
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
  for (var i = 0; i < field.length; i++) {
  	if (iChars.indexOf(field.charAt(i)) != -1) {
//	alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }

	}
	
	
	function opacity(id, opacStart, opacEnd) {
	//speed for each frame
	var millisec = 1000;
	var speed = Math.round(millisec/100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac("+i+ ",'"+id+"')",(timer*speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac("+i+",'"+id+"')",(timer*speed));
			timer++;
		}
	}
}

function changeOpac(opacity,id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity/100);
	object.MozOpacity = (opacity/100);
	object.KhtmlOpacity = (opacity/100);
	object.filter = "alpha(opacity="+opacity+")";
}
function emailvalidation(em)   //Email validation 
{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(em))
		return true
		else
		return false
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
/********************************FOR VALIDATION**************************************************/
function forgotValidation(form)
{
	var email=form.userid.value;
	alert(email);
	if(email==""){
		inlineMsg('userid',"Email field cannot be empty.",2);
		return false;
	}
	else{
		if(!emailvalidation(email))
		{
			inlineMsg('userid',"Please enter valid email address",2);
			return false
		}
	}
	var pass=form.pass.value;
	//alert(email);
	if(pass==""){
		inlineMsg('pass',"Password field cannot be empty.",2);
		return false;
	}
	return true;
}
var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

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));
}

function hideMsg(msg){
  var msg = document.getElementById('msg');
  if(!msg.timer){
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

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);
  }
}

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;
}

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;
}

if(document.images){
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}
