// =================================================
//@					MAKE BY PRAPAS KAMHANPON
//@		(SOFTWARE ENGINEER OF TRUE STEP CO., LTD.)
// =================================================

var tmp_status;
var photo_number;
photo_number = 1;
/**
 *	@subpackage modules
 */
 function setPhotoNumber(num){
	 photo_number = parseInt(num)
 }

function magicImagesPre(){

	if(photo_number == 1){
		photo_numbeir = parseInt(photoi.length) -1 
	}else{
		photo_numbeir = photo_number - 1
	}
	
	magicImages(photoi[photo_numbeir])	

	if(photo_number == 1){
		photo_number = photoi.length - 1
	}else{
		photo_number = photo_number - 1
	}

}

function magicImagesNext(){
	if(photo_number == parseInt(photoi.length) -1 ){
		photo_numbeir = 1 
	}else{
		photo_numbeir = photo_number + 1
	}

	magicImages(photoi[photo_numbeir])
	
	if(photo_number == parseInt(photoi.length) -1){
		photo_number = 1
	}else{
		photo_number = photo_number + 1
	}
	
}

function TSdelete(id,name,url,lang){
	if(lang == 'th'){
		var resc = confirm("คุณต้องการลบ \" "+name+" \" ?");
	}else{
		var resc = confirm("Are you delete \" "+name+" \" sure?");
	}

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




function TSedit(id,url){
	window.parent.location=url+"&action=edit&id="+id;
}

function TSeditType(id,url){
	if (id<=0)
	{alert("กรุณาเลือก รายการ !");return;
	}
	window.parent.location=url+"&action=edittype&id="+id;
}

function TSaddType(id,url){
	window.parent.location=url+"&action=addtype";
}

function toggle(id,url){
	window.parent.location=url+"&action=toggle&id="+id;
}

function toggleHome(id,url){
	window.parent.location=url+"&action=toggleHome&id="+id;
}

function logout(url,lang){
	if(lang == 'th'){
		var resc = confirm("คุณต้องการออกจากระบบ ?");
	}else{
		var resc = confirm("Are you sure logout ?");
	}

	if(resc){
		window.parent.location=url;
	}
}

function magicImages(_obj)
{
  document.images["flyer"].src=_obj;
}

function magicImages1(_obj)
{
  document.images["flyer1"].src=_obj;
}

function magicImages2(_obj)
{
  document.images["flyer2"].src=_obj;
}

function magicImages3(_obj)
{
  document.embeds["flyer3"].src=_obj;

}

function chgImages2(_obj)
{
  document.images["flyer2"].src=_obj;
}


function showDiv(div_name) { 
	hide_special=div_name;
	
	if(tmp_status == '' || tmp_status == 1){
		tmp_status = 2;
		var status = "none";
	}else{
		tmp_status = 1;
		var status = "inline";
	}


	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(div_name).style.display = status; 
		return false;
	} 
	else { 
		if (document.layers) { // Netscape 4 
			document.layers[div_name].display = status; 
			return false;
		} 
		else { // IE 4 
			document.all[div_name].style.display = status; 
		return false;
		} 
	} 
} 

function showDivE(div_name) { 
	hide_special=div_name;

if (document.getElementById) { // DOM3 = IE5, NS6 
//if(isbrowser=='MOZ'){alert(div_name);
//document.getElementById[div_name].style.visibility = 'visible'; 
//return false;
//}else if(isbrowser=='IE'){
document.getElementById(div_name).style.display = "inline"; 
return false;
//}
} 
else { 
if (document.layers) { // Netscape 4 
document.layers[div_name].display = "inline"; 
return false;
} 
else { // IE 4 
document.all[div_name].style.display = "inline"; 
return false;
} 
} 
}  

function hideDiv(div_name) { 
		tmp_status = 2;
		set_back=div_name;
		if (document.getElementById) { // DOM3 = IE5, NS6 
			document.getElementById(div_name).style.display = 'none'; 
			return false;
		} 
		else { 
			if (document.layers) { // Netscape 4 
				document.layers[div_name].display = 'none'; 
				return false;
			} 
			else { // IE 4 
				document.all[div_name].style.visibility = 'none'; 
				return false;
			} 
	} 
} 


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 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  - 40;	 

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

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

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

	  }
	  
}


function showAtElement (el) {
	var p = getAbsolutePos(el);
	//this.showAt(p.x, p.y + el.offsetHeight);
	return p;
}


