
function ArrangeCells(DocObj)
{	
	var IDPrefix 	= "view:_id1:";
	var StrCategory	= DocObj.getElementById(IDPrefix + "Category").innerHTML;
	
	if(StrCategory == "magazine")
	{
		var TblObj = document.getElementById("view:_id1:viewPanel1");
		if (TblObj)
		{		
			TblObj.width="680px";
			TblObj.border="0";
			var ArrRows = TblObj.rows;
		
			if (ArrRows.length > 2)
			{
				for (k=1; k < ArrRows.length; k+=2)
				{			
					OddRow = ArrRows[k];			
					OddCell = OddRow.children[0];			
					EvenRow = ArrRows[k+1];		
					if (EvenRow)
					{
						EvenCell = EvenRow.children[0];									
						$(OddCell).insertAfter(EvenCell);				
					}				
				}
				TblObj.deleteTHead();
				for (k=0; k < TblObj.rows.length; k++)
				{
					if(TblObj.rows[k].children.length ==0)
					{	
						TblObj.deleteRow(k);
					}
				}		
			}	
		}
	}
	else
	{
		
		var TblObj = document.getElementById("view:_id1:viewPanel1");
		if (TblObj)
		{
			//TblObj.border="1"
			TblObj.width="100%"
			ArrChildTbl =TblObj.getElementsByTagName("table");
			for(k = 0;k<ArrChildTbl.length;k++)
			{
				ArrChildTbl[k].rows[0].cells[0].removeAttribute("style");
			}	
		}
	}
}	
function OnLoadScript()
{	
	$(".list li, .itemsList div").hover(
		  function () {
			$(this).addClass("itemsListhover1");
			$("a", this).addClass("linkHover");
		  },
		  function () {
			$(this).removeClass("itemsListhover1");
			$("a", this).removeClass("linkHover");
		  }
		);
		
		$(".itemsList .divvvv").hover(
		  function () {
			$(this).addClass("itemsListhover3");
			$("a", this).addClass("linkHover");
		  },
		  function () {
			$(this).removeClass("itemsListhover3");
			$("a", this).removeClass("linkHover");
		  }
		);
		
	  $(".res-Featured").hover(
		  function () {
			$(".save",this).addClass("itemsListhover2");
			$("a", this).addClass("linkHover");
		  },
		  function () {
			$(".save",this).removeClass("itemsListhover2");
			$("a", this).removeClass("linkHover");
		  }
	  );
	  $(".res-Featured").hover(
		  function () {
			$(".play",this).addClass("itemsListhover4");
			$("a", this).addClass("linkHover");
		  },
		  function () {
			$(".play",this).removeClass("itemsListhover4");
			$("a", this).removeClass("linkHover");
		  }
	  );
	  
	  $(".res-Featured").hover(
		  function () {
			$(".register",this).addClass("itemsListhover5");
			$("a", this).addClass("linkHover");
		  },
		  function () {
			$(".resiter",this).removeClass("itemsListhover5");
			$("a", this).removeClass("linkHover");
		  }
	  );
	/*
	$(".list, .res-Featured").click(function(){
	     window.location=$(this).find("a").attr("href");
	     return false;
	  });
      $(".list td").hover(
		  function () {
			$(this).addClass("itemsListhover1");
			$("a", this).addClass("linkHover");
		  },
		  function () {
			$(this).removeClass("itemsListhover1");
			$("a", this).removeClass("linkHover");
		  }
		);
	  $(".res-Featured").hover(
		  function () {
			$(".save",this).addClass("itemsListhover2");
			$("a", this).addClass("linkHover");
		  },
		  function () {
			$(".save",this).removeClass("itemsListhover2");
			$("a", this).removeClass("linkHover");
		  }
	  );
	  */    
}
function ClearResults()
{
	var IDPrefix 	= "view:_id1:";
	var StrEmail 	= (document.getElementById(IDPrefix + "Email").innerHTML);
	var StrReferrer = (document.getElementById(IDPrefix + "Referrer").innerHTML);
	var StrCategory = (document.getElementById(IDPrefix + "Category").innerHTML);
	if (StrCategory == "")
	{
		var StrURL = "fEduResources?Openform&Email=" + StrEmail + "&SygSource=" + StrReferrer;	
	}
	else
	{
	
		var StrURL = "xpListPage.xsp?Category=" + StrCategory.replace("&amp;","%26") + "&Email=" + StrEmail + "&SygSource=" + StrReferrer;
	}
	location.href = StrURL;
}

