var validator;

function getLeft(el) {
	var left = el.offsetLeft;
	return left + ((el.offsetParent.nodeName.toUpperCase() == "BODY") ? 0 : getLeft(el.offsetParent));
}

function getTop(el) {
	var top = el.offsetTop;
	return top + ((el.offsetParent.nodeName.toUpperCase() == "BODY") ? 0 : getTop(el.offsetParent));
}

function showLogin() {
	$import("net.sf.iafw.js.html.IElement");
	var loginPannel = IElement.getElement("login_panel");
	loginPannel.style.display = "";
}

function closeLogin() {
	$import("net.sf.iafw.js.html.IElement");
	var loginPannel = IElement.getElement("login_panel");
	loginPannel.style.display = "none";
}

function doLogin() {
	$import("net.sf.iafw.js.html.IElement");
	$import("net.sf.iafw.js.http.IRequest");
	var loginHttp = new IRequest("doLogin.asp?member_email=" + IElement.getText("member_email") + "&login_password=" + IElement.getText("login_password") + "&login_cookie=" + IElement.getText("login_cookie"), true, IRequest.GET, refreshLoginArea);
	loginHttp.response();
	closeLogin();
}

function refreshLoginArea(http) {
	if(http.responseText.match(/invalid/g)) {
		alert("your account has not been activated yet, please check your email and activate your account.");
	}else if(!IString.isEmpty(http.responseText)) {
		//IElement.setText("login_area", http.responseText);
		window.location.reload();
	} else {
		alert("Login error.Check your nickname or password,please.");
		showLogin();
	}
}

function doLoginKeyDown(evt){
	evt = window.event ? window.event : evt;
	if(evt.keyCode == 13) {
		doLogin();
	}
}

function doLogout() {
	window.location = "doLogin.asp?logout=true";
}

function submitDeal() {
	checkLoginAndGo("submit", "submit_a_deal.asp");
}

function submitTopic() {
	checkLoginAndGo("write topic", "forum_thread_new.asp");
}

function doValidate(field) {
	if(!validator) {
		$import("net.sf.iafw.js.html.IValidator");
		validator = new IValidator(field.form.name);
	}
	validator.validateField(field);
}

function doSubmit(form) {
	if(!validator) {
		$import("net.sf.iafw.js.html.IValidator");
		validator = new IValidator(form.name);
	}
	return validator.validateForm(form);
}

function confirmAndGo(msg, url) {
	if(confirm(msg)) {
		window.location = url;
	}
}

function promptAndGo(msg, url) {
	var vmsg = prompt(msg);
	if(vmsg) {
		window.location = url + "&comment=" + vmsg;
	}
}

function checkLoginAndGo(msg, url) {
	$import("net.sf.iafw.js.html.IElement");
	if(IElement.hasElement("login_panel")) {
		alert("Please login / register to " + msg + ".");
		window.location.hash = "login";
		showLogin();
	} else {
		window.location = url;
	}
}



 function doClear(theText) 
{
     if (theText.value == theText.defaultValue)
 {
         theText.value = ""
     }
 }

function menuChange(obj,menu)
{
	if(menu.style.display=="none")
	{
		
		menu.style.display="";
	}
	else
	{
		
		menu.style.display="none";
	}
}
function showcategory() {
	$import("net.sf.iafw.js.html.IElement");
	var loginPannel = IElement.getElement("category_list");
	loginPannel.style.display = "";
}
function closecategorylist() {
	$import("net.sf.iafw.js.html.IElement");
	var loginPannel = IElement.getElement("category_list");
	loginPannel.style.display = "none";
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function isEmail()
{
var strm = document.mail_alert.email.value   
var regm = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
if (!strm.match(regm) && strm!="")
   {
     alert("Wrong email!\n Please check your email!");
  document.mail_alert.email.select();   
  return false;
   }
 }
