function pop_err(fieldname,err_msg)
{
	fieldname.focus();
	alert(err_msg);
}

//set MD5 for password
function calculateValue() {
	var doc = document.frmLogin;
	var szPW = doc.password.value;
	szPW +=sharedValue;
	return calcValue(szPW);
}

function doLogin()
{
	var doc = document.frmLogin;
	if(doc.username.value == ""){
		pop_err(doc.username,"Please input Email address or Nickname!")
		return false;
	}
	if(doc.password.value == ""){
		pop_err(doc.password,"Please input password!")
		return false;
	}
	var szPW = calculateValue();
	doc.strpassword.value=szPW;
	doc.password.value="";
	doc.act.value = 1;
	return true;
}

function Checkinput()
{
	var doc = document.frmLogin;
	if(doc.username.value=="")
	{
		alert("Please input Email address or Nickname!");
		doc.username.focus();
		return false;
	}
	if(doc.password.value=="")
	{
		alert("Please input password!");
		doc.password.focus();
		return false;
	}
	var szPW = calculateValue();
	doc.strpassword.value=szPW;
	doc.curtime.value = sharedValue;
	doc.password.value="";
	doc.act.value = "login";
	return true;
}

function doRegister()
{
	var doc = document.frmRegister;
	var email = doc.email.value;
	var nickname = doc.nickname.value;
	
	if(email == ""){
		pop_err(doc.email,"Please input Email address!")
		return false;
	}else{ 
		if(!isemailaddress(email)){
			pop_err(doc.email,"Email address is invalid! Please input again!")
			return false;
		}
	}
	if(doc.firstname.value == ""){
		pop_err(doc.firstname,"Please input First Name!")
		return false;
	}else{
		if(!checkKeyword(doc.firstname)){
			return false;	
		}
	}
	if(doc.lastname.value != "" && !checkKeyword(doc.lastname)){
		return false;
	}
	if(doc.address.value != "" && !checkKeyword(doc.address)){
		return false;
	}
	if(doc.city.value != "" && !checkKeyword(doc.city)){
		return false;
	}
	if(doc.zipcode.value != "" && !checkKeyword(doc.zipcode)){
		return false;
	}
	if(doc.phone.value != "" && !checkKeyword(doc.phone)){
		return false;
	}
	if(doc.fax.value != "" && !checkKeyword(doc.fax)){
		return false;
	}
	if(doc.nickname.value == ""){
		pop_err(doc.nickname,"Please input Nick Name!")
		return false;
	}else{
		if(!checkKeyword(doc.nickname)){
			return false;	
		}
		if(!isUsername(nickname)){
			pop_err(doc.nickname,"Nick name can not contain space! Please input again!")
			return false;
		}
	}
	if(typeof(doc.password) == "object" && typeof(doc.confirm_password) == "object"){
		var password = doc.password.value;
		var confirm_password = doc.confirm_password.value;
		if(doc.password.value == ""){
			pop_err(doc.password,"Please input password!")
			return false;
		}else{
			if(!checkKeyword(doc.password)){
				return false;	
			}
			if(password != confirm_password){
				pop_err(doc.confirm_password,"Password and confirm password are different!")
				return false;
			}
		}
	}
	if(doc.security_code.value == ""){
		pop_err(doc.security_code,"Please enter the characters in the image!")
		return false;
	}
	doc.act.value = 2;
	return true;
}

function doShopDetail()
{
	var doc = document.frmRegister;
	if(doc.shopname.value == ""){
		pop_err(doc.shopname,"Please input Shop Name!")
		return false;
	}else{
		if(!checkKeyword(doc.shopname)){
			return false;	
		}
	}

	if(doc.tagline.value != "" && !checkKeyword(doc.tagline)){
		return false;
	}
	
	if(doc.shop_intro.value != "" && !checkKeyword(doc.shop_intro)){
		return false;
	}
	
	if(doc.about.value == ""){
		pop_err(doc.about,"Please input About You and Your Shop !")
		return false;
	}else{
		if(!checkKeyword(doc.about)){
			return false;	
		}
	}
	
	if(doc.contactname.value == ""){
		pop_err(doc.contactname,"Please input Contact Name!")
		return false;
	}else{
		if(!checkKeyword(doc.contactname)){
			return false;	
		}
	}
	
	if(doc.email.value == ""){
		pop_err(doc.email,"Please input Email address!")
		return false;
	}else{ 
		if(!isemailaddress(doc.email.value)){
			pop_err(doc.email,"Email address is invalid! Please input again!")
			return false;
		}
	}
	
	if(doc.address.value == ""){
		pop_err(doc.address,"Please input Address!")
		return false;
	}else{
		if(!checkKeyword(doc.address)){
			return false;	
		}
	}
	
	if(doc.city.value == ""){
		pop_err(doc.city,"Please input City!")
		return false;
	}
	
	if(doc.state.value == ""){
		pop_err(doc.state,"Please select State!")
		return false;
	}	
	
	if(doc.country.value == ""){
		pop_err(doc.country,"Please select Country!")
		return false;
	}
	
	if(doc.phone.value == ""){
		pop_err(doc.phone,"Please input Phone!")
		return false;
	}else{
		if(!checkKeyword(doc.phone)){
			return false;	
		}
	}
	if(doc.zipcode.value != "" && !checkKeyword(doc.zipcode)){
		return false;
	}
	if(doc.fax.value != "" && !checkKeyword(doc.fax)){
		return false;
	}
	if(doc.logopath.value != "" && !checkKeyword(doc.logopath)){
		return false;
	}
	// Check method of Payment
	var check_payonline = 0;
	var check_payoffline = 0;
	for(var i=0; i<doc.length;i++){
		if(doc.elements[i].type=="radio" && doc.elements[i].name == "payment" && doc.elements[i].checked == true){
			check_radio = 1;
			i = doc.length;
		}
	}
	for(var i=0; i<doc.length;i++){
		if(doc.elements[i].type=="checkbox" && doc.elements[i].name == "payment_offline" && doc.elements[i].checked == true){
			check_payoffline = 1;
			i = doc.length;
		}
	}
	if(check_payonline == 0 && check_payoffline == 0){
		alert("Please select Payment Method!");
		return false;
	}
	if(doc.ship_handle.value == ""){
		pop_err(doc.ship_handle,"Please input Shipping and Handling Policy!")
		return false;
	}else{
		if(!checkKeyword(doc.ship_handle)){
			return false;	
		}
	}
	if(doc.otherinfo.value != "" && !checkKeyword(doc.otherinfo)){
		return false;
	}
	if(typeof(doc.chkaccept) == "object" && doc.chkaccept.checked == false){
		pop_err(doc.chkaccept,"Please check the 'I ACCEPT' box!")
		return false;
	}
	
	doc.act.value = 2;
	return true;
}

function doChangePW()
{
	var doc = document.frmRegister;
	var password = doc.password.value;
	var confirm_password = doc.confirm_password.value;
	if(doc.password.value == ""){
		pop_err(doc.password,"Please input password!")
		return false;
	}else{
		if(!checkKeyword(doc.password)){
			return false;	
		}
		if(password != confirm_password){
			pop_err(doc.confirm_password,"Password and confirm password are different!")
			return false;
		}
	}

	doc.act.value = 2;
	return true;
}