function Search()
{
	var frm = document.forms[0];
	// http://isgdev.synygy.net/SIMS/websubs.nsf/xpListPage.xsp?Category=whitepaper 
	var IDPrefix 	= "view:_id1:";
	var SearchStr = (document.getElementById(IDPrefix + "SearchText").value);
	var StrEmail = (document.getElementById(IDPrefix + "Email").innerHTML);
	var StrReferrer = (document.getElementById(IDPrefix + "Referrer").innerHTML);
	var StrCategory = (document.getElementById(IDPrefix + "Category").innerHTML);
/*	if (StrCategory =="")
	{
		StrCategory = "Whitepaper";
	}
	*/
	if (SearchStr == "")
	{
		return false; 
	}
	if (StrCategory =="")
	{
		var StrURL = "xpListPage.xsp?search=" + SearchStr + "&Email=" + StrEmail + "&SygSource=" + StrReferrer;
	}
	else
	{
		var StrURL = "xpListPage.xsp?Category=" + StrCategory.replace("&amp;","%26") + "&search=" + SearchStr + " and " + StrCategory + "&Email=" + StrEmail + "&SygSource=" + StrReferrer;
	}	
	location.href = StrURL;
}
function RemoveFirstRow(docObj)
{

	var TblObj = docObj.getElementById("view:_id1:viewPanel1_OUTER_TABLE");
	if(TblObj)
	{
		if(TblObj.rows.length >1)
		{
			TblObj.deleteRow(0);
		}	
	}
}
function ReplaceURL1(docObj)
{
	
	var IDPrefix 	= "view:_id1:";	//XPage appends this prefix to the field name.
	var usrEmail 	= docObj.getElementById(IDPrefix + "Email").innerHTML;
	var StrDomain 	= docObj.getElementById(IDPrefix + "Domain").innerHTML;
	var strLE	 	= docObj.getElementById(IDPrefix + "LeadExists").innerHTML;
	var Server 		= docObj.getElementById(IDPrefix + "ServerName").innerHTML;
	var DBName 		= docObj.getElementById(IDPrefix + "DBName").innerHTML;	
	var StrReferrer	= docObj.getElementById(IDPrefix + "Referrer").innerHTML;
	var DivObj 		= docObj.getElementById("Content");
	var StrHref 	= "";
	var StrShortName = "";
	var ArrATagsObj;
	
	var ArrATagsObj = docObj.getElementsByTagName("a");
	for(var j = 0; j < ArrATagsObj.length; j++)
	{
		var StrHref = ArrATagsObj[j].href;				
		if(StrHref.match("dummy") != null)	// Consider a tags which has dummy in the href
		{			
			StrShortName =ArrATagsObj[j].id;			 		
			if(usrEmail == "" || strLE == "N")			// if email is blank or if the leaddoc for that email doesnt exist.
			{
				// redirect user to registration page and set the target to same window;
				ArrATagsObj[j].target = "_top";
				StrURL = StrDomain + "/register.html?ShortName=" + StrShortName + "&SygSource=" + StrReferrer;  
			}
			else
			{
				// redirect user to download agent and set the target to new window.
				ArrATagsObj[j].target = "_blank";
				StrURL = Server + "/" + DBName + "/aUpdateDwnldActivitiesNew?OpenAgent&Email=" + usrEmail + "&SName=" + StrShortName + "&SygSource=" + StrReferrer; 
			}
			ArrATagsObj[j].href = StrURL;
		}
	}	
}

