// JavaScript Document
function allcheck(obj,main){
	for(var i=0; i < obj.elements.length ; i++){		
		if(main.checked==true){
			obj[i].checked=true;
		}else{
			obj[i].checked=false;
		}
	}
}


function Del(obj){
	var status=false;
	for(var i=0 ; i < obj.elements.length ; i++ ){
		if(obj[i].type=='checkbox'){
			if(obj[i].checked==true){
				status=true;
			}
		}
	}
	if(status==false){
		alert('Please check one or more.');
		return false;
	}else{
		if(confirm("Are you sure ?"))
			return true;
		else
			return false;
	}
}

function ConfirmDel(links){
	if(confirm('Are you sure?')){
		location=links;
	}
}

function newwin(URLStr,width, height)
{
	  var popUpWin=0;
	  var left = (screen.width/2) - width/2;
	  var top = (screen.height/2) - height/2;
	  if(popUpWin)
	  {
		  if(!popUpWin.closed) popUpWin.close();
	   }
	   popUpWin = open(URLStr, 'popUpWin', 'toolbar=0,location=0,directories=0,status=0,menub ar=0,scrollbars=1,resizable=0,copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function addbookmark(){
	var bookmarkurl="http://www.i-p-p-c.com"
	var bookmarktitle="  IPPC International Precision Products Co.Ltd"
    if (document.all)
    	window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function ChangeLang(url,lang){
	var checklang;
	var start=url.indexOf('?');
	var option=url.substr(start); //alert(option); return;
	
	if(option!="?"){
		checklang="&";
	}else {
		checklang="";
	}	
	
	if(option=="http://www.i-p-p-c.com/")
		checklang="?";
	
	if(url.indexOf("lang") == -1){
		if(lang=='th'){
			option=option+checklang+"lang=th";
		}else if(lang=='en'){
			option=option+checklang+"lang=en";
		}
	}else{
		if(lang=='th'){
			option=option.replace("lang=en","lang=th");
		}else if(lang=='en'){
			option=option.replace("lang=th","lang=en");
		}
	}
	location=option;
}

var xmlHttp;
function createXmlHttp(){
	var xml = new Array();
	xml[0] = "MSXML2.XMLHTTP.5.0";
	xml[1] = "MSXML2.XMLHTTP.4.0";
	xml[2] = "MSXML2.XMLHTTP.3.0";
	xml[3] = "MSXML2.XMLHTTP";
	xml[4] = "Microsoft.XMLHTTP";
	xml[5] = "WinHttp.WinHttpRequest.5";
	xml[6] = "WinHttp.WinHttpRequest.5.1";
	if (window.ActiveXObject) {
		for (var i=0; i<xml.length; i++) {
			try {
				xmlHttp = new ActiveXObject(xml[i]);
				break;
			} catch(e) {
				xmlHttp = null;
			}
		}
	} else if(window.XMLHttpRequest) {
		try {
			xmlHttp = new XMLHttpRequest();
		} catch(e) {
			xmlHttp = null;
		}
	}
}


function startRequest() {
     createXmlHttp();
	 var detail=document.frm.gbook.value;
	 var idfrom=document.frm.idfrom.value;
	 var idto=document.frm.idto.value;
	 if(detail==''){
	 	alert('Please enter your message.');
		document.frm.gbook.focus();
		return;
	 }
	 var url="action_vote.php?id="+id+"&what="+detail+"&idto="+idto;
	 //alert(url);
     xmlHttp.open('GET', url, true);
     xmlHttp.onreadystatechange = function() { 
          if (xmlHttp.readyState==4) {
               if (xmlHttp.status==200) {
                    document.getElementById("lastpost").innerHTML=xmlHttp.responseText; 
					document.frm.gbook.value="";
					alert('Thank you.');
					
               }
          }
     };
    // req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); /
     xmlHttp.send(null);
};