function docheckItem(){
	var doc = document.frmItem;
	
	if(doc.itemcode.value == ""){
		pop_err(doc.itemcode,"Please input Item ID!")
		return false;
	}else{
		if(!checkKeyword(doc.itemcode)){
			return false;	
		}
	}
	
	if(doc.itemname.value == ""){
		pop_err(doc.itemname,"Please input Title!")
		return false;
	}else{
		if(!checkKeyword(doc.itemname)){
			return false;	
		}
	}
	
	if(doc.itemdescription.value == ""){
		pop_err(doc.itemdescription,"Please input Description!")
		return false;
	}else{
		if(!checkKeyword(doc.itemdescription)){
			return false;	
		}
	}
	
	if(doc.itemqty.value == ""){
		pop_err(doc.itemqty,"Please input Quantity!")
		return false;
	}else{
		if(!isInteger(doc.itemqty.value)){
			pop_err(doc.itemqty,"Quantity is invalid! Please input again!")
			return false;
		}
	}
	
	if(doc.currentprice.value == ""){
		pop_err(doc.currentprice,"Please input Current Price!")
		return false;
	}else{
		if(!isnumeric(doc.currentprice.value)){
			pop_err(doc.currentprice,"Current price is invalid! Please input again!")
			return false;
		}
	}
	
	if(doc.displayprice.value == "OR"){
		if(doc.realprice.value == ""){
			pop_err(doc.realprice,"Please input Original Price!")
			return false;
		}else{
			if(!isnumeric(doc.realprice.value)){
				pop_err(doc.realprice,"Original price is invalid! Please input again!")
				return false;
			}
		}
	}
	
	if(doc.systemcate.value == ""){
		pop_err(doc.systemcate,"Please select Category for item!")
		return false;
	}
	if(doc.shopcate.value != "" && !checkKeyword(doc.shopcate)){
		return false;
	}
	doc.act.value = 2;
	return true;
}

function docheckOffer(){
	var doc = document.frmOffer;
	
	if(doc.uemail.value == ""){
		pop_err(doc.uemail,"Please input Email!");
		return false;
	}else{
		if(!isemailaddress(doc.uemail.value)){
			pop_err(doc.uemail,"Email address is invalid! Please input again!");
			return false;
		}
	}
	
	if(doc.offerprice.value == ""){
		pop_err(doc.offerprice,"Please input Offer Price!");
		return false;
	}else{
		var offerprice = doc.offerprice.value;
		if(!isnumeric(offerprice)){
			pop_err(doc.offerprice,"Offer Price is invalid! Please input again!");
			return false;
		}
		/*
		var begin_offer = doc.begin_offer.value;
		var end_offer = doc.end_offer.value;
		if(offerprice < begin_offer || offerprice > end_offer){
			pop_err(doc.offerprice,"Offer Price must between " + begin_offer + " and " + end_offer + "!");
			return false;
		}
		*/
	}
	
	var check_payment = 0;
	for(var i=0; i<doc.length;i++){
		if(doc.elements[i].type=="radio" && doc.elements[i].name == "payment" && doc.elements[i].checked == true){
			check_payment = 1;
			i = doc.length;
		}
	}
	
	if(check_payment == 0){
		pop_err(doc.addinfo,"Please select Payment Method!")
		return false;
	}
	
	doc.act.value = 2;
	return true;
}

function upload_images()
{
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false

	winW = (ns4)? window.innerWidth-16 : document.body.offsetWidth-20
	winH = (ns4)? window.innerHeight : document.body.offsetHeight

	winTop = 95;
	winLeft = 115;
	szpage = "show_form_upload.asp?itemid=" + document.frmItem.itemcode.value;
	//alert(szpage);
	sPro = "WIDTH=530,HEIGHT=162,scrollbars=no,resize=no,menubar=no,resizable=no,left=" + winLeft + ",top=" + winTop
	window.open(szpage,"uploadfile",sPro,true)
}

function upload_logo_profile()
{
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false

	winW = (ns4)? window.innerWidth-16 : document.body.offsetWidth-20
	winH = (ns4)? window.innerHeight : document.body.offsetHeight

	winTop = 95;
	winLeft = 115;
	szpage = "upload_logo_shop.asp";
	sPro = "WIDTH=530,HEIGHT=103,scrollbars=no,resize=no,menubar=no,resizable=no,left=" + winLeft + ",top=" + winTop
	window.open(szpage,"uploadfile",sPro,true)
}
function chkfile_upload(){
	var doc = document.frm;
	var input_file = 0;
	for(var i=0; i<doc.length;i++){
		if(doc.elements[i].type=="file"){
			if(doc.elements[i].value != ""){
				input_file = 1;
				szfile = doc.elements[i].value;	
				var szlen = szfile.length;
				var szfirstlen = szlen - 3;
				var strend = trim(szfile.substr(szfirstlen,szlen));
				if(strend.toLowerCase() != 'gif' && strend.toLowerCase() != 'jpg'){
					pop_err(doc.elements[i],"File upload is invalid. Please upload gif or jpg!");
					return false;
				}
			}
		}
	}
	if(input_file == 0){
		alert("Please Browse to select file for upload!");
		return false;
	}
	return true;
}

function doSubmit(value){
	var doc = document.frmCart;
	var checkitem = 0;
	if(value == 1){
		for(var i=0; i<doc.length; i++){
			if(doc.elements[i].name=="chkpid" && doc.elements[i].type=="checkbox" && doc.elements[i].checked == true){
				checkitem = 1;
				i = doc.length;
			}
		}
		if(checkitem == 0){
			alert("Please select items to check out");
			return false;
		}
	}else{
		for(var i=0; i<doc.length; i++){
			if(doc.elements[i].name=="chkpid" && doc.elements[i].type=="checkbox"){
				doc.elements[i].checked = true;
			}
		}
	}
	
	document.frmCart.act.value = 2;
	document.frmCart.action = 'process_checkout.asp';
	document.frmCart.submit();
}

function doDeleteItem(){
	var doc = document.frmCart;
	var checkitem = 0;
	for(var i=0; i<doc.length; i++){
		if(doc.elements[i].name=="chkpid" && doc.elements[i].type=="checkbox" && doc.elements[i].checked == true){
			checkitem = 1;
			i = doc.length;
		}
	}
	if(checkitem == 0){
		alert("Please select items to delete!");
		return false;
	}
	doc.act.value = 2;
	doc.action = "view_shopping_bag.asp";
	doc.submit();
}

function doDeleteBag(value){
	var doc = document.frmCheckOut;
	doc.act.value = 2;
	doc.shopcheckout.value = value;
	doc.action = "process_checkout.asp";
	doc.submit();
}

function doCheckoutDetail(value){
	var doc = document.frmCheckOut;
	doc.act.value = 2;
	doc.shopcheckout.value = value;
	doc.action = "checkout_detail.asp";
	doc.submit();
}

function doAdvanceSearch(value){
	var doc = document.frmAdvanceSearch;
	doc.act.value = value;
	doc.display_type.value = "result";
	doc.action = "advance_search.asp";
	doc.submit();
}

function docheckOrder(){
	var doc = document.frmOrder;
	
	if(doc.uemail.value == ""){
		pop_err(doc.uemail,"Please input Email!")
		return false;
	}else{
		if(!isemailaddress(doc.uemail.value)){
			pop_err(doc.uemail,"Email address is invalid! Please input again!")
			return false;
		}
	}
	
	var check_payment = 0;
	for(var i=0; i<doc.length;i++){
		if(doc.elements[i].type=="radio" && doc.elements[i].name == "payment" && doc.elements[i].checked == true){
			check_payment = 1;
			i = doc.length;
		}
	}
	
	if(check_payment == 0){
		pop_err(doc.addinfo,"Please select Payment Method!")
		return false;
	}
	
	doc.act.value = 2;
	return true;
}

function doFavorite(type, id){
	if(type == 0){
		window.external.AddFavorite(location.href, document.title);
	}else{
		var doc = document.formShopTool;
		doc.pageadd_favorite.value = location.href;
		doc.favorite_item.value = id;
		doc.favorite_type.value = type;
		doc.action = "addto_favorite.asp";
		doc.submit();
	}
}

function doDeleteBag(value){
	var doc = document.frmCheckOut;
	doc.act.value = 2;
	doc.shopcheckout.value = value;
	doc.action = "process_checkout.asp";
	doc.submit();
}

