// JavaScript Document
/* for product.tpl */
function sampleList(tid){
	document.location.replace('?view=samples&tid='+tid);
}
function showParameter(parameter_infor){
	if(!parameter_infor){
		document.getElementById('property_infor').style.display="block";
		document.getElementById('parameter_infor').style.display="none";
	}
	else{
		document.getElementById('property_infor').style.display="none";
		document.getElementById('parameter_infor').style.display="block";
	}
	document.getElementById('toComment').style.display="none";	
}
function showComment(){
	document.getElementById('toComment').style.display="block";
	document.getElementById('property_infor').style.display="none";
	document.getElementById('parameter_infor').style.display="none";	
}
function showInputComment(show){
	document.getElementById('inputComment').style.display=(show ? 'block':'none');
}
function __reloadBriefcase(orders){
	var show = ((document.getElementById('detailContent')!=null) ? 1:0);	
	$('isFloat').innerHTML = '<img src="images/ajaxloader.gif" width="32" height="32">';
	var pars = 'orders='+orders+'&show='+show;
	var myAjax = new Ajax.Updater('isFloat', 'ajax/ajaxbriefcase.php', {method: 'get', parameters: pars});
}
function __clearBriefcase(){
	var show = ((document.getElementById('detailContent')!=null) ? 1:0);
	$('isFloat').innerHTML = '<img src="images/ajaxloader.gif" width="32" height="32">';
	var pars = 'clear=1&show='+show;
	var myAjax = new Ajax.Updater('isFloat', 'ajax/ajaxbriefcase.php', {method: 'get', parameters: pars});
}
function __toOrder(){
	document.location.replace('?view=orders');
}
function __waiting(){
	__sleep(900);	
}
function __sleep(ms){
	var date = new Date();
	curDate = null;
	do{var curDate = new Date();}
	while( curDate - date < ms);
}	
function autoshow_advertise(){
	var widthWnd = screen.width;
	document.getElementById('advertise_left_block').style.display = "block";
	document.getElementById('advertise_right_block').style.display = "block";
	/*
	if(widthWnd > 800){
		document.getElementById('advertise_left_block').style.display = "block";
		document.getElementById('advertise_right_block').style.display = "block";
	}
	else{
		document.getElementById('advertise_left_block').style.display = "none";
		document.getElementById('advertise_right_block').style.display = "none";
	}
	*/
}
function spareparts(typeid,manid){
	var pathlink = '?view=spareparts&tid='+typeid+'&mid='+manid;
	document.location.replace(pathlink);
}
function producttype(typeid,manid){
	var pathlink = '?view=product&tid='+typeid+'&mid='+manid;
	document.location.replace(pathlink);
}
function detail(id){
	var pathlink = '?view=detail&id='+id;
	document.location.replace(pathlink);
}
function samples(id,typeid){
	var pathlink = '?view=sample&id='+id+'&tid='+typeid;
	document.location.replace(pathlink);
}

function gotopage(page, typeid, manid,filter){
	var pathlink = '?view=product&cpg='+page+'&tid='+typeid+'&mid='+manid+'&filter='+filter;
	document.location.replace(pathlink);
}

/* for detail.tpl */
function show( targets ){
    target_list = targets.split(',');
    for( i = 0 ; i < target_list.length; i++ ){
        document.getElementById( target_list[i] ).style.display="";
    }
}
function hide( targets ){
    target_list = targets.split(',');
    for( i = 0 ; i < target_list.length; i++ ){
        document.getElementById( target_list[i] ).style.display="none";
    }
}
function displayimages(id, iss){
	var pathlink = 'includes/images.php?id='+id+'&iss='+iss;
	window_open(pathlink, 600,520,'yes','normal');
}

/* dinh nghia khac */
<!--
var last_click;             // zuletzt angeklickter Button
var windows = new Array();  // Array mit Win-Objekten
function button_mouse_overme(obj){
	obj.className='mybutton_over';
}
function button_mouse_outme(obj){
	obj.className='mybutton';
}
function set_over(obj) {
   document.getElementById(obj).style.borderTopColor = "white";
   document.getElementById(obj).style.borderLeftColor = "white";
   document.getElementById(obj).style.borderBottomColor = "black";
   document.getElementById(obj).style.borderRightColor = "black";
}

function set_out(obj) {
   document.getElementById(obj).style.borderColor = "black";
}
function set_outh(obj) {
   document.getElementById(obj).style.borderColor = "ButtonFace";
}

