// JavaScript Document

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("loginpanel");
	loginPannel.style.display = "";
}

function closeLogin() {
	$import("net.sf.iafw.js.html.IElement");
	var loginPannel = IElement.getElement("loginpanel");
	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) {
	$import("net.sf.iafw.js.html.IElement");
	$import("net.sf.iafw.js.http.IRequest");
	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("loginpanel")) {
		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 isEmail()
{
	$import("net.sf.iafw.js.html.IElement");
	
	var strm = IElement.getElement("email");
	strmValue = strm.value.replace(/ /g,"")
	var regm = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
	if ((!strmValue.match(regm) && strmValue!="") || strmValue=="")
 	{
		alert("Wrong email!\n Please check your email!");
		strm.select();   
		return false;
 	}
}

function isEmailSubmit()
{
var strm = document.mail_shop.email.value;  
var name = document.mail_shop.name.value; 
var addr = document.mail_shop.addr.value; 
var regm = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
if ((!strm.match(regm) && strm!="") || strm=="")
 {
	alert("Wrong email!\n Please check your email!");
	document.mail_shop.email.select();   
	return false;
 }
 if (name=="")
 {
	alert("Name is null!\n Please check your name!");
	document.mail_shop.name.select();   
	return false;
 }
 if (addr=="")
 {
	alert("Postal/Address is null!\n Please check your Postal/Address!");
	document.mail_shop.addr.select();   
	return false;
 }
}
function show(id)
{
	document.getElementById(id).style.display='block';
}
function hide(id)
{
	document.getElementById(id).style.display='none';
}

function toClip(ids)
{
	ids = document.getElementById(ids);
	ids.focus();
	ids.select();
	what = ids.createTextRange();
	what.execCommand("Copy");window.status = "Highlighted Content Copied To Clipboard!";
	setTimeout("window.status=''",5000);
}

function display()
{
	if(document.getElementById("mstore").style.display == "block")
	{
	document.getElementById("mstore").style.display = "none";
	}
	else
	{
	document.getElementById("mstore").style.display = "block";
	}
}

function onImgError(img, name) {
	var pNode = img.parentNode.parentNode;
	var a = img.parentNode.cloneNode(false);
	img.style.display = "none";
	var d = document.createElement("table");
	d.className = "stoname";
	d.cellPadding = "0";
	d.cellSpacing = "0";
	var td = d.insertRow(0).insertCell(0);
	td.vAlign = "middle";
	td.appendChild(a);
	td.height = "31";
	a.innerHTML = name;
	img.onerror = null;
	pNode.replaceChild(d, img.parentNode);
}

var tabId = 1;
function changDiv(id4)
{
	id4=parseInt(id4);
	for (i = 1; i <= 14; i++) 
	{
		if (i==id4)
		{
			document.getElementById('cthead0'+i).className='cur_use';
			document.getElementById('cas0'+i).style.display='block'
		}
		else
		{
			document.getElementById('cthead0'+i).className='';
			document.getElementById('cas0'+i).style.display='none'
		}
	}
	tabId = id4;
}

function initDiv(id) {
	nextDiv(id);
	if (id > 3 && id < 12) {
		document.getElementById('tab0' + (id + 2)).style.display='block';
		document.getElementById('tab0' + (id + 3)).style.display='block';
	}
}

function nextDiv(id4)
{
	id = tabId + id4;
	if (id > 3 && id < 12 && id4 > 0) {
		for(i = 1; i < id - 2; i++) {
			document.getElementById('tab0' + i).style.display='none';
		}
		document.getElementById('tab0' + id).style.display='block';
	}else if(id > 3 && id < 12 && id4 < 0) {
		for(i = 14; i > id + 2; i--) {
			document.getElementById('tab0' + i).style.display='none';
		}
		document.getElementById('tab0' + id).style.display='block';
	} else if (id <= 3) {
		for(i = 14; i > 3; i--) {
			document.getElementById('tab0' + i).style.display='none';
		}
		document.getElementById('tab01').style.display='block';
		document.getElementById('tab02').style.display='block';
		document.getElementById('tab03').style.display='block';
	} else if (id >= 12) {
		for(i = 1; i < 12; i++) {
			document.getElementById('tab0' + i).style.display='none';
		}
		document.getElementById('tab012').style.display='block';
		document.getElementById('tab013').style.display='block';
		document.getElementById('tab014').style.display='block';
	}
	if (id > 3) {
		document.getElementById('tableft').style.display='block';
	} else if (id <= 3){
		document.getElementById('tableft').style.display='none';
	}
	if (id >= 12) {
		document.getElementById('tabright').style.display='none';
	} else if (id < 12){
		document.getElementById('tabright').style.display='block';
	}
	for (i = 1; i <= 14; i++) 
	{
		if (i==id)
		{
			document.getElementById('cthead0'+i).className='cur_use';
			document.getElementById('cas0'+i).style.display='block';
		}
		else
		{
			document.getElementById('cthead0'+i).className='';
			document.getElementById('cas0'+i).style.display='none';
		}
	}
	tabId = id;
}

function MM_displayStatusMsg(msgStr) { //v1.0 dea of the day
  status=msgStr;
  document.MM_returnValue = true;
}

function resizeImg(img, size) {
	img.onload = null;
	if (img.width >= size && img.width >= img.height) {
		img.height = img.height / (img.width / size);
		img.width = size;
	}else if (img.height >= size && img.width <= img.height) {
		img.width = img.width / (img.height / size);
		img.height = size;
	}
}

function onPrint(){
	window.print(); 
}

function addFavorite(title,url) {  
if (window.sidebar) {   
window.sidebar.addPanel(title, url,"");   
} else if( document.all ) {  
window.external.AddFavorite( url, title);  
} else if( window.opera && window.print ) {  
return true;  
}  
}

function showHelp() { 
  $import("net.sf.iafw.js.html.IElement");
  IElement.getElement("showHelp").style.display = "block";
}
function hideHelp() { 
  $import("net.sf.iafw.js.html.IElement");
  IElement.getElement("showHelp").style.display = "none";
}
