
/*set ul dropdown IE6 */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/* search */

function validateSearch(e){
	if (e.q.value.trim()==''){
		alert('กรุณาระบุคำที่ต้องการค้นหาด้วยค่ะ!');
		e.q.value='';
		e.q.focus();
		return false;
	}
	var trimW = e.q.value.trim();
	if (trimW.length < 3){
		alert('กรุณาระบุคำที่ต้องการค้นหามากกว่า 3 ตัวอักษรค่ะ!');
		e.q.focus();
		return false;
	}
	document.form_search.submit();
}


String.prototype.trim=function() 
{
	return this.replace(/^\s*|\s*$/g,'');
}
String.prototype.ltrim=function() 
{
	return this.replace(/^\s*/g,'');
}
String.prototype.rtrim=function() 
{
	return this.replace(/\s*$/g,'');
}
/******************************** Buyer ************************************/

function submitPage(urlforlink){

	if (!IsNumeric(document.formpost.fgtp.value)) 
    { 
	  alert('กรุณาระบุหมายเลขหน้าให้ถูกต้องค่ะ') 
	  document.formpost.fgtp.focus(); 
	  return false; 
    } 

	var afg = parseInt(document.formpost.fgtp.value);
	if(afg <= parseInt(document.formpost.tpge.value) && afg !=0){

	document.formpost.action = urlforlink+"&page="+afg;
	document.formpost.submit();

	}else if(afg ==0){
		alert("กรุณากรอกหมายเลขหน้าที่มากกว่า 0 ค่ะ");
		document.formpost.fgtp.focus();
	}else{
		alert("กรุณากรอกหมายเลขหน้าที่ไม่เกินจำนวนหน้าทั้งหมดค่ะ");
		document.formpost.fgtp.focus();
		//return false();
	}
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
	var k =0;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
	        blnResult = false;
         }
	  /*if (strChar == "."){
			k++;
		 }*/
	  if(k>1){
		  blnResult = false;
		  }
      }
   return blnResult;
   }

function changeOrder(Section,urlforlink){
	var sortby = "";
	if(Section==0){
			sortby = "nec";//near_close
	}else if(Section==1){
			sortby = "nav";//new_avai
	}else if(Section==2){
			sortby = "net";//new_today
	}else if(Section==3){
			sortby = "clt";//close_today
	}else if(Section==4){
			sortby = "lop";//low_price
	}else if(Section==5){
			sortby = "exp";//exp_price
	}else if(Section==6){
			sortby = "mv";//max_view
	}else{
			sortby = "mb";//max_bid
	}

	document.formpost.sortby.value=sortby;
	document.formpost.action =urlforlink;
    document.formpost.method = "get";
	document.formpost.submit();

}
function changeOrder2(Section,urlforlink){

	var sortby = "";
	if(Section==0){
			sortby = "nec";//near_close
	}else if(Section==1){
			sortby = "nav";//new_avai
	}else if(Section==2){
			sortby = "net";//new_today
	}else if(Section==3){
			sortby = "clt";//close_today
	}else if(Section==4){
			sortby = "lop";//low_price
	}else if(Section==5){
			sortby = "exp";//exp_price
	}else if(Section==6){
			sortby = "mv";//max_view
	}else{
			sortby = "mb";//max_bid
	}

	document.formpost.sortby.value=sortby;
	document.formpost.action = urlforlink;
    document.formpost.method = "get";
	document.formpost.submit();

}

function IsNumeric2(strString){

	
	var ab = strString.replace(".", "");
	//alert(ab.replace(".", ""));
	var aa = IsNumeric(ab);
	if(aa){
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
	var k =0;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
	        blnResult = false;
         }
	  if (strChar == "."){
			k++;
		 }
	  if(k>1){
		  blnResult = false;
		  }
      }
   return blnResult;
	}else{
		return false;
	}
   }

function Search(){

	if(parseFloat(document.formpost.end_price.value) <= parseFloat(document.formpost.start_price.value)){
	  alert('ช่วงราคาเริ่มต้นควรน้อยกว่าราคาสิ้นสุดค่ะ') 
	  document.formpost.start_price.focus(); 
	  return false; 
	}

	if (!IsNumeric2(document.formpost.start_price.value) && document.formpost.start_price.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขและจุดทศนิยมค่ะ') 
	  document.formpost.start_price.focus(); 
	  return false; 
    }

	if (!IsNumeric2(document.formpost.end_price.value) && document.formpost.end_price.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขและจุดทศนิยมค่ะ') 
	  document.formpost.end_price.focus(); 
	  return false; 
    } else{
	document.formpost.method="get";
	document.formpost.submit();

	}
}