function ReplaceURL(docObj)
{
	
	var IDPrefix 	= "view:_id1:";	//XPage appends this prefix to the field name.
	var usrEmail 	= docObj.getElementById(IDPrefix + "Email").innerHTML;
	var StrDomain 	= docObj.getElementById(IDPrefix + "Domain").innerHTML;
	var strLE	 	= docObj.getElementById(IDPrefix + "LeadExists").innerHTML;
	var Server 		= docObj.getElementById(IDPrefix + "ServerName").innerHTML;
	var DBName 		= docObj.getElementById(IDPrefix + "DBName").innerHTML;	
	var StrReferrer	= docObj.getElementById(IDPrefix + "Referrer").innerHTML;
	
	
	var DivObj 		= docObj.getElementById("Content");
	var StrHref 	= "";
	var StrShortName = "";
	var StrRegReqd = "";
	var ArrATagsObj;
	var DwnldURL;
	
	var ArrATagsObj = docObj.getElementsByTagName("a");
	for(var j = 0; j < ArrATagsObj.length; j++)
	{
		var StrHref = ArrATagsObj[j].href;				
		if(StrHref.match("dummy") != null)	// Consider a tags which has dummy in the href
		{
			
			SetURL(Server, DBName, StrDomain, ArrATagsObj[j], usrEmail, strLE, StrReferrer);
		/*
			StrRegReqd = strLeft(ArrATagsObj[j].id, "~");		
			StrShortName = strRight(ArrATagsObj[j].id, "~");
			//alert(StrRegReqd + " = " + StrShortName + " = " + StrHref)
			DwnldURL = Server + "/" + DBName + "/aUpdateDwnldActivitiesNew?OpenAgent&Email=" + usrEmail + "&SName=" + StrShortName + "&SygSource=" + StrReferrer; 
			if (StrRegReqd == "No")
			{				
				ArrATagsObj[j].target = "_blank";
			//	StrURL = Server + "/" + DBName + "/aUpdateDwnldActivitiesNew?OpenAgent&Email=" + usrEmail + "&SName=" + StrShortName + "&SygSource=" + StrReferrer;
				StrURL = DwnldURL;
			}
			else
			{
				if(usrEmail == "" || strLE == "N")	// if email is blank or if the lead doc for that email doesnt exist.
				{
					// redirect user to registration page and set the target to same window;
					ArrATagsObj[j].target = "_top";
					StrURL = StrDomain + "/register.html?ShortName=" + StrShortName + "&SygSource=" + StrReferrer;  
				}
				else
				{
					// redirect user to download agent and set the target to new window.
					ArrATagsObj[j].target = "_blank";
					// StrURL = Server + "/" + DBName + "/aUpdateDwnldActivitiesNew?OpenAgent&Email=" + usrEmail + "&SName=" + StrShortName + "&SygSource=" + StrReferrer;
					StrURL = DwnldURL; 
				}				
			}
			//alert("URL = " + StrURL);
			ArrATagsObj[j].href = StrURL;	
			*/
		}
	}	
}
function SetURL(StrServer, StrDBName, StrDomain, ATagObj, UserEmail, StrLeadExists, StrReferrer)
{
	var StrRegReqd = strLeft(ATagObj.id, "~");		
	var StrShortName = strRight(ATagObj.id, "~");
	
	//alert(StrRegReqd + " = " + StrShortName + " = " + StrHref)
	var DwnldURL = StrServer + "/" + StrDBName + "/aUpdateDwnldActivitiesNew?OpenAgent&Email=" + UserEmail + "&SName=" + StrShortName + "&SygSource=" + StrReferrer; 
	if (StrRegReqd == "No")
	{				
		ATagObj.target = "_blank";
		//	StrURL = Server + "/" + DBName + "/aUpdateDwnldActivitiesNew?OpenAgent&Email=" + usrEmail + "&SName=" + StrShortName + "&SygSource=" + StrReferrer;
		StrURL = DwnldURL;
	}
	else
	{
		if(UserEmail == "" || StrLeadExists == "N")	// if email is blank or if the lead doc for that email doesnt exist.
		{
			// redirect user to registration page and set the target to same window;
			ATagObj.target = "_top";
			StrURL = StrDomain + "/register.html?ShortName=" + StrShortName + "&SygSource=" + StrReferrer;  
		}
		else
		{
			// redirect user to download agent and set the target to new window.
			ATagObj.target = "_blank";
			// StrURL = Server + "/" + DBName + "/aUpdateDwnldActivitiesNew?OpenAgent&Email=" + usrEmail + "&SName=" + StrShortName + "&SygSource=" + StrReferrer;
			StrURL = DwnldURL; 
		}				
	}
	//alert("URL = " + StrURL);
	ATagObj.href = StrURL;	
}
