
// Opens a pop-up when the function is called.
 function openPopUp(url,navStatus,name,height,width) {
 	//Opens the popup window.
	var newwindow;
	newwindow=window.open(url,name,'height='+height+',width='+width+',scrollbars='+navStatus+',toolbar='+navStatus+',menubar='+navStatus+',status=yes');
	
}


 //Populates the parameters to be passed for Page Tagging and returns in the form of a url.
 function getPageTaggingParameters(pgLbel,pageType,pageView,lobName, testCell, cusSegment, cusExp){

	//Retrieving the Page Context. 	
 	var page = bea.wlp.disc.context.Page.findByLabel(pgLbel);
 	
 	//Retriving the LOB name from the Page Context.
	 var lob = lobName;

 	//Retriving the Portlets Information from Page Context
 	var placables = page.getPlaceables();
 	var contentComponents= "";
 	var temp;

 	//Retriving the Portlet's title and position.
 	for(var i=0;i<placables.length;i++){
	
 		temp = document.getElementById("PageTagging"+placables[i].getInstanceLabel());
 			if(temp!=null){
 				if(contentComponents.length == 0){
 					contentComponents = temp.value;
 				}
 				else
 				{
 					contentComponents = contentComponents+":"+temp.value;
 				}
 				
 			}	
 		}
 	
 	//Retriving the page's Layout Information.	
 	
 	if(page.getType() == 'Book'){
            page = page.getPage();
      }     
 	
 	var layout = page.getLayout().getMarkupName();
 	var temp = 'capital_one_';
 	var index = layout.indexOf(temp);
 	 
 	layout = layout.substring(index+temp.length);
 	 
 	 
 	Pg_Tag_url = "?log=1"+
 				"&System=www"+
 				"&LOB="+lob+
 				"&TestCell="+testCell+
 				"&segment="+cusSegment+
 				"&experience="+cusExp+
 				"&PageName="+pageView+
 				"&PageType="+pageType+
 				"&Layout="+	layout+
 				"&ContentComponent="+contentComponents;
 	
 	return 	Pg_Tag_url;		
 }

	
 // Returns the TestCell value from the cookie	
 function getTestCell(Lob){
 	var lobName = Lob + "=";
 	var lobCookies = document.cookie.split(';');
 	for(var i=0;i<lobCookies.length;i++){
 		var tc = lobCookies[i];
 		while (tc.charAt(0)==' '){
 			tc = tc.substring(1,tc.length);
 		}
 		if (tc.indexOf(lobName) == 0){
 			return tc.substring(lobName.length,tc.length);
 		} 
 	}
 }	
	

//Retrieves the Parameters to be passed for Link Tagging and returns in the form of a url.

 function PopulateVSLinkData(pageId, eventType, portletInstanceLabel,contentElement, componentType, componentMetaData){

 	var pageId = pageId;
 	
 	//Retrieving the Portlet Context
 	var portletContext = bea.wlp.disc.context.Portlet.findByElement(portletInstanceLabel);
 	
 	//Retrieving the Portlet's Position.
 	var ContentComponent = portletContext.getPlaceholderPosition()+"_"+portletContext.getTitle();
 	
 	var lnk_Tg_Url = "?pageId="+pageId+
 					 "&EventType="+eventType+
 					 "&ContentComponent="+ContentComponent+
 				     "&ContentElement="+contentElement+		 
 					 "&ComponentType="+componentType;
 					 
	if(componentMetaData!=null && componentMetaData.length>0){
		lnk_Tg_Url = lnk_Tg_Url+"&ComponentMetaData="+componentMetaData;
	}
	 					 
 	return 	lnk_Tg_Url;			 	 
 }	
 
 //function to be called for tagging modal windows.
 function modalTagging(){
 	//Retrieving pageLabel,pageId,pageType from request.
	var Pg_Tag_url = null;
	var pgLbel = "${requestScope.pageDef_Label}";
	var pageId = "${requestScope.pageid}";
 	var pageType = "${requestScope.pageType}";
		
	//Making a call to the tagging javascript to tag the parameters for the pop-up window.	
	Pg_Tag_url = getPageTaggingParameters(pgLbel,pageId,pageType);
	Pg_Tag_url = "${pageContext.request.contextPath}"+Pg_Tag_url;
	
	//Making ajax call to hit the webserver.
	var xmlHttpReq = new bea.wlp.disc.io.XMLHttpRequest();
    xmlHttpReq.onreadystatechange = function() 
     {
        if (xmlHttpReq.readyState == 4) 
         {
         	if (xmlHttpReq.status == 200) {
          		var data = eval('(' + xmlHttpReq.responseText.toString() + ')');
	        	}
	        	else {
	    	    }
    	   	}
      	};
	    xmlHttpReq.open('GET', Pg_Tag_url, true);
      	xmlHttpReq.send(null);
 }
 
 // TO-DO
 function breakingOutOfFrames() {

      if (top.location != location) {
      top.location.href = document.location.href;
   }
}
 