function doMakeOffer(type, id){
	var doc = document.frmOffer;
	doc.act.value = type;
	doc.offerid.value = id;
	if(type == 1){
		doc.action = "shop_makeoffer_accept.asp";
	}else if(type == 2){
			doc.action = "shop_makeoffer_reject.asp";
	}else if(type == 3){
			doc.action = "shop_makeoffer_response.asp";
	}
	doc.submit();
}

function handleMakeOffer(type){
	var doc = document.frmOffer;
	doc.act.value = type;
	if(doc.txt_response.value == ""){
		pop_err(doc.txt_response,"Please input your response!")
		return false;
	}else{
		if(doc.txt_response.value.length > 2000){
			pop_err(doc.txt_response,"Please input your response < 2000 characters!")
			return false;
		}
	}
	return true;
}

function doPurchase(type, id){
	var doc = document.frmPurchase;
	doc.act.value = type;
	doc.orderid.value = id;
	if(type == 1)
		doc.action = "shop_purchase_response.asp";
	if(type == 2)
		doc.action = "shop_purchase_finalize.asp";
	doc.submit();
}

function handlePurchase(type){
	var doc = document.frmPurchase;
	doc.act.value = type;
	if(doc.txt_response.value == ""){
		pop_err(doc.txt_response,"Please input your response!")
		return false;
	}else{
		if(doc.txt_response.value.length > 2000){
			pop_err(doc.txt_response,"Please input your response < 2000 characters!")
			return false;
		}
	}
	return true;
}

function doDeleteFavorite(type){
	var doc = document.frmFavorite;
	if(type == 1){
		var check_shop = 0;
		for(var i=0; i<doc.length;i++){
			if(doc.elements[i].type=="checkbox" && doc.elements[i].name == "chkid" && doc.elements[i].checked == true){
				check_shop = 1;
				i = doc.length;
			}
		}
		if(check_shop == 0){
			alert("Please select items to delete!");
			return false;
		}
	}
	if(type == 2){
		for(var i=0; i<doc.length; i++){
			if(doc.elements[i].name=="chkid" && doc.elements[i].type=="checkbox"){
				doc.elements[i].checked = true;
			}
		}
	}	
	
	doc.act.value = 2;
	doc.action = "favorite_shop.asp";
	doc.submit();
}

function doDeleteWishList(type){
	var doc = document.frmWishList;
	if(type == 1){
		var check_shop = 0;
		for(var i=0; i<doc.length;i++){
			if(doc.elements[i].type=="checkbox" && doc.elements[i].name == "chkpid" && doc.elements[i].checked == true){
				check_shop = 1;
				i = doc.length;
			}
		}
		if(check_shop == 0){
			alert("Please select items to delete!");
			return false;
		}
	}
	if(type == 2){
		for(var i=0; i<doc.length; i++){
			if(doc.elements[i].name=="chkpid" && doc.elements[i].type=="checkbox"){
				doc.elements[i].checked = true;
			}
		}
	}	
	
	doc.act.value = 2;
	doc.action = "wishlist.asp";
	doc.submit();
}

function FindAssistant(value){
	var doc = document.frmFindAssistant;
	doc.act.value = value;
	doc.action = "find_assistant_result.asp";
	doc.submit();
}

function doModifyItem(){
	var doc = document.frmItem;
	doc.act.value = 2;
	doc.submit();
}

function doRemoveItem(){
	var doc = document.frmItem;
	doc.act.value = 2;
	doc.submit();
}

function doManageItem(type){
	var doc = document.frmItem;
	doc.act.value = type;
	doc.submit();
}

function doAddLink(){
	var doc = document.frmLink;
	if(doc.sitename.value == ""){
		pop_err(doc.sitename,"Please input name of site!")
		return false;
	}
	
	if(doc.siteurl.value == ""){
		pop_err(doc.siteurl,"Please input URL of site!")
		return false;
	}else{
		if(!check_url(doc.siteurl.value)){
			pop_err(doc.siteurl,"URL is invalid! Please input again!")
			return false;
		}
	}
	doc.act.value = 2;
	doc.submit();
}

function deleteLink(type){
	var doc = document.frmLink;
	if(type == 1){
		var check_link = 0;
		for(var i=0; i<doc.length;i++){
			if(doc.elements[i].type=="checkbox" && doc.elements[i].name == "chklink" && doc.elements[i].checked == true){
				check_link = 1;
				i = doc.length;
			}
		}
		if(check_link == 0){
			alert("Please select items to delete!");
			return false;
		}
	}
	if(type == 2){
		for(var i=0; i<doc.length; i++){
			if(doc.elements[i].name=="chklink" && doc.elements[i].type=="checkbox"){
				doc.elements[i].checked = true;
			}
		}
	}	
	doc.act.value = 2;
	doc.action = "shop_favorites.asp";
	doc.submit();
}

function editLink(type){
	var doc = document.frmLink;
	if(type == 1){
		var check_link = 0;
		for(var i=0; i<doc.length;i++){
			if(doc.elements[i].type=="checkbox" && doc.elements[i].name == "chklink" && doc.elements[i].checked == true){
				check_link = check_link + 1;
			}
		}
		if(check_link > 1){
			alert("Please select only one item to edit!");
			return false;
		}
		
		if(check_link == 0){
			alert("Please select item to edit!");
			return false;
		}
		doc.action = "shop_edit_favorites.asp";
	}else{
		doc.act.value = 2;
		doc.action = "shop_edit_favorites.asp";
	}
	doc.submit();
}

function doTellFriend(type){
	doc = document.frmTellFriend;
	var inputmail = 0;
	if(doc.uemail.value == ""){
		pop_err(doc.uemail,"Please input your email address!")
		return false;
	}else{
		if(!isemailaddress(doc.uemail.value)){
			pop_err(doc.uemail,"Email address is invalid! Please input again!")
			return false;
		}	
	}
	if(doc.email1.value != ""){
		inputmail = 1;	
		if(!isemailaddress(doc.email1.value)){
			pop_err(doc.email1,"Email address is invalid! Please input again!")
			return false;
		}	
	}
	if(doc.email2.value != ""){
		inputmail = 1;		
		if(!isemailaddress(doc.email2.value)){
			pop_err(doc.email2,"Email address is invalid! Please input again!")
			return false;
		}	
	}
	if(doc.email3.value != ""){
		inputmail = 1;		
		if(!isemailaddress(doc.email3.value)){
			pop_err(doc.email3,"Email address is invalid! Please input again!")
			return false;
		}	
	}
	if(inputmail == 0){
		pop_err(doc.email1,"Please input email address of your friend!")
		return false;
	}
	if(doc.bodymail.value == ""){
		pop_err(doc.bodymail,"Please input content of email!")
		return false;
	}
	if(type == 1){
		doc.action = "tell_your_friend.asp";	
	}else{
		doc.action = "tell_your_friend_shop.asp";	
	}
	doc.act.value = 2;
	doc.submit();
}

function doAuction(type){
	doc = document.frmAuction;
	if(type < 3){
		var inputid = 0;
		if(doc.itemid.value != ""){
			inputid = 1;
		}
		
		if(doc.slitemid.value != ""){
			inputid = 1;
		}
		
		if(inputid == 0){
			pop_err(doc.itemid,"Please input Item ID!")
			return false;
		}
	}
	
	if(type == 1){
		doc.action = "shop_preview_auction.asp";	
	}
	if(type == 2){
		doc.action = "shop_send_auction.asp";	
	}
	if(type == 3){
		window.open("http://cgi5.ebay.com/ws1/eBayISAPI.dll?SellYourItem","","scrollbars=yes,resizeable=yes,left=100");
		doc.action = "shop_send_auction.asp";	
	}
	doc.act.value = 2;
	if(type == 4){
		if(doc.returnURL.value == ""){
			pop_err(doc.returnURL,"Please input Auction's URL!")
			return false;
		}
		doc.action = "shop_send_auction.asp";	
		doc.act.value = 1;	
	}
	doc.submit();
}

