/*

   Define any JavaScript functions that are specifically for this market segment
   
   
*/

/*
  Name : SetupEventBindings
  Author: Thuraisamy Sivapatham
  Description: This functionality is needed to cater for the old CCR and ORMS form links that are accessed from
  Reference manager web site, in addition to providing pop up functionality on the reference manager web site
  Reason : Called to setup any even bindings on the page
*/

function setupEventBindings()
{
	var arrDocumentATags = document.getElementsByTagName('A');
	var arrHost = location.host;
  
	if ( arrDocumentATags )
    {
		for ( var i = arrDocumentATags.length - 1; i >= 0; i--)
		{	
			
			if (arrDocumentATags[i].href)
			{
				
				//handle  NEW CCR links
				if (arrDocumentATags[i].href.toLowerCase().indexOf('/scripts/forms/ccr') >=0) 
				{

						//alert('link is   '+ arrDocumentATags[i].href);
						arrDocumentATags[i].href = "/" + arrDocumentATags[i].href.toLowerCase().substr(arrDocumentATags[i].href.toLowerCase().indexOf('/scripts/forms/ccr'));          
						arrDocumentATags[i].attachEvent('onclick', popupFormActivated);
						//arrDocumentATags[i].onclick = popupFormActivated;
						//alert('link is   '+ arrDocumentATags[i].href);
					
				} 
		
				//handle orms forms
				else  if  (arrDocumentATags[i].href.toLowerCase().indexOf('orms/tools/forms') >= 0) 
				{
						//alert('link is    '+  arrDocumentATags[i].href);
						arrDocumentATags[i].href =  "/scripts/popupforms/default.asp?ormsurl=" + arrDocumentATags[i].href.toLowerCase().substr(arrDocumentATags[i].href.toLowerCase().indexOf('/orms/tools/forms'));          
						arrDocumentATags[i].attachEvent('onclick', popupFormActivated);
						//arrDocumentATags[i].onclick = popupFormActivated;
						//alert('link is    '+  arrDocumentATags[i].href);
				} 
				//handle orms forms
				else  if  (arrDocumentATags[i].href.toLowerCase().indexOf('/scripts/forms/orms') >= 0) 
				{
						//alert('link is    '+  arrDocumentATags[i].href);
						arrDocumentATags[i].href = "/scripts/popupforms/default.asp?ormsurl=" + arrDocumentATags[i].href.toLowerCase().substr(arrDocumentATags[i].href.toLowerCase().indexOf('/scripts/forms/orms'));          
						arrDocumentATags[i].attachEvent('onclick', popupFormActivated);
						//arrDocumentATags[i].onclick = popupFormActivated;
						//alert('link is    '+  arrDocumentATags[i].href);
				} 
				else if  (arrDocumentATags[i].href.toLowerCase().indexOf('popupwin=true') >= 0) 
				{
						//alert('link is   '+ arrDocumentATags[i].href);
						arrDocumentATags[i].href = "/scripts/popupforms/default.asp?url=" + arrDocumentATags[i].href;
						arrDocumentATags[i].attachEvent('onclick', popupFormActivated);
						//arrDocumentATags[i].onclick = popupFormActivated;
						//alert('link is   '+ arrDocumentATags[i].href);
				}
				else if (arrDocumentATags[i].href.toLowerCase().indexOf('scripts/popupforms') >= 0) 
				{
					arrDocumentATags[i].attachEvent('onclick', popupFormActivated);
				}
			}  //end of if     
		 } //end of for loop
	}
     
	try 
	{  
		if (arrPlacements && document.all )
		{
			for (var iLoop = arrPlacements.length - 1; iLoop >= 0; iLoop--)
    		{
    			var objAnchor; 
				var objImage; 
				var objDiv;
				var objHiddenDiv;      
        
				var arrCodes = arrPlacements[iLoop].split('_');
                 
				// alert(' length ' +  arrCodes.length  + ' ' + arrPlacements[iLoop]);  
				if (arrCodes.length == 4 && document.all('pwa' + arrPlacements[iLoop])) 
				{
					objAnchor = document.all('pwa' + arrPlacements[iLoop]);
					objImage = document.all('pwi' + arrPlacements[iLoop]);
					objDiv = document.all('pwdiv' + arrPlacements[iLoop]); 
					objHiddenDiv = document.all('h' + objDiv.id);    
              
					objDiv.innerHTML = objHiddenDiv.innerHTML;
					objDiv.className = 'PWShowLvl3';
					objImage.removeNode();
					if ( objAnchor.parentNode.className == 'PWMinor' ) 
					{
						objAnchor.removeNode(true);
					}
					else
					{
						objAnchor.removeNode(false);
					}

				} //end of if        
			}//end of for loop
        
		} //end if
	} //end of try
	catch(e)
    {
    } 
  }//end of function
  

/*
  Name : SetupEventBindings
  Reason : Called to setup any even bindings on the page
*/

function popupFormActivated()
  {
  var objSrcNode = event.srcElement;
  if ( objSrcNode.tagName.toLowerCase() != 'a' )
  {
	objSrcNode = objSrcNode.parentNode;
  }
  
  myWin(objSrcNode.href);
  return false;
  }
  
function myWin(theUrl)
{ 
	var winNum
  var scrWidth = Math.floor(screen.availWidth / 2) - 15;
	var newWin
  
	//AUTHOR: Leonard Jayasinghe -30.04.02.
	winNum = Math.random()

	//The winNum is a long decimal figure (a random fig between 0 and 1)
	//This will enable to pop up a new window each time even the same link is clicked.
	//However, the function cannot handle it if it is a more than nine figure decimal
	//Hence we round it off.  Ooch ! it will be rounded off to 0 or 1 only
	//To get a unique no. each time we multiply it by 100 or better by 1000 and THEN round it off
	winNum=Math.round(winNum*1000)
  
  if ( theUrl.indexOf('http') < 0)
    {   
            theUrl = 'http://' + location.host + theUrl 
               
    }  
    
    //Change the window size according to scrn resolution:
	if(screen.height== 600 && screen.width==800)
	{
		newWin = open(theUrl, winNum, "Width=" + scrWidth + ",Height=460,status=1,top=20%,left=100%,scrollbars=yes,toolbar=yes,menubar=no,location=no,resizable=yes")
	}
	else //for 768 x 1024 resolution:
	{
		newWin = open(theUrl, winNum, "Width=" + scrWidth + ",Height=625,status=1,top=50%,left=300%,scrollbars=yes,toolbar=yes,menubar=no,location=no,resizable=yes")
	}
	
		//scrWidth = 510;
		
		//newWin = open(theUrl, winNum, "Width=" + scrWidth + ",Height=725,status=1,top=200%,left=300%,scrollbars=yes,toolbar=yes,menubar=no,location=no,resizable=no")

}
  