// JavaScript Document
var curWidth = 0, curHeight = 0, curTop=0, curLeft=0;

function mousePos(e,rw) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	if (rw == 'x'){
		return posx;
	}else{
		return posy;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
}
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id, newx, newy) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

	

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = parseInt(newx);
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = parseInt(newy);

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;
	var once = 0;
  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;

//	 x = 1500;
  //  y = 900;	  
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;

  }

/*	if (x >900 && x< 1000)
		x = 1500;
	if (y >500 && y< 700)
		y = 900;	*/	

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
	

}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

function loadwin(maincontainer, container, datacontainer){
	var host = document.getElementById(maincontainer);
	var content = document.getElementById(container);
	var target = document.getElementById(datacontainer);
	host.style.visibility = 'visible';
	content.innerHTML = target.innerHTML;
	host.style.zIndex = 100;
}

function closewin(winid){
	if (document.getElementById('pagesW')){
		SetContents('');
	}
	
	var host = document.getElementById(winid);
	host.style.visibility = 'hidden';
	e = document.getElementById( 'idMainContainer' );
	e.style.backgroundColor="#ffffff";				
	enableDivs(winid);	
}




function maximizewin(winid){
	  var myWidth = 0, myHeight = 0;
	  var divWidth = document.getElementById(winid).style.width;
	  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;
	  }	
	  //alert(myWidth+' '+divWidth.substring(0,divWidth.length-2));
  	 if ((myWidth-5) > divWidth.substring(0,divWidth.length-2)){
/*	 	 curWidth = document.getElementById(winid).style.width;
	  	 curHeight =document.getElementById(winid).style.heigh;	*/
	  	 document.getElementById(winid).style.width= (myWidth-5)+'px';
	  	 document.getElementById(winid).style.height= myHeight+'px';
	   	 document.getElementById('wContainer').style.height= (myHeight-120)+'px';	  
		 document.getElementById(winid).style.left= '0px';		    
		 document.getElementById(winid).style.top= '0px';		 
	 }else{
		 //alert (curWidth+' '+curHeight);
	  	 document.getElementById(winid).style.width= curWidth+'px';
	  	 document.getElementById(winid).style.height= curHeight+'px';
	   	 document.getElementById('wContainer').style.height= (curHeight-120)+'px';	  
		 document.getElementById(winid).style.left= curLeft+'px';		    
		 document.getElementById(winid).style.top= curTop+'px';		 
	 }
	
}

function openwin(winid){
	var host = document.getElementById(winid);
	host.style.visibility = 'visible';	
	host.style.zIndex = 99;	
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame
	currentElement = document.getElementById(id);
	currentElement.style.opacity = 0;
    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++; 
        }		
    } 
} 

//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); 
    } 
}

cDivs = new Array();
function disableDivs(winid)
{
d = document.getElementsByTagName("BODY")[0];
/*for(x=0;x<arguments.length;x++)
{
    if (document.getElementById(arguments[x]))
    {*/
/*    xPos = document.getElementById(arguments[x]).offsetLeft;
    yPos = document.getElementById(arguments[x]).offsetTop;*/
	//alert(winid);
    cDivs[winid] = document.createElement("DIV");
    cDivs[winid].style.width = document.body.offsetWidth + "px";
    cDivs[winid].style.height = document.body.offsetHeight + "px";
    cDivs[winid].style.position = "absolute";
    cDivs[winid].style.left = "0px";
    cDivs[winid].style.top = "0px";
    cDivs[winid].style.backgroundColor = "#ffffff";
    cDivs[winid].style.opacity = .6;
    cDivs[winid].style.filter = "alpha(opacity=60)";

    d.appendChild(cDivs[winid]);
    //}
//}
document.getElementById("pdlanguage").style.visibility='hidden';

}


function enableDivs(winid)
{
	
//for (i=0;i<cDivs.length;i++){
	//alert(winid);
	document.getElementsByTagName("BODY")[0].removeChild(cDivs[winid]);
//}
//cDivs = [];
document.getElementById("pdlanguage").style.visibility='visible';
}