function KeyEng(e){
	if (e.keyCode <64||e.keyCode > 122){
		if (e.keyCode!=13 && e.keyCode!=32 && e.keyCode!=48 && e.keyCode!=49 && e.keyCode!=50 && e.keyCode!=51 && e.keyCode!=52 && e.keyCode!=53 && e.keyCode!=54 && e.keyCode!=55 && e.keyCode!=56 && e.keyCode!=57 && e.keyCode!=46 && e.keyCode!=45 && e.keyCode!=95 && e.keyCode!=64){
			e.returnValue = false;

			}
		}else {
			if (e.keyCode > 90 && e.keyCode < 97 && e.keyCode!=95) e.returnValue = false;
		}
}

/*--------------------------------- AJAX FUNCTION----------------------------------*/
 function ajaxGet(containerID,url){
 var xmlhttp = null;

	/*if(window.ActiveXObject){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttp = new XmlHttpRequest();
	}*/

		if (window.XMLHttpRequest) { 
		// Mozilla, Safari,...
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
		xmlhttp.overrideMimeType('text/xml');
		// See note below about this line
		}
		} else if (window.ActiveXObject) { // IE
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
		try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) 
		{}
		}
		}

	xmlhttp.open("GET",url);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById(containerID).innerHTML = xmlhttp.responseText;
		}else{
			document.getElementById(containerID).innerHTML = "<img src='/images/live_com_loading.gif'>";
		}
	}
	
	xmlhttp.send(null);
 }

 function ajaxPost(containerID,URL,form){
 var xmlhttp = null;
	/*if(window.ActiveXObject){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttp = new XmlHttpRequest();
	}*/
		if (window.XMLHttpRequest) { 
		// Mozilla, Safari,...
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
		xmlhttp.overrideMimeType('text/xml');
		// See note below about this line
		}
		} else if (window.ActiveXObject) { // IE
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
		try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) 
		{}
		}
		}


	xmlhttp.open("POST",URL,true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById(containerID).innerHTML = xmlhttp.ResponseText;
		}else{
			document.getElementById(containerID).innerHTML = "<img src='live_com_loading.gif'>";
		}
	}
	xmlhttp.send(getValuePost(form));
 }

 function getValuePost(form){
	var qurystring='';
	var allElement = form.elements.length;
	
	for(var i=0;i<allElement;i++){
		if(form.elements[i].type == 'text'){
			qurystring += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value)+"&";
		}
		if(form.elements[i].type == 'text'){
			qurystring += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value)+"&";
		}
		if(form.elements[i].type == 'text'){
			qurystring += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value)+"&";
		}
	}
	return qurystring;
 }
/*-----------------end ajax-------------------------*/

function getDistrictName(ob){
		ajaxGet('getDistrict','ajax_district.php?province='+ob);
}


function advSubmit(){

	if (document.formget.q.value.trim()=="") 
    { 
		alert('กรุณาระบุเฉพาะคำค้นหาค่ะ');
		document.formget.q.value="";
		document.formget.q.focus(); 
		return false; 
    }
	var trimW = document.formget.q.value.trim();
	if (trimW.length < 3){
		alert('กรุณาระบุคำที่ต้องการค้นหามากกว่า 3 ตัวอักษรค่ะ!');
		document.formget.q.focus(); 
		return false;
	}

	if (document.formget.s_topic.checked==false && document.formget.s_uname.checked ==false) 
    { 
	  alert('กรุณาระบุอย่างน้อยหนึ่งรูปแบบการค้นหาค่ะ') 
	  document.formget.s_topic.focus(); 
	  return false; 
    }


	if (!IsNumeric2(document.formget.start_price.value) && document.formget.start_price.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขและจุดทศนิยมค่ะ') 
	  document.formget.start_price.focus(); 
	  return false; 
    }

	if (!IsNumeric2(document.formget.end_price.value) && document.formget.end_price.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขและจุดทศนิยมค่ะ') 
	  document.formget.end_price.focus(); 
	  return false; 
    } 

	if(parseFloat(document.formget.end_price.value) <= parseFloat(document.formget.start_price.value)){
	  alert('ช่วงราคาเริ่มต้นควรน้อยกว่าราคาสิ้นสุดค่ะ') 
	  document.formget.start_price.focus(); 
	  return false; 
	}
	
	if (!IsNumeric(document.formget.start_nbid.value) && document.formget.start_nbid.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขค่ะ') 
	  document.formget.start_nbid.focus(); 
	  return false; 
    } 

	if (!IsNumeric(document.formget.end_nbid.value) && document.formget.end_nbid.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขค่ะ') 
	  document.formget.end_nbid.focus();
	  return false; 
    }

	if(parseInt(document.formget.end_nbid.value) <= parseInt(document.formget.start_nbid.value)){
	  alert('ช่วงจำนวนครั้งเริ่มต้นควรน้อยกว่าจำนวนครั้งที่สิ้นสุดค่ะ') 
	  document.formget.start_nbid.focus(); 
	  return false; 
	}

	
	if (!IsNumeric3(document.formget.pageSize.value) && document.formget.pageSize.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขที่ขึ้นต้นไม่ใช่เลขศูนย์และเป็นจำนวนเต็มค่ะ') 
	  document.formget.pageSize.focus();
	  return false; 
    } else{
	document.formget.submit();

	}

}