function set_click(obj)
{
   document.getElementById(obj).style.borderTopColor = "black";
   document.getElementById(obj).style.borderLeftColor = "black";
   document.getElementById(obj).style.borderBottomColor = "white";
   document.getElementById(obj).style.borderRightColor = "white";
   elem1 = document.getElementById(last_click);
   if (elem1) elem1.style.fontWeight = "normal";
   last_click = obj;
   document.getElementById(obj).style.fontWeight = "bold";
}

function Win(ref, posx, posy) {
   this.ref  = ref;
   this.posx = posx;
   this.posy = posy;
}

function check_windows() {
   windows_new = new Array();
   for (i=0; i<windows.length; i++)
   {
    var found = false;
    try{
        if(!windows[i].ref.closed)
            found = true;
    }
    catch(e){
        found = false;
    }
    if (found && windows[i] && windows[i].ref && !windows[i].ref.closed) {
         windows_new.push(windows[i]);
         windows[i].ref.focus();
      }
   }
   windows = windows_new;
}

function window_open(url, w_width, w_height, scroll, type) {
	var proper;
   check_windows();
   ind = windows.length - 1;
   if (windows[ind]) {
      posx = windows[ind].posx + 20;
      posy = windows[ind].posy + 20;
   }
   else {
      posx = (screen.width - w_width) / 2;
      posy = (screen.height - w_height) / 2 - 30;
   }
   if (type == 'resizeable')  proper = 'titlebar=no,toolbar=yes,menubar=no,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=yes,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'normal')      proper = 'titlebar=no,toolbar=no,menubar=no,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'menu')        proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'mresizeable') proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=yes,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'minimized')   proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+screen.width+',top='+screen.height+',screenX='+screen.width+',screenY='+screen.height;
   

   win_ref = window.open(url, '', proper);
   if (win_ref) {
      tmp = new Win(win_ref, posx, posy);
      windows.push(tmp);
      win_ref.focus();
   }
   return win_ref;
}

function modal_open(url, w_width, w_height, scroll, type) {
	var proper;	
   if (type == 'normal')     proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:no;scroll:'+scroll+';status:no;';
   if (type == 'resizeable') proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:yes;scroll:'+scroll+';status:no;';
   window.showModalDialog(url, window, proper);
}

function modless_open(url, w_width, w_height, scroll, type) {
	var proper;
   if (type == 'normal')     proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:no;scroll:'+scroll+';status:no;';
   if (type == 'resizeable') proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:yes;scroll:'+scroll+';status:no;';
   window.showModalDialog(url, window, proper);
}


function vntext(st)
{
var Rex = ["&#224;","&#7843;","&#227;","&#225;","&#7841;","&#259;","&#7857;","&#7859;","&#7861;","&#7855;","&#7863;","&#226;","&#7847;","&#7849;","&#7851;","&#7845;","&#7853;","&#273;","&#232;","&#7867;","&#7869;","&#233;","&#7865;","&#234;","&#7873;","&#7875;","&#7877;","&#7871;","&#7879;","&#236;","&#7881;","&#297;","&#237;","&#7883;","&#242;","&#7887;","&#245;","&#243;","&#7885;","&#244;","&#7891;","&#7893;","&#7895;","&#7889;","&#7897;","&#417;","&#7901;","&#7903;","&#7905;","&#7899;","&#7907;","&#249;","&#7911;","&#361;","&#250;","&#7909;","&#432;","&#7915;","&#7917;","&#7919;","&#7913;","&#7921;","&#7923;","&#7927;","&#7929;","&#253;","&#7925;","&#192;","&#7842;","&#195;","&#193;","&#7840;","&#258;","&#7856;","&#7858;","&#7860;","&#7854;","&#7862;","&#194;","&#7846;","&#7848;","&#7850;","&#7844;","&#7852;","&#272;","&#200;","&#7866;","&#7868;","&#201;","&#7864;","&#202;","&#7872;","&#7874;","&#7876;","&#7870;","&#7878;","&#204;","&#7880;","&#296;","&#205;","&#7882;","&#210;","&#7886;","&#213;","&#211;","&#7884;","&#212;","&#7890;","&#7892;","&#7894;","&#7888;","&#7896;","&#416;","&#7900;","&#7902;","&#7904;","&#7898;","&#7906;","&#217;","&#7910;","&#360;","&#218;","&#7908;","&#431;","&#7914;","&#7916;","&#431&#7918;","&#7920;","&#7922;","&#7926;","&#7928;","&#221;","&#7924;"]
var Req = ["224","7843","227","225","7841","259","7857","7859","7861","7855","7863","226","7847","7849","7851","7845","7853","273","232","7867","7869","233","7865","234","7873","7875","7877","7871","7879","236","7881","297","237","7883","242","7887","245","243","7885","244","7891","7893","7895","7889","7897","417","7901","7903","7905","7899","7907","249","7911","361","250","7909","432","7915","7917","7919","7913","7921","7923","7927","7929","253","7925","192","7842","195","193","7840","258","7856","7858","7860","7854","7862","194","7846","7848","7850","7844","7852","272","200","7866","7868","201","7864","202","7872","7874","7876","7870","7878","204","7880","296","205","7882","210","7886","213","211","7884","212","7890","7892","7894","7888","7896","416","7900","7902","7904","7898","7906","217","7910","360","218","7908","431","7914","7916","4317918","7920","7922","7926","7928","221","7924"]

     function replaceString(szString,szFind,szReplace){
    var iMatched, fSubstring, sSubstring;
    iMatched=0;
        while(iMatched>=0){
        iMatched=szString.indexOf(szFind);
        if(iMatched<0)
        return szString;
        fSubstring=szString.substring(0,iMatched);
        sSubstring=szString.substring(iMatched+szFind.length,szString.length);
        szString=fSubstring + szReplace + sSubstring;
    }
    // Next line for Netscape compatibility 
    //     only - no effects
    return(0);
}

var s = st
for (i=0;i<133;i++)
{

	s = replaceString(s,Rex[i],String.fromCharCode(Req[i]))
}
return s
}	
// Ham kiem tra chuoi nhap so dau cho cac Mang 

