// Global Variable


//status bar
/* Timer */
var hour=0;
var min =0;
var sec =0;

function timer() {
 // var _status = "Your have been on "+default_page_name+" for: ";
  var _status = "ยินดีต้อนรับสู่  Website NokAir";
  if (++sec>59) {
    if (++min>59) {
      hour++;
      min=0;
    }
   sec=0;
  }
  var _min=min>9?min:"0"+min;
  var _sec=sec>9?sec:"0"+sec;
  var _hour=hour>9?hour:"0"+hour;
//  _status += _hour+":"+_min+":"+_sec;
  top.window.status = _status;
}

var myTimer=null;
var ONE_SECOND = 1000;
function startTimer() {
  endTimer();
  myTimer = setInterval("timer()",ONE_SECOND);
}
function endTimer() {
  if (myTimer != null) {
    clearInterval(myTimer);
	myTimer = null;
  }
}

function page_load_state(val)
{
	var tmp="";
	if(val<100)
	{
		tmp = "Loading ["
		for(i=0;i<=val;i++)tmp += "|";
		for(i=val+1;i<=100;i++)tmp +="-";
		tmp += "]"
	}else{
		tmp = "Loading page complate..."
		startTimer();
	}
	top.window.status = tmp+" ("+ val +"%)";
}	


window.onload = write_date;
function write_date(){
	var d=new Date();
	var weekday=new Array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
	var monthname=new Array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
	var wdate = weekday[d.getDay()] + "ที่ ";
	var dd = d.getDate();
	dd = dd.toString();
	var ld = dd.substr(dd.length);
	 wdate += dd + " ";
	wdate += monthname[d.getMonth()] + " ";
	wdate += "พ.ศ." + ((d.getFullYear()) + 543);
	var dateDiv = document.getElementById('date_show');
	if(dateDiv)
	{
		dateDiv.innerHTML = "<font class='clock_box'>"+"วัน"+wdate+"</font>";
	}
}

function WinPopUp2(url,name,arg,w,h){
	url = escape(url);
	url = "/s1000_obj/global/Popup/winpopup.asp?url="+url;
	return window.showModalDialog(url,arg,'dialogWidth:'+w+'px;dialogHeight:'+h+'px;resizable:no;unadorned:1;help:no;status:0;');
}
function WinPopUp(url,name,arg,w,h){
	url = escape(url);
	url = "/s1000_obj/global/Popup/winpopup.asp?url="+url;
	var winstate='toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width='+w+',height='+h;
	var aPopup=window.open(url,name,winstate);
	aPopup.focus();
}
function PopUp_Gallery(url,name,w,h){
	var winstate='toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h;
	aPopup=window.open(url,name,winstate);
	aPopup.focus();
}
function print_content_detail(content_id,page_no) {
	var w_win = "600px";
	var h_win = "500px";
	var name_win = "print_detail";
	var host_name = window.location.hostname;
	var script_file_print = "/s1000_obj/content_obj/content_frame/print_content_detail.asp?content_id=" + content_id + "&page_no=" + page_no + "&host_name=" + host_name;
	var win_o = 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w_win+',height='+h_win;
	print_win = window.open(script_file_print,name_win,win_o);
	print_win.focus();
}
function email_content_detail(content_id,page_no) {
	var w_win = "600px";
	var h_win = "500px";
	var name_win = "email_detail";
	var host_name = window.location.hostname;
	var script_file_mail = "/s1000_obj/content_obj/content_frame/email_content_detail.asp?content_id=" + content_id + "&page_no=" + page_no + "&host_name=" + host_name;
	var win_o = 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w_win+',height='+h_win;
	mail_win = window.open(script_file_mail,name_win,win_o);
	mail_win.focus();
}
function Center_Win(){
	var x_center=0;
	var y_center=0;
	if (document.all)
	{
		x_center = (screen.availWidth*1/4);
		y_center = (screen.availHeight*1/6);
	}else if (document.layers||document.getElementById)
	{
		x_center = ((screen.availWidth/2) - (top.window.outerWidth/2));
		y_center = (screen.availHeight/2) - (top.window.outerHeight/2);
	}
	if(x_center<0)x_center=0;
	if(y_center<0)y_center=0;
	top.window.moveTo(x_center,y_center);
}