function startRequestTap(setTap,userId,url) {
	ajaxGet('showTap',url + '/ajax_feedback.php?setTap='+setTap+'&nuserID='+userId);
}

function startRequestTap2(setTap,userId,url) {
	ajaxGet('showTap',url + '/ajax_feedbackAuction.php?setTap='+setTap+'&nuserID='+userId);
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function sendContact() {
	if(document.formpost.userID.value ==document.formpost.nuserID.value)
	{
	  alert('ไม่สามารถส่งเมลล์คำถามนี้กลับหาตัวสมาชิกเองได้ค่ะ \n กรุณากดยกเลิกเพื่อทำรายการอื่่นค่ะ') 
	  return false; 
	}

	if (document.formpost.message.value.trim()=="") 
    { 
	  alert('กรุณาระบุรายละเอียดค่ะ') 
	  document.formpost.message.select(); 
	  document.formpost.message.focus(); 
	  return false; 
    }

	document.formpost.submit();
}

function sendContact_n() {
	if(document.formpost.userID.value ==document.formpost.nuserID.value)
	{
	  alert('ไม่สามารถส่งเมลล์คำถามนี้กลับหาตัวสมาชิกเองได้ค่ะ \n กรุณากดยกเลิกเพื่อทำรายการอื่่นค่ะ') 
	  return false; 
	}

	if (document.formpost.subjCust.value.trim()=="") 
    { 
	  alert('กรุณาระบุชื่อเรื่องค่ะ') 
	  document.formpost.subjCust.select(); 
	  document.formpost.subjCust.focus(); 
	  return false; 
    }

	if (document.formpost.message.value.trim()=="") 
    { 
	  alert('กรุณาระบุรายละเอียดค่ะ') 
	  document.formpost.message.select(); 
	  document.formpost.message.focus(); 
	  return false; 
    }

	document.formpost.submit();
}

function IsNumeric3(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "1234567890";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
	var k =0;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
	  if(i==0 && strChar=="0"){
		  return false
	  }
      if (strValidChars.indexOf(strChar) == -1)
         {
	        blnResult = false;
         }
	  /*if (strChar == "."){
			k++;
		 }*/
	  if(k>1){
		  blnResult = false;
		  }
      }
   return blnResult;
   }


function SearchList(val){

	if(parseFloat(document.formpost.end_price.value) <= parseFloat(document.formpost.start_price.value)){
	  alert('ช่วงราคาเริ่มต้นควรน้อยกว่าราคาสิ้นสุดค่ะ') 
	  document.formpost.start_price.focus(); 
	  return false; 
	}

	if (!IsNumeric2(document.formpost.start_price.value) && document.formpost.start_price.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขและจุดทศนิยมค่ะ') 
	  document.formpost.start_price.focus(); 
	  return false; 
    }

	if (!IsNumeric2(document.formpost.end_price.value) && document.formpost.end_price.value !='') 
    { 
	  alert('กรุณาระบุเฉพาะตัวเลขและจุดทศนิยมค่ะ') 
	  document.formpost.end_price.focus(); 
	  return false; 
    } else{
	document.formpost.method="get";
	document.formpost.action=val;
	document.formpost.submit();

	}
}

var copytoclip=1
function HighlightAll(theField,ID) {
	var tempval=eval("document.getElementById('"+theField+"')");
	tempval.focus()
	tempval.select()
	/*if (document.all&&copytoclip==1){
		therange=tempval.createTextRange()
		therange.execCommand("Copy")
		setTimeout("window.status=''",1800)
	}*/
		
	ajaxGet('getCnt','ajax_clipboard.php?nitemID='+ID);
	//alert("คุณ Copy โค้ดสำเร็จแล้วค่ะ \nนำไปโปรโมตที่เว็บไซต์อื่น ได้เลยค่ะ ");
	
}
/******************************** js_script ************************************/


