/**********************************************************
 *                                                        *
 *  Copyright &copy;2005  Corillian Corporation                *
 *                                                        *
 *  All rights reserved.                                  *
 *                                                        *
 *  Highly Confidential.                                  *
 *                                                        *
 *  No portion of this code may be reproduced,            *
 *  transmitted or distributed without the express        *
 *  written permission of Corillian Corporation.          *
 *                                                        *
 **********************************************************/
 
function PopupGuideLines(pageUrl)
{			
	var int_windowLeft = (screen.width - 630) / 2;
	var int_windowTop = (screen.height - 500) / 2;
		
	var popupAttributes = 'width=625px,height=500,left=' + int_windowLeft.toString() +',top=' + int_windowTop.toString() + ',screenX=0,screenY=0,status=yes,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no';		
	helpWindow = window.open(pageUrl, 'CORIGUIDELINES', popupAttributes);
	helpWindow.focus();
}

/* TODO: Please remove this function and call the above one once Rewards is implemented */
function Popupwin(val)
{	
	var pageUrl;
	if (val == 2)
		pageUrl = 'RedeemAwards.htm';
	else
		pageUrl = 'RewardsSummary.htm';
	
	var int_windowLeft = (screen.width - 630) / 2;
	var int_windowTop = (screen.height - 500) / 2;
  	
	var popupAttributes = 'width=625px,height=500,left=' + int_windowLeft.toString() +',top=' + int_windowTop.toString() + ',screenX=0,screenY=0,status=yes,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no';		
	helpWindow = window.open(pageUrl, 'CORIGUIDELINES', popupAttributes);
	helpWindow.focus();
	return;
}

function doClose()
{
	try{
		window.open('','_parent',''); 
		window.close();
	}
	catch(err){
		// Do Nothing
	}
}
	
function openCheckImageWindow(url)
{
	var ciw;
	if(ciw != null)
	{
		ciw.close(); 
	}
	ciw = window.open(url, 'CORICHECKIMAGE', 'width=608,height=500,left=0,top=0,status=yes,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,copyhistory=no');
	ciw.focus();
}
	
function PopupHelp(pageUrl)
{				
	var popupAttributes = 'width=625px,height=420,left=0,top=0,screenX=0,screenY=0,status=yes,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no';		
	helpWindow = window.open(pageUrl, 'CORIHELP', popupAttributes);
	helpWindow.focus();
}

function Popup(pageUrl)
{				
	var popupAttributes = 'width=625px,height=500,left=0,top=0,screenX=0,screenY=0,status=yes,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no';		
	popupWindow = window.open(pageUrl, 'CORIPOPUP', popupAttributes);
	popupWindow.focus();
}

function PopupWithFileMenu(pageUrl)
{				
	var popupAttributes = 'width=625px,height=500,left=0,top=0,screenX=0,screenY=0,status=yes,scrollbars=yes,resizable=yes,toolbar=no,menubar=yes,location=no';		
	popupWindow = window.open(pageUrl, 'CORIPOPUP', popupAttributes);
	popupWindow.focus();
}


///Function to Print the  <Div> Content to the Printer.
function printField(divname) {
	
		try{
		var dctl =	document.getElementById(divname);	
		if (dctl == null)
			return false;
		pWin = window.open('CaptialONE','pWin','location=false, menubar=yes, height = 500, width=500,  toolbar=yes, scrollbars=yes'); 
		if (pWin == null)
			return false;
		pWin.document.open(); 
		pWin.document.write('<html><head></head><body>'); 
		pWin.document.write(dctl.innerHTML); 
		pWin.document.write('</body></html>'); 
		pWin.print(); 
		pWin.document.close(); 
		pWin.close(); 
		}
		catch(err)
		{
			return;
		}
		return;
}

function doPrint()
{
	try{
		window.print();
	}
	catch(err){
		// Do Nothing
	}
}