function xslnext(){
	var total_page = document.all("total_page");
	var current_page = document.all("current_page");
		//--- check config
	var now_url = document.location.href;
	var check_question_mark; 
	var check_sharp;
	check_question_mark =  now_url.indexOf('?');
	if (check_question_mark != -1) // no ?
	{
		
		check_sharp = now_url.indexOf('#');

		if (check_sharp == -1) // no sharp sign
		{
			document.location.href = document.location.href+"#";
		}

	}
	//------- End check Config ///
	if ((current_page)&&(total_page))
	{
		if (eval(current_page.value)<eval(total_page.value))
		{
			xslgo(eval(current_page.value)+1,eval(total_page.value));
		}
	}
	
}

function xslprev(){
	var current_page = document.all("current_page");
		var total_page = document.all("total_page");
		//--- check config
	var now_url = document.location.href;
	var check_question_mark; 
	var check_sharp;
	check_question_mark =  now_url.indexOf('?');
	if (check_question_mark != -1) // no ?
	{
		check_sharp = now_url.indexOf('#');
		if (check_sharp == -1) // no sharp sign
		{
			document.location.href = document.location.href;+"#";
		}
	}
	//------- End check Config ///
	if ((current_page))
	{
	
		if (eval(current_page.value)>1)
		{
		xslgo(eval(current_page.value)-1,eval(total_page.value));
		}
	}
}

function xslgo(i,total_page){
	var obj = document.all("go_page_no");
	obj.value = remove_null(obj.value);
	if (!chknum("go_page_no",true))
	{
		return;
	}
	if((i>total_page)||(i<=0))
	{
		window.alert('Page not found');
		if(obj)obj.focus();
		return;
	}
	var now = document.location.href;
	var last = now.indexOf('#');
	var last_question_mark;
	if(last!=-1)now=now.substring(0,last);
	last_question_mark = now.indexOf('?');
//	if(last_question_mark!=-1)now=now.substring(0,last);
	if(last_question_mark == -1)
	{
		now=now+"?page_no="+i
	}
	else
	{
		if (now.indexOf('&page_no=') != -1 )
		{
			now=now.substring(0,now.indexOf('&page_no='));
		}
		else
		{
		}
		now=now+"&page_no="+i
	}
	
	document.location.href=now;
}

function form_checkMail(namemail){
	
	var obj_mail = document.all(namemail);
	var x = obj_mail.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x))
	{
		return true;
	}
	else 
	{	
		window.alert("Email not correct");
		obj_mail.focus();
		return false;
	}
}

function  remove_null(nullvalue){
	var null_return;
	null_return = 	nullvalue.replace(/^\s*|\s*$/g,"");
	return null_return;
}

function chkblank(o1){
	var obj1 = document.all(o1);
	if (obj1.value=="")
	{
		o1 = o1.replace("txt_","")
		window.alert("please enter "+o1);
		if(!obj1.disabled)obj1.focus();
		return false;
	}
	else return true;
}

function isNum(str) {
  if(!str) return false;
  for(var i=0; i<str.length; i++){
    var ch=str.charAt(i);
    if ("0123456789".indexOf(ch) ==-1) return false;
  }
  return true;
} 

function chknum(obj,hid){
	obj_use = document.all(obj);
	if (!isNum(obj_use.value))
	{
	
		var name_obj_new;
		name_obj_new = obj.replace("txt_","")
		
		if (hid)
		{			
			if(!obj.disabled)obj_use.focus();
			window.alert(""+ name_obj_new +" only numeric input..!");
		}
		else
		{
			window.alert("In URL Address Parameter "+ name_obj_new +" only numeric input..!");
		}
		return false;
	}
	return true;
}

function getRandom(min,max){
   return (Math.round(Math.random()*(max-min)))+min;
}

function chksame(o1,o2){
	var obj1 = document.all(o1);
	var obj2 = document.all(o2);
if (isNum(obj2.value))
{
	obj2.value = eval(obj2.value);
}
if (isNum(obj1.value))
{
	obj1.value = eval(obj1.value);
}

	if (obj1.value == obj2.value) return true;
	else
	{
	//	window.alert(o1+" and "+o2+" not same...!");
	//	obj1.value="";
		obj2.value="";
	//	if(!obj1.disabled)obj1.focus();
		return false;
	}
}


