int_obj = '';
var pageName = '';
function loadField(id) {

	if($(id)) {

		attachTooltip(id);
		Highlight(id);
		clearInterval(int_obj);
	}
}

//Baloon functions

function attachTooltip(elementId){
	if($(elementId)){
		Event.observe(elementId, 'focus', onfocusEle, false);
		Event.observe(elementId, 'blur', onblurEle, false);
	}
};


//only for home page tool-tip

function onblurEle(e){
	var id = Event.element(e).id;
	$(id).className = "inputstyle" ;
	$("h-" + id).className = "field-hint-inactive" ;
};

function onfocusEle(e){

	if($(selected_field)) {
		$("h-" + selected_field).className = "field-hint-inactive" ;
		$(selected_field).className = "inputstyle" ;
	}
	var id = Event.element(e).id;
	$(id).className = "inputstyle-focus" ;
	$("h-" + id).className = "field-hint" ;
};

selected_field = '';

function Highlight(id){
	selected_field = id;
	$(id).focus();
};

function displayAlert(msg)
{
	if(msg) $('msg_div').innerHTML = msg;
	$('alert_div').className = 'alert_show';
}
function hideAlert()
{
	$('msg_div').innerHTML = '';
	$('alert_div').className = 'alert_hide';	
}

function ViewForgot() {
	if($('alert_div')) $('alert_div').className = "alert_hide";
	if($('login_div')) $('login_div').style.display = 'none';
	if($('forgot_div')) $('forgot_div').style.display = '';
}

function ViewLogin() {
	if($('alert_div')) $('alert_div').className = "alert_hide";
	if($('login_div')) $('login_div').show();
	if($('forgot_div')) $('forgot_div').hide();
}
/**
 * this function validates for available user name in the database
 */
 
function checkAvailUserName(){
	var uname = $F('lusername');
	if(alltrim(uname) == '')
	{
		$('loginErr').innerHTML="Username is blank!";
		return false;
	}
	if(alltrim(uname.length) < 4)
	{
		$('loginErr').innerHTML="Username must contain atleast 4 characters!";
		return false;
	}
	
	var url = 'verify.php';
	var pars = 'userName=' + uname+"&mode=checkUname";
		
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'get',
		parameters: pars,
		onComplete:showMessage
	});
}

function showMessage(originalRequest) {
 
	response = originalRequest.responseText;
	if( response == 'invalid') {
		$('loginErr').innerHTML = "User name does not exist.";
		return false;
	}
	else{
		$('loginErr').innerHTML = "";
	}
}
/**
 * this function validates user login for database
 * 
 */
function userLogin(page)
{
	var url =  'verify.php';
	checkAvailUserName();
	if(alltrim($F('lpassword')) == '')
	{
		$('loginErr').innerHTML="Password is blank!";
		return false;
	}
	var pars = 'userName=' + $F('lusername') + '&userPass=' + $F('lpassword') + "&mode=login";
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'GET',
		parameters: pars,
		onComplete:showLogin_Response
	});


}

function showLogin_Response(originalRequest)
{
	response  = originalRequest.responseText;
	if(response.indexOf('yes') != -1) {
		window.location = 'myAccount.php';
	}
	else {
		
		$('loginErr').innerHTML = response;
		return false;
	}
}