/*
Function textBoxLimit is used for the Key Press event 
for the text box or text area : When a key is pressed this function checks if 
the total number of characters typed equals the limit given by the property 
maxLength for the field. If the limit is reached then it return false thus not 
allowing any further key press event.
*/

function textBoxLimit(textBoxObjid,maxLength,spnCntId) {
	var textBoxObj = document.getElementById(textBoxObjid);
	textBoxCount(textBoxObjid,spnCntId,maxLength);
	if (textBoxObj.value.length==maxLength*1) return false;
}

/*Function is used for the Key Up event : 
We use this to change the value of the counter displayed and to truncate the 
excess characters if any (example if someone has cut and pasted the value into 
the field when we have allowed paste). We use the inner text 
property of the span element to change the counter displayed. 
*/
function textBoxCount(textBoxObjId,spnCntId,maxLength) { 
	var textBoxObj = document.getElementById(textBoxObjId);
	var spnCnt = document.getElementById(spnCntId);
	if (spnCnt == null || textBoxObj == null)
		return;
	if (textBoxObj.value.length>maxLength*1) 
	{
		textBoxObj.value=textBoxObj.value.substring(0,maxLength*1);
		//alert(textBoxObj.value);
	}
	if (spnCnt != null) 
	{
		spnCnt.value=maxLength-textBoxObj.value.length;
	}
}

function ShowHideToolTip(toolTipId)
{
	var toolTipObj = document.getElementById(toolTipId);
	if(toolTipObj.style.visibility =="hidden" )
		toolTipObj.style.visibility ="visible";
	else
		toolTipObj.style.visibility ="hidden";
}


function toggleSearchResults(excerpts, contentpanel,mainImage,CollapsedImage,ExpandedImage,
 resultId, catName, url,defCount,catNo,catResCnt,IsURL,IsEOS)
{

  var pnlExcerpts = document.getElementById(excerpts);   	
  var pnlContent=document.getElementById(contentpanel);
  var imgMain=document.getElementById(mainImage);
  var imgCollapsed=document.getElementById(CollapsedImage);
  var imgExpanded=document.getElementById(ExpandedImage);
  var defResult;
  var temp;
  var temp1;
  
 // alert(url.length);
  //alert(catName);
  if(!pnlContent)return true;
	
	if(IsEOS == 'True')
	{	
		//alert("isurl");
		window.location.href = url;
	}
	else if(catName == 'WWW' && url.length > 0)
	{
		//alert("catName");
		PopupBalanceTransfer(url);
	}
	else if(IsURL == 'False' && imgMain != null && imgMain.src == imgCollapsed.src && url.length > 0)
	{
		//alert("IsURL false");
		PopupBalanceTransfer(url);
	}
	if(pnlContent.style.display=="none")
	{
		if(pnlContent.id.indexOf('ctlDefResult') >= 0)
		{
			for(i=0;i<defCount;i++)
			{
				//alert(defCount);
				defResult = 'ctlDefResult_' + i + '_pnlContent';
				temp = 'ctlDefResult_'+i+'_pnlExcerpts';
				temp1 = 'ctlDefResult_' + i + '_pnlTitle';
				img = 'ctlDefResult_'+i+'_imgMain';
				//alert(defResult);	
				//alert(pnlContent.id);				
				if( pnlContent.id != defResult)
				{
					//alert("cmg in if");		
					if(document.getElementById(defResult) != null)						
						document.getElementById(defResult).style.display="none";
					//alert("cmg in defResult");	
					if(document.getElementById(temp1) != null)
						document.getElementById(temp1).style.display="block";
					//alert("cmg in temp1");
					if(document.getElementById(temp) != null)
						document.getElementById(temp).style.display="block";
					//alert("cmg in temp");
					
					//alert(document.getElementById(img).src);
					if(document.getElementById(img) != null && document.getElementById(img).src != null)
					{						
						document.getElementById(img).src = imgCollapsed.src;					
					}
								
				}
			}	
				
		}
		if(pnlContent.id.indexOf('ctlCat') >= 0 )//&& catName != 'WWW'
		{
			//alert("cmg in if1");
			//for(i=0;i<catNo;i++)
			//{
				for(j=0;j<catResCnt;j++)
				{
					//alert(catResCnt);
					defResult =	'ctlCat'+catNo+'_Result'+j+'_pnlContent';	
					temp = 'ctlCat'+catNo+'_Result'+j+'_pnlExcerpts';
					temp1 = 'ctlCat'+catNo+'_Result'+j+'_pnlTitle';
					img = 'ctlCat'+catNo+'_Result'+j+'_imgMain';
					//alert(pnlContent.id);
					//alert(defResult);
					if(pnlContent.id != defResult)
					{
						var defRes = document.getElementById(defResult);
						var tempRes = document.getElementById(temp);
						
						if(defRes != null)						
							defRes.style.display="none";
						if(temp1 != null)
							document.getElementById(temp1).style.display="block";
						if(tempRes != null)
							tempRes.style.display="block";
						if(document.getElementById(img) != null)
							document.getElementById(img).src =imgCollapsed.src;	
					}
				}
			//}
		}
		//alert(pnlContent);
		//alert(pnlExcerpts);
		pnlContent.style.display="block";    
		pnlExcerpts.style.display="none";
		if(imgMain != null)
			imgMain.src =imgExpanded.src;
		
	
		RecordClick(resultId);
	} 
	else 
	{			
		pnlContent.style.display="none";
		pnlExcerpts.style.display="block";
		imgMain.src =imgCollapsed.src;
	}
	//}
  
  return true;
}

