// JavaScript Document
function ___isnumber(obj){
	obj.value = ___number(obj.value);
}
function ___number(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 ___email(obj){
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	return emailRegExp.test(obj.value);
}
function ___quesionnew(scid,pid,page){
	var url='../../includes/vs_question.php?scid='+scid+'&pid='+pid+'&page='+page;
	window_open(url, 600, 400, 'yes', 'normal');
}
function ___answernew(scid,pid,qid,page){
	var url='../../includes/vs_answer.php?scid='+scid+'&pid='+pid+'&qid='+qid+'&page='+page;
	window_open(url, 600, 400, 'yes', 'normal');
}
function ___search(){
	var choose = document.searchfrm.choose.value;
	var keyword = document.searchfrm.keyword.value;
	var category = document.searchfrm.category.value;
	var supply = document.searchfrm.supply.value;
	var price = document.searchfrm.price.value;
	var linkpath='./?show=search&choose='+choose+((keyword!='') ? '&key='+keyword:'');
	if(choose<2){
		linkpath += '&cgy='+category+'&spl='+supply+'&prc='+price;
	}
	document.location.replace(linkpath);
}
function load_supply_list(){
	if(supply_list==null){
		return false;
	}
	else{
		var obj = document.searchfrm.supply;
		if(remove_listbox(obj)){ 
			var category_id = document.searchfrm.category.value;
			var index=0;
			for(var i=0; i < supply_list.length; i++){
				if(supply_list[i][0]==category_id){
					index++;
					var text = supply_list[i][2];
					obj.options[index] =  new Option(text, supply_list[i][1]);
				}	
			}
			if(obj.options.length>1){
				obj.options[1].selected=true;
			}
		}
	}
}
function remove_listbox(obj){
	while(obj.length != 1){
		obj.remove(1);
	}
	return true;	
}
function ___chooseSearch(obj){
	if(document.getElementById('searchArea')!=null){
		document.getElementById('searchArea').style.visibility=((obj.value<2) ? 'visible':'hidden');
	}
}
function ___subcategory(sid){
	document.location.replace('./?show=category&scid='+sid);
}
function ___product(act){
	document.location.replace('./?show=products&flr='+act);
}
function ___detail(scid, id, page){
	document.location.replace('./?show=detail&scid='+scid+'&id='+id+'&page='+page);
}
function ___detail_s(scid, id, page){
	document.location.replace('./?show=detail&scid='+scid+'&id='+id);
}

function ___submenu(id){
	if(document.getElementById(id+'sub')!=null){
		document.getElementById(id+'sub').style.display='block';
	}
}
function ___printnew(id){
	window.open('./printer.php?id='+id,"PRINTER");
}
function ___sendmail(id){
	document.location.replace('./?show=sendnews&id='+id);
}

var last_click;             // zuletzt angeklickter Button
var windows = new Array();  // Array mit Win-Objekten
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) {
   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) {
   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) {
   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 thumbnail(pathlink, w, h){
	if((w > 0)&&(h > 0)){
		if(w > screen.width)
			w = screen.width;
		if(h > screen.height)
			h = screen.height;
		window_open(pathlink, w, h,'yes','normal');
	}
}

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_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_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];}
}
function show( targets ){
	var target_list = targets.split(',');
	for(var i = 0 ; i < target_list.length; i++ ){
		if(document.getElementById( target_list[i])!=null){
			document.getElementById( target_list[i] ).style.display="block";
		}
	}
}

function hide( targets ){
	var target_list = targets.split(',');
	for(var i = 0 ; i < target_list.length; i++ ){
		if(document.getElementById( target_list[i])!=null){
			document.getElementById( target_list[i]).style.display="none";
		}
	}
}

//hien thi gio hang ben phai cua trang web
function ___showshoppingcart(p_obj_name, p_gap_point){ 
	var start_point, end_point, timer; 
	
	var obj_layer   = document.getElementById(p_obj_name);  // ·¹ÀÌ¾î ¿ÀºêÁ§Æ®
	
	start_point = parseInt(obj_layer.style.top, 10); 
	
	if ( start_point < p_gap_point )    start_point = p_gap_point;

	end_point   = document.body.scrollTop + p_gap_point; 
	limit_point = parseInt(window.document.body.scrollHeight) - parseInt(obj_layer.offsetHeight) -10; 
	
	if ( end_point > limit_point )  end_point = limit_point; 
	
	if ( start_point != end_point ) 
	{ 
		scroll_amount = Math.ceil( Math.abs( end_point - start_point ) / 15 ); 
		obj_layer.style.top = parseInt(start_point, 10) + ( ( end_point < start_point ) ? -scroll_amount : scroll_amount ); 
	} 

	timer = window.setTimeout ("___showshoppingcart('" + p_obj_name + "', " + p_gap_point + ");", 1); 
} 