function showAt(x, y) {
	var s = this.element.style;
	s.left = x + "px";
	s.top = y + "px";
	this.show();
}



 function check_number(uiLang)
	 {
	
  var keycode = window.event.keyCode;
  //alert(keycode);
  if( keycode >=37 && keycode <=40 ) return true;  // arrow left, up, right, down  
  if( keycode >=48 && keycode <=57 ) return true;  // key 0-9
  if( keycode >=96 && keycode <=105 ) return true;  // numpad 0-9
  if( keycode ==8  ) return true;  // backspace
  if( keycode ==9 ) return true;  // tab
  if( keycode ==13  ) return true; 	 //enter
  if( keycode ==116  ) return true; 	 //enter

  if( keycode ==45 ||  keycode ==46 || keycode ==35 || keycode ==36) return true;  // insert, del, end, home
  if(uiLang == 'th'){
		alert("ข้อมูลนี้ไม่ใช่ตัวเลข !");
  }else{
	  alert("This data no number !");
  }
  return false;
}


function TSconfirm(uiLang,name){
	if(uiLang == 'th'){
		var Cres = confirm("คุณต้องการลบ \""+name+" \"?");
	}else{
		var Cres = confirm("Are you delete \" "+name+" \" sure?")
	}
		if(Cres){return true;}		
}

function sumpriceEachRows(digit1,digit2,Fshow){
	var Edigit1 =  eval(digit1);
	var grandPrice = Edigit1 * digit2;
	var frm = eval("document.frmBasket."+Fshow);
	var grandPrice = grandPrice.toString();
	var _p_split = grandPrice.split('.');

	if(_p_split[1] != null){
		if(_p_split[1].length < 2){ _p_split[1] = _p_split[1]+"0"; }
		frm.value = _p_split[0]+"."+_p_split[1].substr(0,2);
	}else{
		frm.value = _p_split[0]+".00";
	}
	
}

function sumPriceEachCols(colsCount){
	//alert(colsCount);
	var frmGrand = eval("document.frmBasket.grandPrice");
	var tmpGrand = 0;
	for(var i=0;i<colsCount;i++){
		var  Fshow = "Fshow"+i;
		var frm = eval("document.frmBasket."+Fshow);
		//alert(frm.value);
		tmpGrand = parseFloat(tmpGrand) + parseFloat(frm.value);
	}

	var tmpGrand = tmpGrand.toString();
	var _p_split = tmpGrand.split('.');

	if(_p_split[1] != null){
		if(_p_split[1].length < 2){ _p_split[1] = _p_split[1]+"0"; }
		frmGrand.value = _p_split[0]+"."+_p_split[1].substr(0,2);
	}else{
		frmGrand.value = _p_split[0]+".00";
	}

}

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

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

 function getSelectedIndexProd(_obj){
	var _return = _obj.options[_obj.selectedIndex].value;
	var _per = parseInt(_return) / 100.00;
	//alert(_per)
	var _price = eval(document.frmProduct.price.value);
	if(document.frmProduct.price.value == 0){
		alert('กรุณาระบุ ราคา ก่อนค่ะ');
		document.frmProduct.price.style.background='orange';
		document.frmProduct.price.focus();

	}else{
		var _price_decimal = document.frmProduct.price_decimal.value;
		var _com = parseInt(_price+"."+_price_decimal);
		var _price_net = parseFloat(_com * _per);
		_price_net = _com - _price_net;
		_price_net = _price_net.toString();
		var _p_split = _price_net.split('.');
		document.frmProduct.price2.value = _p_split[0];
		document.frmProduct.price2_decimal.value = _p_split[1].substr(0,2);

	}
 }

 //@ Effect photo -->
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();

function nereidFade(object, destOp, rate, delta){
if (!document.all)
return
if (object != "[object]"){ //do this so I can take a string too
setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
return;
}

clearTimeout(nereidFadeTimers[object.sourceIndex]);

diff = destOp-object.filters.alpha.opacity;
direction = 1;
if (object.filters.alpha.opacity > destOp){
direction = -1;
}
delta=Math.min(direction*diff,delta);
object.filters.alpha.opacity+=direction*delta;

if (object.filters.alpha.opacity != destOp){
nereidFadeObjects[object.sourceIndex]=object;
nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
}
}

//@ Effect photo -->



function PJadd(id,url){
	if (id<=0)
{ alert("กรุณาเลือกรายการ /Please Select   !"); return; }
	window.parent.location=url;
}


function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = ((screen.height - h) / 2)-30;
//wint=10;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function Bnadd(url){
	window.parent.location=url;
}

function TSdeletex(id,name,url,lang){
	if(lang == 'th'){
		var resc = confirm("คุณต้องการลบ \" "+name+" \" ?");
	}else{
		var resc = confirm("Are you delete \" "+name+" \" sure?");
	}

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

<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->