function doFeatured(){
	doc = document.frmFeatured;
	doc.act.value = 2;	
	doc.submit();
}

function doCheckItemBR(){
	var doc = document.frmBackRoom;
	var num_check = 0;
	var i = 0;
	for(i= 0; i < doc.length; i++){
		if(doc.elements[i].name == "itemid" && doc.elements[i].checked == true)
			num_check = num_check + 1;
	}
	if(num_check <= 1){
		doc.modify.disabled = false;
		doc.sendauction.disabled = false;
	}else{
		doc.modify.disabled = true;
		doc.sendauction.disabled = true;
	}
}

function doBackRoom(type){
	var doc = document.frmBackRoom;
	if(type == 1){
		doc.action = "shop_modify_item.asp";	
	}
	if(type == 2){
		doc.action = "shop_backroom_item.asp";	
	}
	if(type == 3){
		doc.action = "shop_item_auction.asp";	
	}
	doc.act.value = 2;
	doc.submit();
}

function checkUniqueShop(type){
	var doc = document.frmRegister;
	var shopname = doc.shopname.value;
	if(type == 1){
		var pagename = "checkUniqueShop.asp?shopname=" + shopname;
		window.open(pagename,"","scrollbars=no,resizeable=yes,menubar=no,status=no,Maximize=no,toolbar=no,left=220,width=400,height=125");
	}
	if(type == 2){
		if(shopname == ""){
			pop_err(doc.shopname,"Please input Shop name!")
			return false;
		}
		doc.act.value = 2;
		doc.action = "checkUniqueShop.asp";
		doc.submit();
	}
	if(type == 3){
		window.opener.document.frmRegister.shopname.value = shopname;
	}
	return true;
}

function popup(type){
	var pagename = "";
	if(type == 1){
		pagename = "whatanickname.asp";
		window.open(pagename,"","scrollbars=no,resizeable=yes,menubar=no,status=no,Maximize=no,toolbar=no,left=300,width=400,height=315");
	}
	if(type == 2){
		pagename = "forgotPassword.asp";
		window.open(pagename,"","scrollbars=no,resizeable=yes,menubar=no,status=no,Maximize=no,toolbar=no,left=220,width=400,height=125");	
	}
}

function forgotPassword(){
	var doc = document.frmPassword;
	var email = doc.email.value;
	if(email == ""){
		pop_err(doc.email,"Please input Email address!")
		return false;
	}else{ 
		if(!isemailaddress(email)){
			pop_err(doc.email,"Email address is invalid! Please input again!")
			return false;
		}
	}
	doc.act.value = 2;
	doc.submit();
}

/*Admin Function*/
function LoadSettingDefault(type)
{
	document.getElementById("tblSetting").style.display = "block";
	document.getElementById("tblClient").style.display = "none";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("tblCategory").style.display = "block";
	document.getElementById("menu_setting").style.color = "#FF0000";
	if(type == 1)
		document.getElementById("tblAddCat").style.display = "block";
}
function LoadForFeeSetting()
{
	document.getElementById("tblSetting").style.display = "block";
	document.getElementById("tblClient").style.display = "none";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("tblFeeSetting").style.display = "block";
	document.getElementById("menu_setting").style.color = "#FF0000";
}
function LoadForAdminAssistant(type)
{
	document.getElementById("tblSetting").style.display = "block";
	document.getElementById("tblClient").style.display = "none";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("tblAssistant").style.display = "block";
	document.getElementById("menu_setting").style.color = "#FF0000";
	if(type == 1)
		document.getElementById("tblAddAssistant").style.display = "block";
}
function LoadForDataConfig()
{
	document.getElementById("tblSetting").style.display = "block";
	document.getElementById("tblClient").style.display = "none";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("tblDataConfig").style.display = "block";
	document.getElementById("menu_setting").style.color = "#FF0000";
}
function LoadForEmailNotify()
{
	document.getElementById("tblSetting").style.display = "block";
	document.getElementById("tblClient").style.display = "none";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("tblEmailNotify").style.display = "block";
	document.getElementById("menu_setting").style.color = "#FF0000";	
}
function LoadForAdminInformation(type)
{
	document.getElementById("tblSetting").style.display = "block";
	document.getElementById("tblClient").style.display = "none";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("tblInformation").style.display = "block";
	document.getElementById("menu_setting").style.color = "#FF0000";
	if(type == 1)
		document.getElementById("tblEditInformation").style.display = "block";
}
function adminclient()
{
	window.location.replace("admin_client.asp");
}
function LoadClientDefault(type)
{
	document.getElementById("tblSetting").style.display = "none";
	document.getElementById("tblClient").style.display = "block";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("menu_client").style.color = "#FF0000";
	if(type == 0)
		document.getElementById("tblListClient").style.display = "block";
	else
		document.getElementById("tblEditClient").style.display = "block";
}
function LoadSearchClient(type)
{
	document.getElementById("tblSetting").style.display = "none";
	document.getElementById("tblClient").style.display = "block";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("menu_client").style.color = "#FF0000";
	if(type > 0){
		document.getElementById("tblSearchClient").style.display = "block";
		if(type > 2)
			document.getElementById("tblListSearchClient").style.display = "block";
	}else{
		document.getElementById("tblEditClient").style.display = "block";
	}
}

function LoadFeatureDefault()
{
	document.getElementById("tblSetting").style.display = "none";
	document.getElementById("tblClient").style.display = "block";
	document.getElementById("tblReport").style.display = "none";
	document.getElementById("menu_client").style.color = "#FF0000";
}

function adminreport()
{
	window.location.replace("admin_report.asp");
}
function LoadReportDefault()
{
	document.getElementById("tblReport").style.display = "block";
	document.getElementById("tblReportClient").style.display = "block";
	document.getElementById("menu_report").style.color = "#FF0000";
}
function LoadProfileDefault(){
	document.getElementById("menu_profile").style.color = "#FF0000";
}
function LoadReportDetailDefault(){
	document.getElementById("tblReport").style.display = "block";
	document.getElementById("menu_report").style.color = "#FF0000";
}
function LoadCategory()
{
	window.location.replace("admin_category.asp");	
}
function LoadFeeSetup()
{
	window.location.replace("admin_fee_setup.asp");	
}
function LoadAdminAssistant()
{
	window.location.replace("admin_assistant.asp");
}
function LoadDataConfig()
{
	window.location.replace("admin_data_config.asp");	
}
function LoadEmailNotify()
{
	window.location.replace("admin_email_notify.asp");	
}
function saveEmail(){
	var doc = document.frm;
	if(trim(doc.email_title.value) == "") {
		pop_err(doc.email_title,"Please input email title!")
		return false;
	}else if(!checkKeyword(doc.email_title)){
		return false;
	}
	if(doc.content_to_user.value != "" && !checkKeyword(doc.content_to_user)){
		return false;
	}
	if(doc.content_to_admin.value != "" && !checkKeyword(doc.content_to_admin)){
		return false;
	}
	doc.act.value = "update";
	return true;
}
function LoadInformation()
{
	window.location.replace("admin_information.asp");	
}

