var Utils = new Object();

Utils.trim = function( text )
{
  if (typeof(text) == "string")
  {
    return text.replace(/^\s*|\s*$/g, "");
  }
  else
  {
    return text;
  }
}



Utils.isNumber = function(val)
{
  var reg = /^[\d|\.|,]+$/;
  return reg.test(val);
}

Utils.isEmail = function( email )
{
  var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;

  return reg1.test( email );
}


var mydiv = document.getElementById('messages');

var handleSuccess = function(o){
	
	if(o.responseText !== undefined){
		if(window.ActiveXObject)
		{
			//********* IS IE
			
			mydiv.setAttribute("className",'no_load');
			
			}else{
			
			mydiv.setAttribute("class",'no_load');
			
		}
		var iweburl=document.getElementById("weburl");
		var igotopage=document.getElementById("gotopage");
		//alert("responsetest is "+o.responseText);
		if(o.responseText=='y')
		{
			mydiv.innerHTML = "<li>system alert:  you have successfully login the system</li>";
			//alert("your igotopage is"+igotopage.value);
			if(igotopage.value=="")
			{
				window.location.replace(iweburl.value);
				}else{
				window.location.replace(iweburl.value+"/"+igotopage.value);
				
			}
			
		}else{
			
			
			mydiv.innerHTML = "<li>system alert: your login info is wrong </li>";
			mydiv.style.display = 'block';
			document.login_form.idsubmit.disabled=false; 
		}
		
		
		
	}
};

var handleFailure = function(o){
		YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");

	if(o.responseText !== undefined){
		mydiv.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
		mydiv.innerHTML += "<li>HTTP status: " + o.status + "</li>";
		mydiv.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
		mydiv.style.display = 'block';
	}
	
	document.login_form.idsubmit.disabled="false"; 
	if(window.ActiveXObject)
		{
			//********* IS IE
			
			mydiv.setAttribute("className",'no_load');
			
			}else{
			
			mydiv.setAttribute("class",'no_load');
	
		}
};

var callback =
{
  success:handleSuccess,
  failure:handleFailure,
  argument:['foo','bar']
};


function mylogin()    
{
	var messages = document.getElementById('messages');
	
	var iemail=document.getElementById("email");
	
	var ipassword=document.getElementById("password");

	var iweburl=document.getElementById("weburl");
		
	
	if(iemail.value==""||Utils.isEmail(iemail.value)==false)
	{
		alert("Please enter email address");
		iemail.focus();
		return false;
	}

	
	
	if(ipassword.value=="")
	{
		alert("Please enter password ");
		ipassword.focus();
		return false;
	}
	

	var sUrl = iweburl.value+"/member.php?action=login";
	var postData = "email="+iemail.value+"&password="+ipassword.value;
	//alert("sUrl is "+sUrl);
	//alert("postData is "+postData);
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
	
	
	document.login_form.idsubmit.disabled="disabled"; 
	//document.login_form.action = sUrl;
	//document.login_form.target="blank_iframe"  
	
	mydiv.style.display = 'block';
	if(window.ActiveXObject)
	{
		//********* IS IE
			
		mydiv.setAttribute("className",'ajax_loading');
		
			
		}else{
		mydiv.setAttribute("class",'ajax_loading');
			

	}
	      

}
