// JavaScript Document
function regularExp(o,pattern){
	var text = o.value;
	//var pattern = "";		
	var reg = new RegExp(pattern);
	if(reg.test(text)){
		return true;
	}
	return false;
}

function on_ads_click(id){
	window.open('http://www.secondhandtown.com/redirect.php?id='+id);
}

function on_login_click(){
	if(!checkForm()){
		clearForm();
	}else{
		//agent.call("handler.call.php","login","on_bSubmit_callback",$("#tLogin_left").val(),$("#tPassword_left").val());	
		var frm = document.getElementById("form1");
		frm.action = "http://www.secondhandtown.com/login.process.php";
		frm.submit();
	}
}

function on_bSubmit_callback(callback){
	if(callback){
		document.location.href = 'index.php';	
	}else{
		alert(callback);
	}
}

function onsearch_btn_submit(){
	var frm = document.getElementById("form1");
	frm.action = "http://www.secondhandtown.com/search.php";
	frm.submit();
}

function checkForm(){
	if($("#tLogin_left").val() != "" && $("#tPassword_left").val()){
		return true;
	}else{
		return false;
	}
}

function clearForm(){
	$("#tLogin_left").val("");
	$("#tPassword_left").val("");
}

function on_searchbar_click(){
	var selectgroup = $("#searbarselectorgroup").val();	
	var kw_forsearch = $("#searchbar_keyword").val();
	document.location.href = 'http://www.secondhandtown.com/search.php?key='+kw_forsearch+'&group='+selectgroup;
}

function on_logout_click(){
	document.location.href = 'http://www.secondhandtown.com/logout.php';
}

function createCustomHandler(){
	var tmp = null;
	if(window.XMLHttpRequest){
		tmp = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		tmp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return tmp;	
	
}