function ValidString(sText,sodau,socuoi)
{
	var ValidChars = "0123456789,";
	var IsNumber=true;
	var Char;
	// Kiem tra tinh hop le cua cac Ky tu trong chuoi
	for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
			Char = sText.charAt(i); 
			if (i == 0 && Char=="," ) // Kiem tra dau o dau chuoi
				{
					return false;
				}
					//continue;
			if (ValidChars.indexOf(Char) == -1) 
				{
					return false;
				}
       }		
// kiem tra tinh hop le cua vi tri dau cham (,) trong chuoi so, khong the co <> 3-4  chu so giua 2 dau ,
//var mang=new Array();
    var luu=sText;
	var mang=luu.split(",");
	if (mang.length>0)	
		for(i=0;i<mang.length;i++)
			{
			    if(mang[i].length>socuoi || mang[i].length <sodau)
				    return false;				
			}			

	return true;

}
//--> 
function isNumeric(str)
{	var iLen;
	iLen=str.length;
	var c ;
	for(var i=0; i<iLen; i++)
	{	c = str.charAt(i);
		if ((c<'0') || (c>'9'))
			return false;
	}
	return true;
}
function numberInput(obj){
	var len = obj.value.length;
	obj.value = format_strnumber(obj.value);
	
	function format_strnumber(number){
		number = isNumber(resetValue(number));	
		var res='';
		var len = number.length;
		if(len <= 3)
			return number;
		else{
			var pos = len%3;
			if(pos>0)
				res += number.substr(0, pos)+'.';
			for(var i=pos; i < len; i+=3){
				res += number.substr(i, 3);
				if(i < len-3)
					res += '.';
			}
		}
		return res;
	}
	function resetValue(num){
		var str='';
		for(var i=0; i < num.length; i++){
			if(num.charAt(i) !='.')
				str += num.charAt(i);
		}
		return str;	
	}
	function isNumber(str){
		for(var i=0; i<str.length; i++){
			var c = str.charAt(i);
			if ((c<'0') || (c>'9'))
				return str.substr(0, i);
		}
		return str;
	}
}
function Selection(target)
        {
        if (typeof target.onselectstart!="undefined") //IE route
	        target.onselectstart=function(){return false}
        else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	        target.style.MozUserSelect="none"
        else //All other route (ie: Opera)
	        target.onmousedown=function(){return false}
        target.style.cursor = "default"
}
 function disableRightClick(e)
        {
            if(!document.rightClickDisabled) // initialize
            {
                if(document.layers)
                {
                    document.captureEvents(Event.MOUSEDOWN);
                    document.onmousedown = disableRightClick;
                }
                else document.oncontextmenu = disableRightClick;
                return document.rightClickDisabled = true;
            }
            if(document.layers || (document.getElementById && !document.all))
            {
                if (e.which==2||e.which==3)
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        disableRightClick();
		

var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;

var origWidth, origHeight;

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }

///////////////////////  CUSTOMIZE HERE   ////////////////////
// settings for tooltip 
// Do you want tip to move when mouse moves over link?
var tipFollowMouse= true;	
// Be sure to set tipWidth wide enough for widest image
var tipWidth= 160;
var offX= 20;	// how far from mouse to show tip
var offY= 12; 
var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
var tipFontSize= "8pt";
// set default text color and background color for tooltip here
// individual tooltips can have their own (set in messages arrays)
// but don't have to
var tipFontColor= "#000000";
var tipBgColor= "#DDECFF"; 
var tipBorderColor= "#000080";
var tipBorderWidth= 3;
var tipBorderStyle= "ridge";
var tipPadding= 4;

// tooltip content goes here (image, description, optional bgColor, optional textcolor)
var messages = new Array();
// multi-dimensional arrays containing: 
// image and text for tooltip
// optional: bgColor and color to be sent to tooltip
messages[0] = new Array('<img src="http://www.kitco.com/images/live/gold.gif" width="600" height="390">','Bi&#7875;u &#273;&#7891; t&#7927; gi&#225; v&#224;ng th&#7871; gi&#432;&#7899;i c&#7911;a Kitco',"#FFFFFF");

////////////////////  END OF CUSTOMIZATION AREA  ///////////////////

// preload images that are to appear in tooltip
// from arrays above
if (document.images) {
	var theImgs = new Array();
	for (var i=0; i<messages.length; i++) {
  	theImgs[i] = new Image();
		theImgs[i].src = messages[i][0];
  }
}

// to layout image and text, 2-row table, image centered in top cell
// these go in var tip in doTooltip function
// startStr goes before image, midStr goes between image and text
var startStr = '<table width="' + tipWidth + '"><tr><td align="center" width="100%"><img src="';
var midStr = '" border="0"></td></tr><tr><td valign="top">';
var endStr = '</td></tr></table>';

////////////////////////////////////////////////////////////
//  initTip	- initialization for tooltip.
//		Global variables for tooltip. 
//		Set styles
//		Set up mousemove capture if tipFollowMouse set true.
////////////////////////////////////////////////////////////
var tooltip, tipcss;
function initTip() {
	if (nodyn) return;
	tooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = tooltip.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		tipcss.width = tipWidth+"px";
		tipcss.fontFamily = tipFontFamily;
		tipcss.fontSize = tipFontSize;
		tipcss.color = tipFontColor;
		tipcss.backgroundColor = tipBgColor;
		tipcss.borderColor = tipBorderColor;
		tipcss.borderWidth = tipBorderWidth+"px";
		tipcss.padding = tipPadding+"px";
		tipcss.borderStyle = tipBorderStyle;
	}
	if (tooltip&&tipFollowMouse) {
		document.onmousemove = trackMouse;
	}
}

