var sDivName="";

function toggle(div_id) {
	var el = document.getElementById(div_id);
	
	if ( el.style.display == 'none' ) 
	{	   
        var tmp = "show('" + div_id + "')";
	    //eval("setTimeout(" + tmp + ",300)");
	    eval(tmp);

	    if(div_id=='blanket')
	        opacity(div_id,0,80,300);
	    else
	        opacity(div_id,0,100,300);
	}
	else
	{
	    if(div_id=='blanket') 
	        opacity(div_id,80,0,300);
	    else
	        opacity(div_id,100,0,300);
	        
	    
	    var tmp = "hide('" + div_id + "')";
	    //eval("setTimeout(" + tmp + ",600)");
	    setTimeout("eval("+tmp+")",300);
	}
}



function dim(div_id) {
	opacity(div_id,100,80,2000);
}

function show(div_id)
{
    //alert(div_id);
    var el = document.getElementById(div_id);
    el.style.display = 'block';
    //alert('/show');
}

function hide(div_id)
{
    //alert(div_id);
    var el = document.getElementById(div_id);
    el.style.display = 'none';
    //alert('/hide');
}


function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		//viewportwidth = window.innerHeight;
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	} else {
		//viewportwidth = document.documentElement.clientHeight;
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	var popUpWidth = popUpDiv.offsetWidth;
	var popUpHeight = popUpDiv.offsetHeight;
	window_width=window_width/2-(popUpWidth/2);//150 is half popup's width
	viewportheight=viewportheight/2-(popUpHeight/2);//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
	popUpDiv.style.top = viewportheight + 'px';
	//alert(popUpDiv.offsetWidth);
}
function popup(windowname,status) {

    if(status=='first')
    {
	    blanket_size(windowname);
        document.body.style.display="block";
	    //show('blanket');
	    dim('blanket');
	    toggle(windowname);	
	    window_pos(windowname);
	 }
	 else
	 {
	    blanket_size(windowname);
	    toggle('blanket');
	    toggle(windowname);	
	    window_pos(windowname);
	 }
	
}

function opacity(id, opacStart, opacEnd, millisec) 
{ 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) 
    { 
        for(i = opacStart; i >= opacEnd; i--) 
        { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        }         
    }   
    else if(opacStart < opacEnd) 
    {       
        for(i = opacStart; i <= opacEnd; i++) 
        { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
        } 
    
    }  
} 


function opacityold(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        //alert('dolj');
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
        for(i = 70; i >= 100; i++) { 
            setTimeout("changeOpac(" + i + ",'blanket')",(timer * speed*2)); 
            timer++; 
        } 
        var tmp = "popup('" + id + "')";
        //alert(tmp);
        eval("setTimeout(tmp,300)");
        
    } else if(opacStart < opacEnd) { 
        //alert('visa');
        eval("popup('" + id + "')");
        
        for(i = opacStart; i <= opacEnd; i++) 
        { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
        } 
        for(i = 100; i <= 70; i--) 
        { 
            setTimeout("changeOpac(" + i + ",'blanket')",(timer * speed*2)); 
            timer++;
        } 
    } 

} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
}
    
    
    
function processAjax(url) {

    if (window.XMLHttpRequest) { // Non-IE browsers
        req = new XMLHttpRequest();
        req.onreadystatechange = targetDiv;
        try {
            req.open("GET", url, true);
        } 
        catch (e) {
            alert(e);
        }
        req.send(null);
    } 
    else if (window.ActiveXObject) { // IE
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = targetDiv;
            req.open("GET", url, true);
            req.send();

        }
    }
}

function targetDiv() {
    if (req.readyState == 4) { // Complete
        if (req.status == 200) { // OK response
            document.getElementById(sDivName).innerHTML = req.responseText;
        } 
        else {
            alert("Problem: " + req.statusText);
        }
    }
} 
