// JavaScript Document

var doDrag=false;
var dragPopupDiv="";


function closePopup(popWndDiv)
{
	document.getElementById(popWndDiv).style.display='none';	    
	    createCookiePop('currencyPopupState','close',1);
}


function togglePopup(popWndDiv,buttonDiv)
{
   if(document.getElementById(popWndDiv).style.display=='block')
      {
        document.getElementById(popWndDiv).style.display='none';	    
	    createCookiePop('currencyPopupState','close',1);
      }
      else
      {
        document.getElementById(popWndDiv).style.display='block';	    
	    createCookiePop('currencyPopupState','open',1);
	    /*
	    var topVal=document.getElementById(buttonDiv).style.top;
	    var topV=0;
	    if(topVal.indexOf('px')!=-1)
	    {
	      topV=topVal.substring(0,topVal.indexOf('px'));
	      document.getElementById(popWndDiv).style.top=(topV-105)+'px';
	    }
	    else if(topVal.indexOf('%')!=-1)
	    {
	       topV=topVal.substring(0,topVal.indexOf('%'));
	       document.getElementById(popWndDiv).style.top=(topV-2)+'%';
	    }
	    
	    document.getElementById(popWndDiv).style.display='block';
	    */
	  
      }
	
}



function dragging(e)
{
	var x;
	var y;
	
	if(dragPopupDiv!="" && doDrag==true)
	{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
        x=window.event.clientX;
        y=window.event.clientY;
		//alert("x :"+x+" y:"+y);
		/*coords = "X = " + window.event.clientX + " Y = " + window.event.clientY;*/


		/*document.getElementById('stat').innerHTML=coords;*/
		document.getElementById(dragPopupDiv).style.top=y+'px';
		document.getElementById(dragPopupDiv).style.left=x+'px';
    }
	else
	{
			//	alert("x :"+x+" y:"+y);
			
			
         x=e.pageX;
         y=e.pageY;
		/* coords = "X = " + e.pageX + " and Y =" + e.pageY;
         document.getElementById('stat').innerHTML=coords; */

 		document.getElementById(dragPopupDiv).style.top=y+'px';
		document.getElementById(dragPopupDiv).style.left=x+'px';

    }
	}
}


/*function dragPopup(popWndDiv)
{
	var x;
	var y;
	popWindow=document.getElementById(popWndDiv);
	if(dragPopupDiv==popWndDiv && doDrag==true)
	{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
        x=window.event.clientX;
        y=window.event.clientY;
		//alert("x :"+x+" y:"+y);
		document.getElementById('stat').innerHTML="x :"+x+" y:"+y;
		popWindow.style.top=y;
		popWindow.style.left=x;
    }
	else
	{
			//	alert("x :"+x+" y:"+y);
			document.getElementById('stat').innerHTML="x :"+x+" y:"+y;
         x=e.pageX;
         y=e.pageY;
 		popWindow.style.top=y;
		popWindow.style.left=x;

    }
	}
	
}*/

function regDrag(popWndDiv)
{
	document.onmousemove = dragging;
	document.onmouseup = unregDrag;
			//alert("reg");
	dragPopupDiv=popWndDiv;
	doDrag=true;
}

function unregDrag(e)
{
				//alert("unreg");
   if(dragPopupDiv!="" && doDrag==true)
	{
	dragPopupDiv="";
	doDrag=false;
	document.onmousemove = null;
	}
}

function checkForPopupState(popWndDiv)
{

if(readCookiePop('currencyPopupState')!=null && readCookiePop('currencyPopupState')!='close')
  {   
     document.getElementById(popWndDiv).style.display='block';	
  }
  else
  {
     document.getElementById(popWndDiv).style.display='none';
  }  

}




function checkForCurrencyPreference()
{ 

  var selectCurr=document.currencyConverterForm.currToSel;
  if(readCookiePop('preferCurrencyCode')!=null)
  {    
    var indexi=parseInt(readCookiePop('preferCurrencyCode'));
    selectCurr.options[indexi].selected = true; 
  }  
}

function setCurrencyPreference()
{ 
    var selectCurr=document.currencyConverterForm.currToSel;
    if(readCookiePop('preferCurrencyCode')==null ||(selectCurr.selectedIndex+'')!=readCookiePop('preferCurrencyCode'))
	  {    
	    createCookiePop('preferCurrencyCode',selectCurr.selectedIndex+'',1);	    
	  }  
    
}


function createCookiePop(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookiePop(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookiePop(name) {
	createCookie(name,"",-1);
}