window.onload = initTip;

/////////////////////////////////////////////////
//  doTooltip function
//			Assembles content for tooltip and writes 
//			it to tipDiv
/////////////////////////////////////////////////
var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link
function doTooltip(evt,num) {
	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	// set colors if included in messages array
	if (messages[num][2])	var curBgColor = messages[num][2];
	else curBgColor = tipBgColor;
	if (messages[num][3])	var curFontColor = messages[num][3];
	else curFontColor = tipFontColor;
	if (ie4||ie5||ns5) {
		var tip = startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr;
		tipcss.backgroundColor = curBgColor;
	 	tooltip.innerHTML = tip;
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}

var mouseX, mouseY;
function trackMouse(evt) {
	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	if (tipOn) positionTip(evt);
}

/////////////////////////////////////////////////////////////
//  positionTip function
//		If tipFollowMouse set false, so trackMouse function
//		not being used, get position of mouseover event.
//		Calculations use mouseover event position, 
//		offset amounts and tooltip width to position
//		tooltip within window.
/////////////////////////////////////////////////////////////
function positionTip(evt) {
	if (!tipFollowMouse) {
		standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
		mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
		mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	}
	// tooltip width and height
	var tpWd = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip 
	if ((mouseX+offX+tpWd)>winWd) 
		tipcss.left = mouseX-(tpWd+offX)+"px";
	else tipcss.left = mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		tipcss.top = winHt-(tpHt+offY)+"px";
	else tipcss.top = mouseY+offY+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

function hideTip() {
	if (!tooltip) return;
	t2=setTimeout("tipcss.visibility='hidden'",100);
	tipOn = false;
}

document.write('<div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100"></div>')