/********************************/

/* Search */




/**********/
function toggleMe(groupName,a,b,c,d)
{
	//Collapse all the items in the group
	
		
	
  var e=document.getElementById(a);
  var imgMain=document.getElementById(b);
  var imgCollapsed=document.getElementById(c);
  var imgExpanded=document.getElementById(d);
  
  if(!e)return true;
 
  if(e.style.display=="none")
  {
    //Collapse all the other items 
	CollapseItemsInGroup(groupName,b);
	
    e.style.display="block"    
    imgMain.src =imgExpanded.src;
    
   
  } 
  else 
  {
	e.style.display="none"	
	imgMain.src =imgCollapsed.src;
  }
  return true;
}

function CollapseItemsInGroup(groupName,mainImageName)
{
	//alert(groupName.length);
	
	//Get the name of the workflow control if available(two underscores are present)
	var firstPosition = mainImageName.indexOf("_");
	var secondPos = mainImageName.indexOf("_", firstPosition + 1);
	var strTemp;
	var ctlWorkflow;
	
	if(secondPos!=-1)
	{
		strTemp = mainImageName.split("_");
		ctlWorkflow = strTemp[0];
	}
	
	for( var i=0 ; i < groupName.length; i++ )
	{
		strTemp = groupName[i].split("_");
		var ctlUserControl = strTemp[0];
		
		var e=document.getElementById(groupName[i]);
		e.style.display="none";
		//debugger;
		
		var imgMain;
		var imgCollapsed;
		
		if(secondPos!=1)
		{
			imgMain = ctlWorkflow + "_" + ctlUserControl + "_imgMain";
			imgCollapsed = ctlWorkflow + "_" + ctlUserControl + "_imgCollapsed";
		}
		else
		{	
			imgMain =  ctlUserControl + "_imgMain";
			imgCollapsed = ctlUserControl + "_imgCollapsed";
		}
		
		//Change the main image since we are collapsing all
		e = document.getElementById(imgMain);
		e.src = document.getElementById(imgCollapsed).src;
			
	
	}
	
}


/**********/


					

