// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true
}


function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showHideLayers() { //v6.0
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function popMove(aLayer)
{
	document.getElementById(aLayer).style.top = tempY-20; 
	document.getElementById(aLayer).style.left = tempX+15;
}

function popOver(aLayer)
{
	document.getElementById(aLayer).style.top = tempY-20; 
	document.getElementById(aLayer).style.left = tempX+15;
	showHideLayers(aLayer,'','show');
}

function popOut(aLayer)
{
	showHideLayers(aLayer,'','hide');
}


function showTable(theTable)
{
     if (document.getElementById(theTable).style.display == 'none')
     {
          document.getElementById(theTable).style.display = 'block';
     }
}
function hideTable(theTable)
{
     if (document.getElementById(theTable).style.display == 'none')
     {
          document.getElementById(theTable).style.display = 'none';
     }
     else
     {
          document.getElementById(theTable).style.display = 'none';
     }
}


function showHideDiv(theDiv)
{
     if (document.getElementById(theDiv).style.display == 'none')
     {
          document.getElementById(theDiv).style.display = 'block';
     }else
	 {
          document.getElementById(theDiv).style.display = 'none';
		 
	 }
}


 var ie= ((document.all)&&(!document.layers)) ? true : false;
 var ns= ((document.layers)&&(!document.getElementById)) ? true : false;
 var moz= ((document.getElementById)&&(!document.all)) ? true : false;

function showLayers(div) { //v0.1
   alert('showLayer' + div + '\n ie=' + ie + '\n ns=' + ns + '\n moz=' + moz);

  if(ie) {document.all[div].style.visibility="visible";}
  if(ns) {document.layers[div].visibility="show";}
  if(moz) {document.getElementById(div).style.visibility="visible";}

}

function hideLayers(div) { //v0.1
  if(ie) (document.all[div].style.visibility="hidden")
  if(ns) (document.layers[div].visibility="hide")
  if(moz) (document.getElementById(div).style.visibility="hidden")

} 


function hideElementById( aElement )
{
	document.getElementById(aElement).style.display	= 'none' ;

}
function showElementById( aElement )
{
	document.getElementById(aElement).style.display	= '' ;

}

function showHideElementById( aElementShow, aElementHide )
{
	document.getElementById(aElementHide).style.display	= 'none' ;
	document.getElementById(aElementShow).style.display	= '' ;
}

function CreateBookmarkLink(title, url) 
{
	alert("TEST");
	if (window.sidebar) 
	{
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");	
	} 
	else if( window.external ) 
	{ 
		// IE Favorite		
		window.external.AddFavorite( url, title); 
	}	
	else if(window.opera && window.print) { 
		// Opera Hotlist		
		return true; 
	} 
} 	

function makeLowCase( aTextBox )
{
	var szText = aTextBox.value;
	var lastchar = " ";
	var rText = "";
	
		
	var lastchar;
	
	lastchar = szText.substr(0, 1);
	rText = "";
	for(i = 1; i <= szText.length; i++)
	{

		newchar = szText.substring(i-1, i);
		
		if((lastchar != " ")&&(i > 1)&&(lastchar != ".")&&(lastchar != ":")&&(lastchar != ".")&&(lastchar != ";")&&(lastchar != "\""))
			newchar = newchar.toLowerCase();
				
/*		if(newchar == "o")&&(i < szText.length)
		{
			nextchar = szText.substring(i, i+1);
			if((nextchar == ".")||(nextchar == ":")||(nextchar == ".")||(nextchar == ";")||(nextchar == " ")||(nextchar == ""))
				newchar = "o";
		}
*/		
		rText+= newchar;
		
		lastchar = newchar;
		
		//else alert( "[" + szText.substr(szText.length-2,szText.length-1) + "]");
	}

	
	aTextBox.value = rText;

}

function showElement(theElement)
{
   getElementByID_Name(theElement).style.display = 'block';
}


function hideElement(theElement)
{
   getElementByID_Name(theElement).style.display = 'none';
}

function getElementByID_Name( objectname )
{
	if(document.getElementById( objectname ) == null)
		return document.getElementsByName( objectname )[0];
	else
		return document.getElementById( objectname );
}


function wizInit( aSets, aStepLabels, aSubmitButtons )
{

		var msg = '';
		
	    this.arrSets = aSets.split(';');
		this.submitButtons = aSubmitButtons;
		this.arrStepLabels = aStepLabels.split(';');
		
		getElementByID_Name( 'wizTotalSteps' ).value = arrSets.length;

		arrSet = arrSets[0].split(',');

		for(var b=0; b < arrSet.length; b++)
		{
			showElement( arrSet[b] );
			msg+="showElement(" + arrSet[b] + ")\n";
		}
		for(var i = 1; i < arrSets.length; i++)
		{
			arrSet = arrSets[i].split(',');
	
			for(var b=0; b < arrSet.length; b++)
			{
				hideElement ( arrSet[b] );
				msg+="hideElement(" + arrSet[b] + ")\n";
			}

		}
		
		getElementByID_Name( 'wizStep' ).value = 1;

		this.totalSteps = arrSets.length;
		this.curStep = 0;
		
		hideElement( 'wizPrevButton' );
		hideElement( submitButtons );

		if(arrStepLabels[0] != "")
			stepLabel = " - " + arrStepLabels[0];
		else
			stepLabel = "";
			
		getElementByID_Name('wizStepTitle').innerHTML = "ÂÇÌÁ 1" + stepLabel;


}


function wizNextStep( )
{	
	
	msg = "";

	with(this)
	{
		
			if( this.curStep < this.totalSteps-1 )
			{
				arrSet = this.arrSets[this.curStep].split(',');
		
				for(var b=0; b < arrSet.length; b++)
				{
					hideElement ( arrSet[b] );
					msg+="hideElement(" + arrSet[b] + ")\n";
				}

				this.curStep++;

				showElement('wizPrevButton');
				if(curStep == totalSteps-1)
				{
					hideElement('wizNextButton');
					showElement( submitButtons );
				}
					
				arrSet = this.arrSets[this.curStep].split(',');
		
				for(var b=0; b < arrSet.length; b++)
				{
					showElement ( arrSet[b] );
					msg+="hideElement(" + arrSet[b] + ")\n";
				}

				getElementByID_Name( 'wizStep' ).value = this.curStep + 1;

				if(arrStepLabels[curStep] != "")
					stepLabel = " - " + arrStepLabels[curStep];
				else
					stepLabel = "";
					
				getElementByID_Name('wizStepTitle').innerHTML = "ÂÇÌÁ " + (this.curStep + 1) + stepLabel;

			}
			

	}
}

function wizPrevStep( )
{
	msg = "";

	with(this)
	{
		
			if( this.curStep > 0  )
			{
				arrSet = this.arrSets[this.curStep].split(',');
		
				for(var b=0; b < arrSet.length; b++)
				{
					hideElement ( arrSet[b] );
					msg+="hideElement(" + arrSet[b] + ")\n";
				}

				this.curStep--;
				
				hideElement( submitButtons );
				showElement('wizNextButton');
				if(curStep == 0)				
					hideElement('wizPrevButton');

				arrSet = this.arrSets[this.curStep].split(',');
		
				for(var b=0; b < arrSet.length; b++)
				{
					showElement ( arrSet[b] );
					msg+="hideElement(" + arrSet[b] + ")\n";
				}

				getElementByID_Name( 'wizStep' ).value = this.curStep + 1;

				if(arrStepLabels[curStep] != "")
					stepLabel = " - " + arrStepLabels[curStep];
				else
					stepLabel = "";
					
				getElementByID_Name('wizStepTitle').innerHTML = "ÂÇÌÁ " + (this.curStep + 1) + stepLabel;

			}

	}
}