/* =================================================
 *	@			     BORROW FROM PRAPAS KAMHANPON
 *	@		(SOFTWARE ENGINEER OF M-WEB., LTD.)
 * =================================================
 */
 var tmp_status;
 function CFdel(id,name,url,lang){
	if(lang == 'th'){
		var resc = confirm("คุณต้องการลบ \" "+name+" \" หรือไม่ YES/NO?");
	}else{
		var resc = confirm("Are you delete \" "+name+" \" sure?");
	}

	if(resc){
		
		window.location=url+"?act=del&id="+id;
	}
	
}

function CFedit(id,url){
	window.location=url+"?act=edit&id="+id;
}

function CFview(id,url){
	window.location=url+"?id="+id;
}

function jumpMenu(targ,selObj,restore)
{ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function showDiv(div_name)
{
	document.getElementById(div_name).style.display = ''; 
}

function hideDiv(div_name)
{
	document.getElementById(div_name).style.display = 'none';
}

function showLayer(id,_button,_style,_Xdimension) {
	
	var el = document.getElementById(_button);
	var rl = getAbsolutePos(el);

	  if(_style == 'normal'){

			document.getElementById(id).style.left = rl.x  + 22 + parseInt(_Xdimension);
			document.getElementById(id).style.top = rl.y ;
			
	  }else if(_style == 'slide'){

			document.getElementById(id).style.left =  rl.x  + 25 + parseInt(_Xdimension);
			document.getElementById(id).style.top =  rl.y  + 0;	 

	  }else if(_style == 'free'){

			document.getElementById(id).style.left =  rl.x  + 25 + (_Xdimension);
			document.getElementById(id).style.top =  rl.y  - 100;
			
	  }else if(_style == 'button'){

			document.getElementById(id).style.left =  rl.x  + 25 + parseInt(_Xdimension);
			document.getElementById(id).style.top =  rl.y  + 22;	 

	  }
	  
}

function getAbsolutePos(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}
function magicImages(_obj){
  document.images["flyer"].src=_obj;
}
function magicImages_special(_obj,_flyer){
  document.images[_flyer].src=_obj;
}
/*
Below Modify by Neung 2008-11-19
*/
/* Category List */
function CateOver(){
	showDiv('boxCategoriespopup');
}
function CateOut(){
	hideDiv('boxCategoriespopup');
}
function CheckSearchSubmit(){
	validateSearch(document.form_search);
}
function ShoppingMember(mem_url,ebay_url,psnid){
	_onlineurl = mem_url+"/member_detail/change_profile.aspx";
	_offlineurl = ebay_url+"/member/step1.php";
	_authenurl = ebay_url+"/member/index.php";
	smi_online_control_setsmiconfig(psnid, "TEXT-DECORATION: none; FONT-FAMILY: Ms sans serif; FONT-SIZE: 10px;", "TEXT-DECORATION: none;", "", "t", "op");
	smi_online_control_display2();
}
function smi_online_control_display2(){
	if (checkonlinestatus()){
		_smiid = getsubcookie("smiservice", "SMI_ID");
		_nickname = getsubcookie("smiservice", "NICKNAME");
		_onlineurl += "?psnid=" + _psnid + "&surl=" + _surl;
		html_text = "";
		html_text += "<img width='0' height='0' alt='' src='" + _statupdateurl + "?smiid=" + _smiid + "&psnid=" + _psnid + "'>";	
		if (_display_text_type == 1){
			html_text += "<a href='" + _onlineurl + "' target='_top'>" + _nickname + "&nbsp;" + _onlinetext + "</a>";
			html_text += "<br/><strong><a target='_top' href='" + _deauthenurl + "?psnid=" + _psnid + "&surl=" + _surl + "&lg=" + _lg + "'>" + _logout_text + "</a></strong>";
		}
		else if (_display_text_type == 2){
			html_text += "<br/><strong><a target='_top' href='" + _deauthenurl + "?psnid=" + _psnid + "&surl=" + _surl + "&lg=" + _lg + "'>" + _logout_text + "</a></strong>";
		}
	}else{
		_offlineurl += "?psnid=" + _psnid + "&surl=" + _surl;
		html_text = "";
		if (_display_text_type == 1){
			html_text += "<a href='" + _offlineurl + "' target='_top'>" + _offlinetext + "</a>";
			html_text += "<br/><strong><a target='_top' href='" + _authenurl + "?psnid=" + _psnid + "&surl=" + _surl + "&turl=" + _turl + "&lg=" + _lg + "'>" + _login_text + "</a></strong>";
		}
		else if (_display_text_type == 2){
			html_text += "<br/><strong><a target='_top' href='" + _authenurl + "?psnid=" + _psnid + "&surl=" + _surl + "&turl=" + _turl + "&lg=" + _lg + "'>" + _login_text + "</a></strong>";
		}
	}
	document.write(html_text);
	//include_javascript_file("smi_email_alert.js");
}
		