function checkCategory(){
	var doc = document.frm;
	var categoryname = doc.categoryname;
	if(trim(categoryname.value) == "") {
		pop_err(categoryname,"Please input category name!")
		return false;
	}else if(!checkKeyword(categoryname)){
		return false;
	}
	return true;
}
function addnewCategory(){
	document.getElementById("tblAddCat").style.display = "block";
	document.frm.id.value = "";
	document.frm.act.value = 1;
	document.frm.categoryid.disabled = false;
	document.frm.categoryid.value = 0;
	document.frm.categoryname.value = "";
	document.frm.btnOK.value = " Save ";
}
function editCategory(id, name, subid){
	var doc = document.frm;
	document.getElementById("tblAddCat").style.display = "block";
	doc.id.value = id;
	doc.act.value = 2;
	doc.categoryid.value = subid;
	if(subid == 0)
		doc.categoryid.disabled = true;
	else
		doc.categoryid.disabled = false;
	doc.categoryname.value = name.replace("|","'");
	doc.btnOK.value = " Update ";
}
function deleteCategory(id){
	if(!confirm("Do you want to delete selected item(s)?")){
		
	}else{
		if(id > 0){
			window.location.replace("admin_category.asp?act=3&id="+id);
		}else{
			document.frm.act.value = 5;
			document.frm.submit();
		}
	}
}
function activeCategory(id){
	window.location.replace("admin_category.asp?act=4&id="+id);
}
function doCheck(type){
	var doc = document.frm;
	var num_check = 0;
	var total_checkbox = 0;
	var i = 0;
	if(type == 1){
		if(doc.chkall.checked == true){
			for(i= 0; i < doc.length; i++){
				if(doc.elements[i].name == "chkitem")
					doc.elements[i].checked = true;
			}
			num_check = i;
		}else{
			for(i= 0; i < doc.length; i++){
				if(doc.elements[i].name == "chkitem")
					doc.elements[i].checked = false;
			}
			num_check = 0;
		}
	}
	if(type == 2 || type == 3){
		for(i= 0; i < doc.length; i++){
			if(doc.elements[i].name == "chkitem"){
				if(doc.elements[i].checked == true)
					num_check = num_check + 1;
				total_checkbox = total_checkbox + 1;
			}
		}
		if(typeof(doc.chkall) == "object"){
			if(num_check == total_checkbox)
				doc.chkall.checked = true;
			else
				doc.chkall.checked = false;
		}
		if(typeof(doc.btnUpdate) == "object"){
			if(type == 3){
				if(num_check == 0)
					doc.btnUpdate.disabled = true;
				else
					doc.btnUpdate.disabled = false;
			}else{
				if(num_check == 1)
					doc.btnUpdate.disabled = false;
				else
					doc.btnUpdate.disabled = true;
			}
		}
	}
	
	if(typeof(doc.btnDelete) == "object"){
		if(num_check == 0){
			doc.btnDelete.disabled = true;
		}else{
			doc.btnDelete.disabled = false;
		}	
	}
}
function checkDataConfig(){
	var doc = document.frm;
	doc.act.value = 1;
	doc.submit();
} 
function checkAssistant(type){
	var doc = document.frm;
	var nickname = doc.nickname;
	var password = doc.password;
	var confirm_password = doc.confirm_password;
	var firstname = doc.firstname;
	var lastname = doc.lastname;
	var email = doc.email;
	if(trim(nickname.value) == ""){
		pop_err(nickname,"Please input nick name!")
		return false;
	}else if(!checkKeyword(nickname)){
		return false;
	}
	if(trim(password.value) == ""){
		pop_err(password,"Please input password!")
		return false;
	}else{
		if(!checkKeyword(password)){
			return false;
		}
		if(password.value != confirm_password.value){
			pop_err(confirm_password,"Password and confirm_passwod do not match!")
			return false;
		}
	}
	if(trim(firstname.value) == ""){
		pop_err(firstname,"Please input first name!")
		return false;
	}else if(!checkKeyword(firstname)){
		return false;
	}
	if(trim(lastname.value) == ""){
		pop_err(lastname,"Please input last name!")
		return false;
	}else if(!checkKeyword(lastname)){
		return false;
	}
	if(trim(email.value) == ""){
		pop_err(email,"Please input email!")
		return false;
	}else{
		if(!isemailaddress(email.value)){
			pop_err(email,"Email address is invalid! Please input again!")
			return false;
		}
	}
	doc.act.value = type;
	return true;
}
function addnewAssistant(){
	var doc = document.frm;
	doc.id.value = "0";
	doc.act.value = "";
	doc.btnOK.value = " Save ";
	doc.submit();
}
function editAssistant(id){
	document.frm.id.value = id;
	document.frm.act.value = "";
	document.frm.btnOK.value = " Update ";
	document.frm.submit();
}
function deleteAssistant(id){
	if(!confirm("Do you want to delete selected item(s)?")){
		
	}else{
		if(id > 0){
			window.location.replace("admin_assistant.asp?act=3&id="+id);
		}else{
			document.frm.act.value = 5;
			document.frm.submit();
		}
	}
}
function editInformation(id){
	document.frm.id.value = id;
	document.frm.act.value = "";
	document.frm.submit();
}
function saveInformation(){
	var doc = document.frm;
	var content = doc.FCKeditor1.value;
	if(content.toLowerCase().indexOf("<script") != -1 || content.toLowerCase().indexOf("</script") != -1
		|| content.toLowerCase().indexOf("&lt;script") != -1 || content.toLowerCase().indexOf("&lt;/script") != -1){
		alert("You can not input keyword '<script>' or '</script>'. Please input again!")
		return false;
	}
	doc.act.value = "update";
	return true;
}
function editClient(id)
{
	document.frm.id.value = id;
	document.frm.act.value = "";
	document.frm.submit();
}
function editSearchClient(id)
{
	document.frm.id.value = id;
	document.frm.act.value = 0;
	document.frm.submit();
}
function docancelupdate(type)
{
	if(type == 1)		
		window.location.replace("admin_client.asp");
	else
		window.location.replace("admin_search_client.asp?act=4");
}
function updateClient(){
	var doc = document.frm;
	var password = doc.password;
	var confirm_password = doc.confirm_password;
	var shopname = doc.shopname;
	var contactname = doc.contactname;
	var activedate = doc.activedate;
	var paymentamount = doc.paymentamount;
	var receivedate = doc.receivedate;
	if(password.value == ""){
		pop_err(password,"Please input password!")
		return false;
	}else{
		if(!checkKeyword(password)){
			return false;
		}
		if(password.value != confirm_password.value){
			pop_err(confirm_password,"Password and confirm password are different!")
			return false;
		}
	}
	if(shopname.value == ""){
		pop_err(shopname,"Please input shop name!")
		return false;
	}else if(!checkKeyword(shopname)){
		return false;
	}
	if(contactname.value == ""){
		pop_err(contactname,"Please input contact name!")
		return false;
	}else if(!checkKeyword(contactname)){
		return false;
	}
	if(doc.active[0].checked == true){
		if(activedate.value == ""){
			pop_err(activedate,"Please input active date!")
			return false;
		}else{
			if(!isDate(activedate.value)){
				pop_err(activedate,"Active date is invalid. Please input with format mm/dd/yyyy!");
				return false;
			}
		}
	}	
	if(paymentamount.value != "" && !isnumeric(paymentamount.value)){
		pop_err(paymentamount,"Payment amount is invalid! Please input numeric format!")
		return false;
	}
	
	if(receivedate.value != "" && !isDate(receivedate.value)){
		pop_err(receivedate,"Receive date is invalid. Please input with format mm/dd/yyyy!");
		return false;
	}
	
	if(doc.statuscomment.value != "" && !checkKeyword(doc.statuscomment)){
		return false;
	}
	
	if(doc.generalcomment.value != "" && !checkKeyword(doc.generalcomment)){
		return false;
	}
	
	document.frm.act.value = 2;
	document.frm.submit();
}
function deleteClient(){
	if(!confirm("Do you want to delete selected item(s)?")){
		
	}else{
		document.frm.act.value = 3;
		document.frm.submit();
	}
}
function searchClient(){
	var doc = document.frm;
	doc.act.value = 4;
	return true;
}
function docheckcontant(type)
{
	var checkbox_name = "";
	var startdate_name = "";
	var enddate_name = "";
	switch (type){
		case 1: 
			checkbox_name = "openfee_constant";
			startdate_name = "startdate_openfee";
			enddate_name = "enddate_openfee";
			imgstart = "img1";
			imgend = "img2";
			break;
		case 2: 
			checkbox_name = "monthlyfee_constant";
			startdate_name = "startdate_monthlyfee";
			enddate_name = "enddate_monthlyfee";
			imgstart = "img3";
			imgend = "img4";
			break;
		case 3: 
			checkbox_name = "itemlimit_constant";
			startdate_name = "startdate_itemlimit";
			enddate_name = "enddate_itemlimit";
			imgstart = "img5";
			imgend = "img6";
			break;
		case 4: 
			checkbox_name = "specialdiscount_constant";
			startdate_name = "startdate_specialdiscount";
			enddate_name = "enddate_specialdiscount";
			imgstart = "img7";
			imgend = "img8";
			break;	
		case 5: 
			checkbox_name = "deposit_constant";
			startdate_name = "startdate_deposit";
			enddate_name = "enddate_deposit";
			imgstart = "img9";
			imgend = "img10";
			break;	
		//default : statement;
	}

	if(document.getElementById(checkbox_name).checked == true)
	{
		document.getElementById(startdate_name).disabled = true;
		document.getElementById(enddate_name).disabled = true;
		document.getElementById(imgstart).style.display = "none";
		document.getElementById(imgend).style.display = "none";
	}else{
		document.getElementById(startdate_name).disabled = false;
		document.getElementById(enddate_name).disabled = false;
		document.getElementById(imgstart).style.display = "block";
		document.getElementById(imgend).style.display = "block";
	}	
}
function saveFee(type){
	var doc = document.frm;
	switch (type){
		case 1: 
			// check data of open fee
			var open_fee = doc.open_fee;
			if(open_fee.value == ""){
				pop_err(open_fee,"Please input open fee!");
				return false;
			}else{
				if(!isnumeric(open_fee.value)){
					pop_err(open_fee,"Open fee is invalid! Please input again!");
					return false;
				}
			}
			if(doc.openfee_constant.checked == false){
				var startdate_openfee = doc.startdate_openfee;
				var enddate_openfee = doc.enddate_openfee;
				if(startdate_openfee.value == ""){
					pop_err(startdate_openfee,"Please input start date!");
					return false;
				}else{
					if(!isDate(startdate_openfee.value)){
						pop_err(startdate_openfee,"Start date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(enddate_openfee.value == ""){
					pop_err(enddate_openfee,"Please input end date!");
					return false;
				}else{
					if(!isDate(enddate_openfee.value)){
						pop_err(enddate_openfee,"End date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(compareDate(startdate_openfee.value, enddate_openfee.value) == 0){
					pop_err(enddate_openfee,"Please input end date later than start date!");
					return false;
				}
			}
			break;
		case 2: 
			// check data of monthly fee
			var monthly_fee = doc.monthly_fee;
			if(monthly_fee.value == ""){
				pop_err(monthly_fee,"Please input monthly fee!");
				return false;
			}else{
				if(!isnumeric(monthly_fee.value)){
					pop_err(monthly_fee,"Monthly fee is invalid! Please input again!");
					return false;
				}
			}
			if(doc.monthlyfee_constant.checked == false){
				var startdate_monthlyfee = doc.startdate_monthlyfee;
				var enddate_monthlyfee = doc.enddate_monthlyfee;
				if(startdate_monthlyfee.value == ""){
					pop_err(startdate_monthlyfee,"Please input start date!");
					return false;
				}else{
					if(!isDate(startdate_monthlyfee.value)){
						pop_err(startdate_monthlyfee,"Start date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(enddate_monthlyfee.value == ""){
					pop_err(enddate_monthlyfee,"Please input end date!");
					return false;
				}else{
					if(!isDate(enddate_monthlyfee.value)){
						pop_err(enddate_monthlyfee,"End date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(compareDate(startdate_monthlyfee.value, enddate_monthlyfee.value) == 0){
					pop_err(enddate_monthlyfee,"Please input end date later than start date!");
					return false;
				}
			}
			break;
		case 3: 
			// check data of item limit
			var min_item_limit = doc.min_item_limit;
			var max_item_limit = doc.max_item_limit;
			if(min_item_limit.value == ""){
				pop_err(min_item_limit,"Please input min item limit!");
				return false;
			}else{
				if(!isInteger(min_item_limit.value)){
					pop_err(min_item_limit,"Min item limit is invalid! Please input again!");
					return false;
				}
			}
			if(max_item_limit.value == ""){
				pop_err(max_item_limit,"Please input max item limit!");
				return false;
			}else{
				if(!isInteger(max_item_limit.value)){
					pop_err(max_item_limit,"Max item limit is invalid! Please input again!");
					return false;
				}
			}
			if(doc.itemlimit_constant.checked == false){
				var startdate_itemlimit = doc.startdate_itemlimit;
				var enddate_itemlimit = doc.enddate_itemlimit;
				if(startdate_itemlimit.value == ""){
					pop_err(startdate_itemlimit,"Please input start date!");
					return false;
				}else{
					if(!isDate(startdate_itemlimit.value)){
						pop_err(startdate_itemlimit,"Start date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(enddate_itemlimit.value == ""){
					pop_err(enddate_itemlimit,"Please input end date!");
					return false;
				}else{
					if(!isDate(enddate_itemlimit.value)){
						pop_err(enddate_itemlimit,"End date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(compareDate(startdate_itemlimit.value, enddate_itemlimit.value) == 0){
					pop_err(enddate_itemlimit,"Please input end date later than start date!");
					return false;
				}
			}
			break;
		case 4: 
			// check data of special discount
			var special_discount = doc.special_discount;
			if(special_discount.value == ""){
				pop_err(special_discount,"Please input special discount!");
				return false;
			}else{
				if(!isnumeric(special_discount.value)){
					pop_err(special_discount,"Special discount is invalid! Please input again!");
					return false;
				}
			}
			if(doc.specialdiscount_constant.checked == false){
				var startdate_specialdiscount = doc.startdate_specialdiscount;
				var enddate_specialdiscount = doc.enddate_specialdiscount;
				if(startdate_specialdiscount.value == ""){
					pop_err(startdate_specialdiscount,"Please input start date!");
					return false;
				}else{
					if(!isDate(startdate_specialdiscount.value)){
						pop_err(startdate_specialdiscount,"Start date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(enddate_specialdiscount.value == ""){
					pop_err(enddate_specialdiscount,"Please input end date!");
					return false;
				}else{
					if(!isDate(enddate_specialdiscount.value)){
						pop_err(enddate_specialdiscount,"End date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(compareDate(startdate_specialdiscount.value, enddate_specialdiscount.value) == 0){
					pop_err(enddate_specialdiscount,"Please input end date later than start date!");
					return false;
				}
			}
			break;
		case 5: 
			// check data of deposit
			var min_balance = doc.min_balance;
			var min_deposit = doc.min_deposit;
			var deposit_bonus = doc.deposit_bonus;
			var min_deposit_amount = doc.min_deposit_amount;
			if(min_balance.value == ""){
				pop_err(min_balance,"Please input min balance!");
				return false;
			}else{
				if(!isnumeric(min_balance.value)){
					pop_err(min_balance,"Min balance is invalid! Please input again!");
					return false;
				}
			}
			if(min_deposit.value == ""){
				pop_err(min_deposit,"Please input min deposit!");
				return false;
			}else{
				if(!isnumeric(min_deposit.value)){
					pop_err(min_deposit,"Min deposit is invalid! Please input again!");
					return false;
				}
			}
			if(deposit_bonus.value == ""){
				pop_err(deposit_bonus,"Please input % deposit!");
				return false;
			}else{
				if(!isnumeric(deposit_bonus.value)){
					pop_err(deposit_bonus,"% deposit is invalid! Please input again!");
					return false;
				}
			}
			if(min_deposit_amount.value == ""){
				pop_err(min_deposit_amount,"Please input min amount!");
				return false;
			}else{
				if(!isnumeric(min_deposit_amount.value)){
					pop_err(min_deposit_amount,"Min amount is invalid! Please input again!");
					return false;
				}
			}
			if(doc.deposit_constant.checked == false){
				var startdate_deposit = doc.startdate_deposit;
				var enddate_deposit = doc.enddate_deposit;
				if(startdate_deposit.value == ""){
					pop_err(startdate_deposit,"Please input start date!");
					return false;
				}else{
					if(!isDate(startdate_deposit.value)){
						pop_err(startdate_deposit,"Start date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(enddate_deposit.value == ""){
					pop_err(enddate_deposit,"Please input end date!");
					return false;
				}else{
					if(!isDate(enddate_deposit.value)){
						pop_err(enddate_deposit,"End date is invalid. Please input with format mm/dd/yyyy!");
						return false;
					}
				}
				if(compareDate(startdate_deposit.value, enddate_deposit.value) == 0){
					pop_err(enddate_deposit,"Please input end date later than start date!");
					return false;
				}
			}
			break;
		case 6: 
			// check data of over limit item
			var pricefrom = doc.pricefrom;
			var priceto = doc.priceto;
			var chargefee = doc.chargefee;
			if(pricefrom.value == ""){
				pop_err(pricefrom,"Please input price from!");
				return false;
			}else{
				if(!isnumeric(pricefrom.value)){
					pop_err(pricefrom,"Price from is invalid! Please input again!");
					return false;
				}
			}
			if(priceto.value != ""){
				if(!isnumeric(priceto.value)){
					pop_err(priceto,"Price to is invalid! Please input again!");
					return false;
				}else{
					if(Math.max(pricefrom.value,priceto.value) == pricefrom.value){
						pop_err(priceto,"Please input price to greater than price from!");
						return false;
					}
				}
			}
			if(chargefee.value == ""){
				pop_err(chargefee,"Please input add fee!");
				return false;
			}else{
				if(!isnumeric(chargefee.value)){
					pop_err(chargefee,"Add fee is invalid! Please input again!");
					return false;
				}
			}
			break;
		case 7:
			if(doc.pricefrom.value == "" || doc.old_id.value != doc.id.value){
				var i = 0;
				for(i = 0; i < doc.length; i++){
					if(doc.elements[i].name == "chkitem" && doc.elements[i].checked == true){
						doc.old_id.value = doc.id.value;
						doc.id.value = doc.elements[i].value;
						var pricefrom_name = "pricefrom" + doc.elements[i].value;
						var priceto_name = "priceto" + doc.elements[i].value;
						var chargefee_name = "chargefee" + doc.elements[i].value;
						if(doc.id.value != doc.old_id.value){
							doc.pricefrom.value = document.getElementById(pricefrom_name).value;
							doc.priceto.value = document.getElementById(priceto_name).value;
							doc.chargefee.value = document.getElementById(chargefee_name).value;
						}
					}
				}
			}
				
			if(doc.pricefrom.value != "" && doc.id.value == doc.old_id.value && doc.old_id.value != ""){
				// check data of over limit item
				var pricefrom = doc.pricefrom;
				var priceto = doc.priceto;
				var chargefee = doc.chargefee;
				if(pricefrom.value == ""){
					pop_err(pricefrom,"Please input price from!");
					return false;
				}else{
					if(!isnumeric(pricefrom.value)){
						pop_err(pricefrom,"Price from is invalid! Please input again!");
						return false;
					}
				}
				if(priceto.value != ""){
					if(!isnumeric(priceto.value)){
						pop_err(priceto,"Price to is invalid! Please input again!");
						return false;
					}else{
						if(Math.max(pricefrom.value,priceto.value) == pricefrom.value){
							pop_err(priceto,"Please input price to greater than price from!");
							return false;
						}
					}
				}
				if(chargefee.value == ""){
					pop_err(chargefee,"Please input add fee!");
					return false;
				}else{
					if(!isnumeric(chargefee.value)){
						pop_err(chargefee,"Add fee is invalid! Please input again!");
						return false;
					}
				}
				doc.act.value = type;
				doc.submit();
			}
			return false;
			break;
		case 8:
			if(!confirm("Do you want to delete selected item(s)?")){
				return false;
			}
			break;
	}
	doc.act.value = type;
	doc.submit();
}

function doFinalize(){
	var doc = document.frmOrder;
	var salestatus = doc.salestatus;
	var i, act;
	for(i = 0; i < 3; i++)
		if(salestatus[i].checked == true)
			act = salestatus[i].value;
	doc.act.value = act + "" + act;
	doc.submit();
	/*if(szid == 0){
		alert("Truong hop nay minh se xu ly order luu thong tin order va gui mail den khach hang va shop owner")
	}
	if(szid == 1){
		alert("Xoa order nay di va e-mail toi shop owner va customer. khong thuc hien viet tinh tien cho order nay nhung ma tinh trang status cua product nay se thay doi dua tren so luong.")
	}
	if(szid == 2){
		alert("Xoa order nay di va e-mail toi shop owner va customer. khong thuc hien viet tinh tien cho order nay")
	}	*/
}

function doShopPayment(){
	var doc = document.frmAcc;
	var min_deposit = doc.min_deposit.value;
	var payment_amount = doc.payment_amount;
	if(trim(payment_amount.value) == ""){
		pop_err(payment_amount,"Please input payment amount!");
		return false;
	}else{
		if(!isnumeric(payment_amount.value)){
			pop_err(payment_amount,"Payment amount is invalid! Please input again!");
			return false;
		}
		
		if(Math.max(payment_amount.value,min_deposit) == min_deposit && payment_amount.value != min_deposit){
			pop_err(payment_amount,"Payment amount must be greater or equal " + min_deposit + "!");
			return false;
		}
	}
	var check_payment = 0;
	var payment_value = "";
	for(var i=0; i<doc.length;i++){
		if(doc.elements[i].type=="radio" && doc.elements[i].name == "payment" && doc.elements[i].checked == true){
			check_payment = 1;
			if(doc.elements[i].value != "-"){
				payment_value = doc.elements[i].value;
			}else{
				payment_value = doc.traditionpayment.value;
			}
			i = doc.length;
		}
	}
	
	if(check_payment == 0){
		pop_err(doc.payment_amount,"Please select Payment Method!")
		return false;
	}else{
		// payment online	
		if(payment_value.substring(payment_value.length,1) == 0){
			doc.action = "shop_acc_fund_paypal.asp";
		}else{
			doc.action = "shop_acc_fund_detail.asp";
		}
	}
	doc.act.value = 2;
	doc.submit();
	return true;
}

function checkDate(){
	var doc = document.frm;
	var from_date = doc.from_date;
	var to_date = doc.to_date;
	if(from_date.value == ""){
		pop_err(from_date,"Please input from date!");
		return false;
	}else{
		if(!isDate(from_date.value)){
			pop_err(from_date,"From date is invalid. Please input with format mm/dd/yyyy!");
			return false;
		}
	}
	if(to_date.value != "" && !isDate(to_date.value)){
		pop_err(to_date,"To date is invalid. Please input with format mm/dd/yyyy!");
		return false;
	}
	doc.act.value = 2;
	return true;
}

function checkVacationMsg(){
	var doc = document.frmVacation;
	var active = doc.active;
	var from_date = doc.from_date;
	var to_date = doc.to_date;
	var content = doc.content;
	if(active[0].checked == true){
		if(to_date.value == ""){
			pop_err(to_date,"Please input return date!");
			return false;
		}else{
			if(!isDate(to_date.value)){
				pop_err(to_date,"Return date is invalid. Please input with format mm/dd/yyyy!");
				return false;
			}
		}
	}
	if(active[1].checked == true && to_date.value != "" && !isDate(to_date.value)){
		pop_err(to_date,"Return date is invalid. Please input with format mm/dd/yyyy!");
		return false;
	}
	if(to_date.value != "" && compareDate(from_date.value, to_date.value) == 0){
		pop_err(to_date,"Please input return date later than current date!");
		return false;
	}
	if(content.value == ""){
			pop_err(content,"Please input content of message!");
			return false;
		}
	doc.act.value = 2;
	return true;
}

function showReport(){
	var doc = document.frmReport;
	if(doc.reportdate.value == ""){
		pop_err(doc.reportdate,"Please input date report!");
			return false;
	}
	doc.act.value = 2;
	doc.submit();
}

function loadReport(){
	if(document.frmReport.act.value == 2)
		document.getElementById('tblReport').style.display = "block";
	else
		document.getElementById('tblReport').style.display = "none";
}

function view_last_payment(id){
	var pagename = "admin_view_last_payment.asp?shopid=" + id;
	window.open(pagename,"","scrollbars=yes,resizeable=yes,menubar=no,status=no,Maximize=no,toolbar=no,left=220,width=600,height=155");
}

function activeInformation(id){
	window.location.replace("admin_information.asp?act=active&id="+id);
}

function doCloseShop(){
	if(!confirm("Are you sure you want to close your shop?")){
		
	}else{
		window.location.replace("close_shop.asp");
	}
}

function doCancelAccount(){
	if(!confirm("Are you sure you want to cancel membership?")){
		
	}else{
		window.location.replace("cancel_account.asp");
	}
}

function check_sale_assistant(){
	var doc = document.frmSA;
	var bootname = doc.bootname;
	var firstname = doc.firstname;
	var email = doc.email;
	var bootcategory = doc.bootcategory;
	var service_description = doc.service_description;
	if(trim(bootname.value) == ""){
		pop_err(bootname,"Please input boot name!")
		return false;
	}
	if(trim(firstname.value) == ""){
		pop_err(firstname,"Please input first name!")
		return false;
	}
	if(trim(email.value) == ""){
		pop_err(email,"Please input email!")
		return false;
	}else{
		if(!isemailaddress(email.value)){
			pop_err(email,"Email address is invalid! Please input again!")
			return false;
		}
	}
	if(trim(bootcategory.value) == ""){
		pop_err(bootcategory,"Please input boot category!")
		return false;
	}
	if(trim(service_description.value) == ""){
		pop_err(service_description,"Please input service description")
		return false;
	}
	doc.act.value = "save";
	return true;
}

function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function isUsername( chkString ) {
  var atFlag = false;   // at sign found
  var stopFlag = false; // stop found
  if ( chkString.length == 0 ) {
    return false;
  }else {
    for ( i = 0; i < chkString.length; i++) {
      if ( chkString.substring( i, i + 1 ) == ' ' ) {
        atFlag = true;
        stopFlag = true;
      }
    }
    if ( atFlag && stopFlag )
      return false;
    else
      return true;
  }
}

function checkKeyword(element){
	if(element.value.toLowerCase().indexOf("<script") != -1 || element.value.toLowerCase().indexOf("</script") != -1
			|| element.value.toLowerCase().indexOf("&lt;script") != -1 || element.value.toLowerCase().indexOf("&lt;/script") != -1){
		pop_err(element,"You can not input keyword '<script>' or '</script>'. Please input again!")
		return false;
	}
	return true;
}

function trim(st)
{
	index = 0;
	for (var i = 0; i < st.length; i++)
	{
		ch = st.charAt(i);
		if (ch == ' ')
			index++;
		else 
			break;
	}
	st = st.substring(index, st.length);
	index = st.length;
	for (i = index-1; i > 0; i--)
	{
		ch = st.charAt(i);
		if (ch==' ')
			index--;
		else
			break;
	}
	st = st.substring(0, index);
	return st;
}

function check_url(str_url)
{
	var arr = new Array();
	var re = /[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*:\/\/([0-9a-zA-Z-_`!@$&*+|\]\[:;?,~=]+)+(\.[0-9a-zA-Z-_`!@$&*+|\]\[:;?,~=]+)*(\/[0-9a-z A-Z-_`!@$&*+|\]\[:;?,~.=]*)*$/;
	str_url = trim(str_url);
	if(str_url.search(re)){
		return false;
	} else{
		pos_pointslash = str_url.indexOf("./");
		pos_slashpoint = str_url.indexOf("/.");
		if(pos_pointslash != -1 || pos_slashpoint != -1)
			return false;
		arr = str_url.split("//");
		if(arr.length > 2)
			return false;
		return true;
	}
}

/*--------------------------------------------------------------------------------------
// Checking the entry string is date and formated mm/dd/yyyy
--------------------------------------------------------------------------------------*/
function isDate(str){
//				mm           /    dd        /   yyyy
	var re = /([0-9]{1,2})+\/([0-9]{1,2})+\/([0-9]{4})+$/;
	if(str.search(re)){
		//alert("Invalid date. Please try again!");			  
		return false;
	}else{
		a = str.split("/");
		mm = parseInt(a[0],10);dd = parseInt(a[1],10);yy = parseInt(a[2],10);
		if(mm == 0 || dd == 0 || yy == 0|| mm > 12 || dd > 31){
			//alert("Invalid date. Please try again!");
			return false;
		}
		if((mm == 4 || mm == 6 || mm == 9 || mm == 11) && (dd > 30)){
			//alert("Invalid date. Please try again!");
			return false;
		}
		if(mm == 2){
			if (((yy % 4 == 0) && (yy % 100 != 0)) || ((yy % 400) == 0)){// check Leap year
				if(dd < 1 || dd > 29){	
				   //alert("Invalid date. Please try again!")
				   return false;
				}
			}else{
				if(a[1] < 1 || a[1] > 28){
					//alert("Invalid date. Please try again!");
					return false;
				} 				
			}
		}
		if(yy < 1970 || yy > 2037){
			//alert("Please input year from 1970 to 2037!");
			return false
		}
		return true;
	}
}
/*--------------------------------------------------------------------------------------
// Compare two date with format mm/dd/yyyy
--------------------------------------------------------------------------------------*/
function compareDate(strDate1, strDate2){
	var arrDate1 = strDate1.split("/");
	var arrDate2 = strDate2.split("/");
	var valueDate1 = arrDate1[2];
	var valueDate2 = arrDate2[2];
	if(arrDate1[0].length < 2)
		valueDate1 = valueDate1 + "0" + arrDate1[0];
	else
		valueDate1 = valueDate1 + "" + arrDate1[0];
	if(arrDate1[1].length < 2)
		valueDate1 = valueDate1 + "0" + arrDate1[1];
	else
		valueDate1 = valueDate1 + "" + arrDate1[1];
	if(arrDate2[0].length < 2)
		valueDate2 = valueDate2 + "0" + arrDate2[0];
	else
		valueDate2 = valueDate2 + "" + arrDate2[0];
	if(arrDate2[1].length < 2)
		valueDate2 = valueDate2 + "0" + arrDate2[1];
	else
		valueDate2 = valueDate2 + "" + arrDate2[1];
	if(valueDate2 <= valueDate1)
		return 0;
	else
		return 1;
}

function isemailaddress(str_email){
	var re = /^[0-9a-z-A-Z-_~=:,|\/\\\'\"]+(\.[0-9a-z-A-Z-_~=:,|\/\\\'\"]+)*@[0-9a-z-A-Z-_~=:,|\/\\\'\"]+(\.[0-9a-z-A-Z-_~=:,|\/\\\'\"]+)+(\.[0-9a-z-A-Z-_~=:,|\/\\\'\"]+)*$/;
	var pos = str_email.search(re);
	if(pos == -1){
		return false;
	}else{
		return true;
	}
}

function isInteger(num){
	var re = /^[0-9]*$/;
	var pos = num.search(re);
	if(pos == -1){
		return false;
	}else{
		return true;
	}
}

function isnumeric(num){
	return !isNaN(num);
}