/**
* @returns A string which specifies which is the current
* browser in which we are running.
*
* Currently-supported browser detection and codes:
* * 'opera' -- Opera
* * 'msie' -- Internet Explorer
* * 'safari' -- Safari
* * 'firefox' -- FireFox
* * 'mozilla' -- Mozilla
*
* If we are unable to property identify the browser, we
* return an empty string.
*
* @type String
*/
function getBrowserName() {
		var browserName = "";
		var ua = navigator.userAgent.toLowerCase();
		if ( ua.indexOf( "opera" ) != -1 ) {
			browserName = "opera";
		} 
		else if ( ua.indexOf( "msie" ) != -1 ) {
			browserName = "msie";
		} 
		else if ( ua.indexOf( "safari" ) != -1 ) {
			browserName = "safari";
		} 
		else if ( ua.indexOf( "mozilla" ) != -1 ) 
		{
			if ( ua.indexOf( "firefox" ) != -1 ) {
				browserName = "firefox";
				} 
			else 
				{
					browserName = "mozilla";
				}
		}
		return browserName;
}

/***************************************************************************************************
//
// Display of internal controls 
//
//
****************************************************************************************************/

// Tooltip functions
var timerID = 0;
var currentTooltip = '';
var tooltipDelay = 500; //the number of milliseconds before the active tooltip disappears when rolled out

function showTooltip(theTip,theLink) {

	if(currentTooltip != theTip && currentTooltip != ''){
		hideTooltip();
	}

	//get the left pointer element
	var strTemp = theTip.substring(theTip.indexOf('_')+1)
	//alert(strTemp);
	var leftPointer = document.getElementById("ttPointerDivLeft_" + strTemp);
	var rightPointer = document.getElementById("ttPointerDivRight_" + strTemp);
	
	var imgpos = document.getElementById(theLink);
	var displayat = getObjCoords(imgpos);
	var initialX = displayat.x
	var initialY = displayat.y
	if ( (displayat.x + 10 + 310) > 765 )
	{
		displayat.x = displayat.x - 355;
		leftPointer.style.display = "none";
		rightPointer.style.left = "333" + "px";
		rightPointer.style.top = "0" + "px";
	}
	else
	{
		rightPointer.style.display = "none";
	}
	document.getElementById(theTip).style.left = (displayat.x + 10) + "px";
	document.getElementById(theTip).style.top = displayat.y + "px";
	currentTooltip = theTip;
	document.getElementById(theTip).style.display = 'block';
	//document.getElementById(theTip).style.left = document.getElementById(theLink).offsetLeft + document.getElementById(theLink).offsetWidth + 5 + "px";
	//document.getElementById(theTip).style.top = document.getElementById(theLink).offsetTop - 0 + "px";

	if(timerID) {
		clearTimeout(timerID);
	}

}

function tooltipTimer(){

	if(timerID) {
		clearTimeout(timerID);
	}
	
	timerID = setTimeout("hideTooltip()", tooltipDelay);

}

function hideTooltip() {

	document.getElementById(currentTooltip).style.display = 'none';
	
	if(timerID) {
		clearTimeout(timerID);
		timerID = 0;
	}

}

function resetTooltipTimer(){
	
	if(timerID) {
		clearTimeout(timerID);
		timerID = 0;
	}
	
}



function Point(x, y) {
this.x = x;
this.y = y;
}

function getObjCoords(o) {
var oX = 0;
var oY = 0;
if (o.offsetParent) {
while (1) {
oX+=o.offsetLeft;
oY+=o.offsetTop;
if (!o.offsetParent) {
break;
}
o=o.offsetParent;
}
} else if (o.x) {
oX+=o.x;
oY+=o.y;
}
//alert(oX + \":\" + oY);
return new Point(oX, oY);
}

// function to handle Enter key submits - 
function keyPressHandler(evnt) 
{
	if (document.layers) 
	{
		keycd = evnt.which; 
	}
	else
	{  
		if (document.all) 
		{
			evnt = window.event; 
			keycd = evnt.keyCode; 
		} 
	}
	if (keycd==13)
	{ 
		// If ENTER key is pressed, see if the DEFAULT_BUTTONID is set
		if (DEFAULT_BUTTONID == '')
		return;
		var bt = document.getElementById(DEFAULT_BUTTONID); 
		if (bt == null)
			return;
		else
		{
			bt.click();
		}
	}
} 



