﻿// JScript File
var imgWidth = 0, imgHeight = 0;	//set chieu rong, chieu cao cho img
var iMaxWidth = 350;						//Kich thuoc lon nhan cua large image
var iMaxHeight = 150;
var exp=4, csp=8;					//Muc do tang, giam (px)
var t;
var divContainer = "DivContainer";
var objTarget = "content";
var idOfsender="";
var browser=navigator.appName;
function append(_top, _left){
    var divObj = document.getElementById(divContainer);
	if(divObj != null){
		document.body.removeChild(divObj);
	}
	divObj = document.createElement("div");
	divObj.id = divContainer;
	divObj.className="divContainer";
	divObj.style.display='none';			
	document.body.appendChild(divObj);
	if (browser=="Microsoft Internet Explorer"){
	    divObj.width = 0;
	    divObj.height = 0;
	}
	divObj.style.top=_top;
	divObj.style.left=_left;
	return divObj;
}
function zoomout(sender){
    idOfsender = sender.id;
    var pos = findPosXY(sender);
	if (browser=="Microsoft Internet Explorer"){	    	    
	    if (window.t)
		    clearInterval(t);		
	    var container = append(parseInt(pos[1])+parseInt(sender.offsetHeight), parseInt(pos[0])+parseInt(100));  //Khoi tao container neu chua co
    	
	    createContent(container, sender);		
        container.style.display="block";
	    t = setInterval("exspan()", 10);
	}
	else{
	    setVisible('layer1', pos, sender.offsetHeight);
	}
    
}
function exspan(){
	var o = document.getElementById(objTarget);
	if (parseInt(o.style.width) < iMaxWidth){
		o.style.width=parseInt(o.style.width)+exp;			
	}
	else if (parseInt(o.style.height) < iMaxHeight){
	    o.style.height=parseInt(o.style.height)+exp;
	}
	else{
	    if (window.t)
		    clearInterval(t);
		requestAndShowData("Ajax/getDetailReview.aspx?rid="+idOfsender+"&lang="+getLanguageParam("lang"),true,"oLoading","Trinh duyet khong ho tro java ajax", "Khong co thong tin", "showResult(strTemp, objTarget)");
	}
}

function requestAndShowData(src, sync, loading, msg1, msg2, pf){
    var xmlHttp;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	}
	else{
		src+="&sid="+Math.random();		
		xmlHttp.onreadystatechange = function(){
		    if (xmlHttp.readyState==4){ 
		        var strTemp=xmlHttp.responseText;
	            if(strTemp != ""){
	                if (browser=="Microsoft Internet Explorer")
	                    getObj(loading).style.display='none';
	                eval(pf);	                
	            }
	            else {
	                alert(msg2);
	                if (browser=="Microsoft Internet Explorer")	                
	                    getObj(loading).style.display='none';
                }
	        }
	        else{
	            if (browser=="Microsoft Internet Explorer")
	                getObj(loading).style.display='block';
	        }
		};
		xmlHttp.open("GET", src, sync);
	    xmlHttp.send(null);
	}
}

function conspan(){
	var o = document.getElementById(objTarget);
	if (parseInt(o.style.width) >= csp && parseInt(o.style.height) >= csp){
		o.style.width=parseInt(o.style.width)- csp;
		o.style.height=parseInt(o.style.height)- csp;
	}
	else
		document.getElementById(divContainer).style.display="none";
}
function emptyContainer(){
    document.getElementById(objTarget).innerHTML="";
	if (window.t)
		clearInterval(t);
	t=setInterval("conspan()", 5);				
}

function findPosXY(obj){
	var pos = new Array();
	pos[0] = pos[1] = 0; //pos[0]: left - pos[1]: top
	var curleft = 0;
	var curtop = 0;
	if(obj.offsetParent)
    	while(1) {
      		pos[0] += obj.offsetLeft;
      		pos[1] += obj.offsetTop;
      		if(!obj.offsetParent)
        		break;
      		obj = obj.offsetParent;
    	}
	else if(obj.x && obj.y){
    	pos[0] += obj.x;
    	pos[1] += obj.y;
   	}
	return pos;
}

function createContent(container, sender){
    var obj = document.getElementById(objTarget);
    var objbar;
    var divTitleBar = "titlebar";
    if(obj == null || obj == "undefined"){
        obj = document.createElement("div");		//Create div tag to container contetn responed from server
	    obj.id=objTarget;
	    obj.style.width=imgWidth;
	    obj.style.height=imgHeight;
	    container.appendChild(obj);
    	
        objbar = document.createElement("div");		//Create div tag to do title bar
	    objbar.id=divTitleBar;
	    var contentBar = "";
	    if (browser=="Microsoft Internet Explorer"){
	        contentBar = '<div id="name" style="text-align: right; margin: 2px"><input onclick="emptyContainer();" type="button" value="Close" style="border: 0px solid gray; cursor: pointer" /></div>';
	    }
	    else{
	        contentBar = '<div id="name" style="text-align: right; margin: 2px; width:'+iMaxWidth+'px"><input onclick="emptyContainer();" type="button" value="Close" style="border: 0px solid gray; cursor: pointer" /></div>';
        }
	    objbar.innerHTML=contentBar;
	    container.appendChild(objbar);	
    }
}

function setVisible(obj, position, s){
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';	
	requestAndShowData("Ajax/getDetailReview.aspx?rid="+idOfsender+"&lang="+getLanguageParam("lang"),true,"oLoading","Trinh duyet khong ho tro java ajax", "Khong co thong tin", "showResult(strTemp, 'contentReview')");	
	obj.style.top=parseInt(pos[1])+parseInt(s);
	obj.style.left=parseInt(pos[0])+parseInt(100);
}