﻿// JavaScript Document

function Inint_AJAX()
{
	try{return new ActiveXObject( "Msxml2.XMLHTTP" );}
	catch ( e ){};
	try{return new ActiveXObject( "Microsoft.XMLHTTP" );}
	catch ( e ){};
	try{return new XMLHttpRequest();}
	catch ( e ){};
	alert( "XMLHttpRequest not supported" );
	return null;
};
function chkSelectVote(url,width,height){
	var vForm = document.frmContest;	
	var vCode = document.frmContest.vCode;
	var vCodeTop = document.frmContest.vCodeTop;
	var vLink;
	var vCheck = false;
	var m;	
	for (m=0; m<vForm.length; m++) {
		if(vForm.elements[m].checked==true){
			vCheck = true;
			vLink = url+'?Vote='+vForm.elements[m].value+'&vCode='+vCode.value+'&vCodeTop='+vCodeTop.value;
		}
	}
	if(vCheck == false){
		alert("กรุณาเลือกหมายเลขที่คุณต้องการโหวตให้คะแนนด้วยค่ะ ");
	}
	else{		
		if((vCode.value=="") && (vCodeTop.value=="")){
			alert("กรุณาใส่ตัวเลขที่คุณเห็นด้วยค่ะ");
			vCode.focus();
		}
		else{
			///parent.window.reload();
			var wleft = (screen.width - width) / 2;
			var wtop = (screen.height - height) / 2;
			
			vwindow = window.open(vLink, 'x','toolbar=0 ,width='+width+' ,height='+height+',scrollbars=yes');
			vwindow.resizeTo(width, height);
			vwindow.moveTo(wleft, wtop);
			window.location.reload();
			vwindow.focus();
			/*var xhtmlHttp = Inint_AJAX();
			var url = "include/chkCode.php?vCode="+vCode.value+"&date="+new Date().getTime() + '' + Math.random();
			xhtmlHttp.onreadystatechange = function(){
				if (xhtmlHttp.readyState==4) {
					if (xhtmlHttp.status==200) {						
						var vdoc=xhtmlHttp.responseText;
						if(vdoc=="true"){
							var wleft = (screen.width - width) / 2;
							var wtop = (screen.height - height) / 2;
							
							vwindow = window.open(vLink, 'x','toolbar=0 ,width='+width+' ,height='+height+'');
							vwindow.resizeTo(width, height);
							vwindow.moveTo(wleft, wtop);
							vwindow.focus();
						}
						else{
							alert("กรุณาตรวจสอบตัวเลขที่คุณเห็นด้วยค่ะ");
						}
					}
				}
			}
			xhtmlHttp.open("GET",url,true);
			xhtmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
			xhtmlHttp.send(null);*/
		}
	}
}
function windowself(url){
	parent.window.location=url;
}
function popupwindow(url,width,height){
	var vCode = document.frmContest.vCode;
	if(vCode.value!=""){
		vLink = url+'&vCode='+vCode.value
		var wleft = (screen.width - width) / 2;
		var wtop = (screen.height - height) / 2;		
		vwindow = window.open(vLink, 'x','toolbar=0 ,width='+width+' ,height='+height+',scrollbars=yes');
		vwindow.resizeTo(width, height);
		vwindow.moveTo(wleft, wtop);
		window.location.reload();
		vwindow.focus();		
	}
	else{
		alert("กรุณาใส่ตัวเลขที่คุณเห็นด้วยค่ะ");
		vCode.focus();
	}	
}
function showClip(url){
	var height = 370;
	var width = 420;
	var wleft = (screen.width - width) / 2;
	var wtop = (screen.height - height) / 2;	
	vwindow = window.open(url, 'x','toolbar=0 ,width='+width+' ,height='+height+',left='+wleft+',top='+wtop+',scrollbars=no');
	vwindow.moveTo(wleft, wtop);
	vwindow.focus();
	return false;
}
function popupresule(url,width,height){
	var wleft = (screen.width - width) / 2;
	var wtop = (screen.height - height) / 2;
	vwindow = window.open(url, 'x','toolbar=0 ,width='+width+' ,height='+height+',scrollbars=yes');
	vwindow.resizeTo(width, height);
	vwindow.moveTo(wleft, wtop);
	vwindow.focus();
}
//-----------------open new window------------------------//
function newwindow_blank(url){
	window.open(url.href);
}
function window_close(url){
	window.close(url.href);
}
function newwindow_self(url){
	window.location.href=url.href;
}
function newwindow_url(url){
	window.location.href=url;
}
