﻿function getBrowserXY() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight];
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX, scrOfY];
}

function JSFX_FloatDiv(id, sx, sy)
{
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 30);
	}
	return el;
}

function doClick(buttonName,e)
{
	//the purpose of this function is to allow the enter key to 
	//point to the correct button to click.
    var key;
        if(window.event)
            key = window.event.keyCode;     //IE
        else
            key = e.which;     //firefox

    if (key == 13)
    {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null)
        { //If we find the button click it
            btn.click();
            event.keyCode = 0
        }
    }
}

function doVote(frm,Qid,Type){
	if(Type=="vote"){
		var rd = frm['V' + Qid];
		var valid = false;
		var Oid;
		for (var i=0;i<rd.length;i++)
		{
			if(rd[i].checked){
				valid = rd[i].checked;
				Oid = rd[i].value;
			}
		}
		if(!valid)
		{
			alert("Bạn phải chọn một lựa chọn.")
			return;
		}else{
			//alert("Popup.aspx?Mod=ViewVote&Qid=" + Qid + "&Oid=" + Oid);
			popupWindows("Popup.aspx?Mod=ViewVoteResult&Qid=" + Qid + "&Oid=" + Oid);
		}
	}else{
		//alert("Popup.aspx?Mod=ViewVote&Qid=" + Qid);
		popupWindows("Popup.aspx?Mod=ViewVoteResult&Qid=" + Qid);
	}
}//doVote

function popupWindows(url){
	var feature = "height=300,width=450,status=0,toolbar=0,location=0,menubar=0,directories=0,";
	feature += "resizable=1,scrollbars=1,top=" + (screen.height-300)/2 + ",left=" + (screen.width-450)/2;
	window.open(url,'_blank',feature);
}//popupWindows

function popupNewWindows(url,iheight,iwidth){
	if(iheight<0){
		iheight = screen.height;
	}
	if(iwidth<0){
		iwidth = screen.width;
	}	
	var feature = "height=" + iheight + ",width=" + iwidth + ",status=0,toolbar=0,location=0,menubar=0,directories=0,";
	feature += "resizable=1,scrollbars=1,top=" + (screen.height-iheight)/2 + ",left=" + (screen.width-iwidth)/2;
	window.open(url,'_blank',feature);
}//popupWindows

function toggleLayer(whichLayer, value)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = value;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = value;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = value;
	}
}

function confirmDelete(){
	if(confirm("Bạn có chắc chắn muốn xóa không?")){
		return true;
	}else{
		return false;
	}
}

function checkAll(itemName,values){
	var str = ":" + itemName;
	var reg = new RegExp(str);
	var max = document.forms[0].elements.length;
	for(var i=0; i<max; i++){
		var obj = document.forms[0].elements[i];
		if(obj.type == "checkbox"){
			if(reg.test(obj.name)){
				obj.checked = values;
			}
		}
	}
}//checkAll

function checkItem(itemName,chkAllItem){
	var str = ":" + itemName;
	var reg = new RegExp(str);
	var max = document.forms[0].elements.length;
	var ischecked = true;
	var i = 0;
	var index = 0;
	
	while(i<max & ischecked){
		var obj = document.forms[0].elements[i];
		if(obj.type == "checkbox"){
			if(reg.test(obj.name)){
				ischecked = obj.checked;
			}
		}
		i++;
	}
	document.forms[0].elements[chkAllItem].checked = ischecked;
}//checkItem

var my_window;
function openPopup(url)
{    
    my_window = window.open(url, "mywindow", "status=0,width=500,height=515,scrollbars=yes");
}

function closePopup()
{
    try{
	    if(false == my_window.closed)
	    {
	        my_window.close();
	    }
	}catch(err){
	
	}
}