﻿function GetClientId(strid)
{
     var count=document.forms[0].length ;
     var i = 0 ;
     var eleName;
     for (i = 0 ;  i < count ;  i++ )
     {
       eleName = document.forms[0].elements[i].id;
       pos=eleName.indexOf ( strid ) ;
       if(pos >= 0)  break;           
     }
    return eleName;
 }


var browserName="";
function resizeIframeToFitContent(iframe,userType) 
{ 
	browserName=navigator.appName;	
	
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		if(userType=="Broker" && iframe.src == "BrokerPage.html")
		 	 LoadIndSegments(iframe,userType);
		 else if(userType=="General" && iframe.src == "GeneralPage.html")
		 	 LoadIndSegments(iframe,userType);
		 	 
		iframe.height = document.frames[iframe.id].document.body.scrollHeight;
	}
	else
	{	
		 LoadIndSegments(iframe,userType);
		 iframe.height=document.getElementById(iframe.id).contentDocument.body.offsetHeight;	
	}

	   	   
	if(document.getElementById(iframe.id).contentWindow.document.documentElement.innerHTML.indexOf('PatentLotsGV')<0)
	{
	 	try
	 	{
			document.getElementById('emptyText').innerHTML="<b><br>Coming soon...</b>";			
		}
		catch(err)
		{}
			iframe.style.display="none";
	}
}

function resizeIframeToFitContentDD(iframe,userType) 
{ 
	browserName=navigator.appName;	
	
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		if(userType=="Broker" && iframe.src == "BrokerPage.html")
		 	 LoadIndSegmentsDD(iframe,userType);
		 else if(userType=="General" && iframe.src == "GeneralPage.html")
		 	 LoadIndSegmentsDD(iframe,userType);
		 	 
		iframe.height = document.frames[iframe.id].document.body.scrollHeight;
	}
	else
	{	
		 LoadIndSegmentsDD(iframe,userType);
		 iframe.height=document.getElementById(iframe.id).contentDocument.body.offsetHeight;	
	}

	   	   
	if(document.getElementById(iframe.id).contentWindow.document.documentElement.innerHTML.indexOf('PatentLotsGV')<0)
	{
	 	try
	 	{
			document.getElementById('emptyText').innerHTML="<b><br>Coming soon...</b>";			
		}
		catch(err)
		{}
			iframe.style.display="none";
	}
}


function LoadIndSegments(iframe,userType)
{
	var categoriesList="";
	if(browserName=="Microsoft Internet Explorer")
		categoriesList=iframe.contentWindow.document.documentElement.document.getElementById("CategoriesList").value;
	else
		categoriesList=document.getElementById(iframe.id).contentWindow.document.documentElement.childNodes[1].childNodes[0].childNodes[5].value;

	var categories=categoriesList.split('^');
	var stringBuilder="<table cellpadding='0' cellspacing='0' border='0'>";			
	
	for(var loopIndex1=0;loopIndex1<categories.length-1;loopIndex1++)
	{
	   if(document.getElementById(iframe.id).contentWindow.document.documentElement.innerHTML.indexOf('PatentLotsGV')>=0)
	   {	   	
			if(IsLotsExists(iframe,categories[loopIndex1].split('|')[1])==true)	
			{
				if(userType=="Broker")	{		
					stringBuilder = stringBuilder + "<tr style='display:none'><td align='left'></td><td width='10' align='left' valign='top' nowrap class='color003366'>&raquo;</td><td width='1' align='left'></td><td width='160' align='left' valign='top' class='color003366'><a href='PRT_CategoryLotsBrokerPage.html?category="+ categories[loopIndex1].split('|')[1] +"'>" + categories[loopIndex1].split('|')[1] + "</a></td><td width='10' align='left'><img src='http://welcome.hp-ww.com/img/s.gif' width='10' height='1' alt=''></td></tr>";
					
				} else if(userType=="General") {
					stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg' style='display:none'><td align='left'></td><td width='10' align='left' valign='top' nowrap class='color003366'>&raquo;</td><td width='1' align='left'></td><td width='160' align='left' valign='top' class='color003366'><a href='CategoryLotsGeneralPage.html?category="+ categories[loopIndex1].split('|')[1] +"'>" + categories[loopIndex1].split('|')[1] + "</a></td><td width='10' align='left'><img src='http://welcome.hp-ww.com/img/s.gif' width='10' height='1' alt=''></td></tr>";
					
				}
			}
			else {
				stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg' style='display:none'><td align='left'></td><td width='10' align='left' valign='top' nowrap class='color003366'>&raquo;</td><td width='1' align='left'></td><td width='160' align='left' valign='top' class='color003366'>" + categories[loopIndex1].split('|')[1] + "*</td><td width='10' align='left'><img src='http://welcome.hp-ww.com/img/s.gif' width='10' height='1' alt=''></td></tr>";
				
			}
		}
		else {
			stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg' style='display:none'><td align='left'></td><td width='10' align='left' valign='top' nowrap class='color003366'>&raquo;</td><td width='1' align='left'></td><td width='160' align='left' valign='top' class='color003366'>" + categories[loopIndex1].split('|')[1] + "*</td><td width='10' align='left'><img src='http://welcome.hp-ww.com/img/s.gif' width='10' height='1' alt=''></td></tr>";
			
		}
	}
	
	if(userType=="Broker")	{
		stringBuilder = stringBuilder + "<tr ><td align='left'>&nbsp;</td><td align='left' valign='top' >&raquo;</td><td align='left'>&nbsp;</td><td align='left' valign='top' ><a href='PRT_ViewAllBrokerCategories.html'>View all industry segments</a></td></td><td width='10' align='left'><img src='http://welcome.hp-ww.com/img/s.gif' width='10' height='1' alt=''></td></tr>";

	} else if(userType=="General") {
		stringBuilder = stringBuilder + "<tr ><td align='left'>&nbsp;</td><td align='left' valign='top' >&raquo;</td><td align='left'>&nbsp;</td><td align='left' valign='top' ><a href='ViewAllGeneralCategories.html'>View all industry segments</a></td></td><td width='10' align='left'><img src='http://welcome.hp-ww.com/img/s.gif' width='10' height='1' alt=''></td></tr>";
	
	}
	stringBuilder = stringBuilder + "</table>";
	

	document.getElementById('IndSegDIV').innerHTML=stringBuilder; 
	
}

function LoadIndSegmentsDD(iframe,userType)
{
	var categoriesList="";
	if(browserName=="Microsoft Internet Explorer")
		categoriesList=iframe.contentWindow.document.documentElement.document.getElementById("CategoriesList").value;
	else
		categoriesList=document.getElementById(iframe.id).contentWindow.document.documentElement.childNodes[1].childNodes[0].childNodes[5].value;

	var categories=categoriesList.split('^');
	//var stringBuilder="<Table><tr class='colorE7E7E7bg'><td width='15' align='left'><img src='http://welcome.hp-ww.com/img/s.gif' width='10' height='1' alt=''></td><td align='left' valign='top' width='175' colspan='3'>Lots relevant to industry segments</tr>";			
	var stringBuilder="<form name='segForm' id='segForm'><select name='indSelect' id='indSelect'><option value=''>Filter lots by Industry Segment (* = coming soon)";
	for(var loopIndex1=0;loopIndex1<categories.length-1;loopIndex1++)
	{
	   if(document.getElementById(iframe.id).contentWindow.document.documentElement.innerHTML.indexOf('PatentLotsGV')>=0)
	   {	   	
			if(IsLotsExists(iframe,categories[loopIndex1].split('|')[1])==true)	
			{
				if(userType=="Broker")	{		
					//stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg'><td align='left'></td><td width='8' align='left' valign='top nowrap class='color003366'>&raquo;</td><td width='1' align='left'></td><td width='175' align='left' valign='top' class='color003366'><a href='PRT_CategoryLotsBrokerPage.html?category="+ categories[loopIndex1].split('|')[1] +"'><u>" + categories[loopIndex1].split('|')[1] + "</u></a></tr>";
					stringBuilder = stringBuilder + "<option value='PRT_CategoryLotsBrokerPage.html?category="+ categories[loopIndex1].split('|')[1] +"'>"+ categories[loopIndex1].split('|')[1];
				} else if(userType=="General") {
					//stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg'><td align='left'></td><td width='8' align='left' valign='top nowrap class='color003366'>&raquo;</td><td width='1' align='left'></td><td width='175' align='left' valign='top' class='color003366'><a href='CategoryLotsGeneralPage.html?category="+ categories[loopIndex1].split('|')[1] +"'><u>" + categories[loopIndex1].split('|')[1] + "</u></a></tr>";
					stringBuilder = stringBuilder + "<option value='CategoryLotsGeneralPage.html?category="+ categories[loopIndex1].split('|')[1] +"'>"+ categories[loopIndex1].split('|')[1];
				}
			}
			else {
				//stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg'><td align='left'></td><td width='8' align='left' valign='top nowrap class='color003366'>&raquo;</td><td width='1' align='left'></td><td width='175' align='left' valign='top' class='color003366'>" + categories[loopIndex1].split('|')[1] + "*</tr>";
				stringBuilder = stringBuilder + "<option value='CategoryLotsGeneralPage.html?category="+ categories[loopIndex1].split('|')[1] +"'>" + categories[loopIndex1].split('|')[1] + "*";
			}
		}
		else {
			//stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg'><td align='left'></td><td width='8' align='left' valign='top nowrap class='color003366'>&raquo;</td><td width='1' align='left'></td><td width='175' align='left' valign='top' class='color003366'>" + categories[loopIndex1].split('|')[1] + "*</tr>";
			stringBuilder = stringBuilder + "<option value=''>" + categories[loopIndex1].split('|')[1] + "*";
		}
	}
	
	if(userType=="Broker")	{
		//stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg'><td align='left'>&nbsp;</td><td align='left' valign='top' class='color003366'>&raquo;</td><td align='left'>&nbsp;</td><td align='left' valign='top' class='color003366'><a href='PRT_ViewAllBrokerCategories.html'><u>View All</u></a></td></tr>";
		stringBuilder = stringBuilder + "<option value='PRT_ViewAllBrokerCategories.html'>View All";
	} else if(userType=="General") {
		//stringBuilder = stringBuilder + "<tr class='colorE7E7E7bg'><td align='left'>&nbsp;</td><td align='left' valign='top' class='color003366'>&raquo;</td><td align='left'>&nbsp;</td><td align='left' valign='top' class='color003366'><a href='ViewAllGeneralCategories.html'><u>View All</u></a></td></tr>";
		stringBuilder = stringBuilder + "<option value='ViewAllGeneralCategories.html'>View All";
	}
	//stringBuilder = stringBuilder + "</table>";
	stringBuilder = stringBuilder + "</select>&nbsp;<a id=\"seg_select\" onmouseover=\"status='Go to URL';return true;\" title=\"Jump to current segment selected\" onclick=\"jumpToURL(document.segForm)\" onmouseout=\"status='';return true;\" href=\"javascript:jumpToURL(document.segForm);\" onBlur=\"status='';return true;\" onFocus=\"status='Go to URL';return true;\" tabindex=\"1\"><img height=\"13\" alt=\"Jump to current segment selection\" src=\"http://welcome.hp-ww.com/img/hpweb_1-2_arrw_sbmt.gif\" width=\"14\" border=\"0\" class=\"dropDownButton\"></a></form> ";

	//document.getElementById('IndSegDIV').innerHTML=stringBuilder; 
	document.getElementById('IndSegDrop').innerHTML=stringBuilder; 
}

function IsLotsExists(iframe,category)
{	
	var trLength="";
			var trs="";
			if(browserName=="Microsoft Internet Explorer")
			{
				trLength=iframe.contentWindow.document.documentElement.document.getElementById("PatentLotsGV").childNodes[0].childNodes.length;		   
				trs=iframe.contentWindow.document.documentElement.document.getElementById("PatentLotsGV").childNodes[0].childNodes;
				
				for(var loopIndex=1;loopIndex<trLength;loopIndex++)
			    {		   		
					if(trs[loopIndex].childNodes[0].childNodes[2].value==category)
						return true; 			
			    }
			   
			   return false;				
			}
			else
			{	
				trLength=iframe.contentWindow.document.getElementById("PatentLotsGV").childNodes[1].childNodes.length;//document.getElementById(iframe.id).contentWindow.document.documentElement.childNodes[1].childNodes[0].childNodes[3].childNodes[1].childNodes[0].childNodes[1].childNodes[1].childNodes[1].childNodes.length;		   
				trs=iframe.contentWindow.document.getElementById("PatentLotsGV").childNodes[1].childNodes;//document.getElementById(iframe.id).contentWindow.document.documentElement.childNodes[1].childNodes[0].childNodes[3].childNodes[1].childNodes[0].childNodes[1].childNodes[1].childNodes[1].childNodes;//document.getElementById(iframe.id).contentWindow.document.documentElement.childNodes[1].childNodes[0].childNodes[3].childNodes;								

				for(var loopIndex=1;loopIndex<trLength-1;loopIndex++)
			    {
					if(trs[loopIndex].childNodes[1].childNodes[3].value==category)
						return true; 			
			    }
			   
			   return false;
			}

}


function GetAllCategories(iframe,userType)
{
	var categoriesList="";
	browserName=navigator.appName;
	
	if(browserName=="Microsoft Internet Explorer")
		categoriesList=iframe.contentWindow.document.documentElement.document.getElementById("SubCategoriesList").value;
	else
		categoriesList=document.getElementById(iframe.id).contentWindow.document.documentElement.childNodes[1].childNodes[0].childNodes[6].value;		

	var categories=categoriesList.split('^'); //CategoryID | CategoryName | SubCategoryID | SubCategoryName ^	
	var stringBuilder="<table cellpadding='0' cellspacing='0' border='0'>";
	var catID=-1;//categories[0].split('|')[0];
	//This is for header
	stringBuilder = stringBuilder + "<tr ><td width='20' align='left'><img src='http://welcome.hp-ww.com/img/s.gif' width='20' height='1' alt=''></td><td align='left' valign='top' colspan='5' class='bold'>Lots relevant to industry segments:</tr>";

	for(var loopIndex1=0;loopIndex1<categories.length-1;loopIndex1++)
	{
		if(catID!=categories[loopIndex1].split('|')[0])
		{
			if(document.getElementById(iframe.id).contentWindow.document.documentElement.innerHTML.indexOf('PatentLotsGV')>=0)
	   		{
				if(IsLotsExists(iframe,categories[loopIndex1].split('|')[1])==true)	
				{
					//This is for Category
					if(userType=="Broker")
					{				
						stringBuilder = stringBuilder + "<tr><td align='left'>&nbsp;</td><td align='left' valign='top'>&raquo;</td><td align='left'>&nbsp;</td><td colspan='3' align='left' valign='top'><a href='PRT_CategoryLotsBrokerPage.html?category="+ categories[loopIndex1].split('|')[1] +"'>" + categories[loopIndex1].split('|')[1] + "</a></td></tr>";
					}
					else if(userType=="General")
					{
						stringBuilder = stringBuilder + "<tr><td align='left'>&nbsp;</td><td align='left' valign='top'>&raquo;</td><td align='left'>&nbsp;</td><td colspan='3' align='left' valign='top'><a href='CategoryLotsGeneralPage.html?category="+ categories[loopIndex1].split('|')[1] +"'>" + categories[loopIndex1].split('|')[1] + "</a></td></tr>";
					}					
				}
				else
				{
					stringBuilder = stringBuilder + "<tr><td align='left'>&nbsp;</td><td align='left' valign='top'>&nbsp;</td><td align='left'>&nbsp;</td><td colspan='3' align='left' valign='top'>" + categories[loopIndex1].split('|')[1] + "</td></tr>";
				}
			}
			else
			{
				stringBuilder = stringBuilder + "<tr><td align='left'>&nbsp;</td><td align='left' valign='top'>&nbsp;</td><td align='left'>&nbsp;</td><td colspan='3' align='left' valign='top'>" + categories[loopIndex1].split('|')[1] + "</td></tr>";
			}
			
			//This is for sub Category	
			stringBuilder = stringBuilder + "<tr><td align='left'>&nbsp;</td><td align='left' valign='top'>&nbsp;</td><td align='left'>&nbsp;</td><td align='left' valign='top'>&nbsp;</td><td align='left'>&nbsp;</td><td align='left' valign='top' >" + categories[loopIndex1].split('|')[3] +"</td></tr>";		
		}
		else
		{
			//This is for sub Category	
			stringBuilder = stringBuilder + "<tr><td align='left'>&nbsp;</td><td align='left' valign='top'>&nbsp;</td><td align='left'>&nbsp;</td><td align='left' valign='top'>&nbsp;</td><td align='left'>&nbsp;</td><td align='left' valign='top' >" + categories[loopIndex1].split('|')[3] +"</td></tr>";
		}
		
		catID=categories[loopIndex1].split('|')[0];
	}	
	
	stringBuilder = stringBuilder + "</table>";

	document.getElementById("categoriesListDIV").innerHTML=stringBuilder; 
}

function PrintOrFax()
{
	var win=null;         
    win = window.open();
    self.focus();
    win.document.open();
    win.document.write('<html><head></head>');
    win.document.write('<body>');
    var Content1 = "<table style='font-family:Arial'>" + document.getElementById('AgreementContentDIV').innerHTML + "</table>"       
    win.document.write(Content1);
    win.document.write('</body></html>');
    win.document.close();
    win.print();
    win.close();
}

function SendAgreementMail(chkBox1,chkBox2,chkBox3,usrName,subject,attention,url,toAddress)
{
    var objOutlookAPP;
    var objMailItem;
    var Content="Body";    

    try
    {
        //var objOutlookAPP = new ActiveXObject("Outlook.Application");           
        //var objMailItem = objOutlookAPP.CreateItem(0);

		if(document.getElementById(chkBox1).checked==true)
		{
			//Content=document.getElementById(chkBox1).value;
			document.getElementById(chkBox1).name="";
			document.getElementById(chkBox1).value="";
			document.getElementById(subject).value="New authorization request - agreement executed";			
		}
		else if(document.getElementById(chkBox2).checked==true)
		{
			//Content=document.getElementById(chkBox2).value;
			document.getElementById(chkBox2).name="";
			document.getElementById(chkBox2).value="";
			document.getElementById(subject).value="New authorization request - bona fide offer";
		}
		else if(document.getElementById(chkBox3).checked==true)
		{
			//Content=document.getElementById(chkBox3).value;
			document.getElementById(chkBox3).name="";
			document.getElementById(chkBox3).value="";
			document.getElementById(subject).value="New authorization request - no offer or signed agreement";
		}
		else 
		{
			alert("Please Select Request type Radio button");
			return;
		}
        //Bind the variables with the email
        //objMailItem.Subject=subject;
		//objMailItem.to = "IPL.PatentSales@hp.com";        
        //objMailItem.HTMLBody = "<font face='Arial' size='2'>The account "+ usrName +" has requested authorization.<br><br><br>Automated web mailer</font>" ; 
        document.getElementById(attention).value="The account "+ usrName +" has requested authorization.";
        document.getElementById(url).value="http://h20229.www2.hp.com/HPVPS/OnlinePatentSales.html";
        document.getElementById(toAddress).value="IPL.PatentSales@hp.com";
        //objMailItem.Attachments.Add(strAttachLoc)
        //objMailItem.Display();
		//objMailItem.Send();
		//window.location.href="OnlinePatentSales.html"		
		return true;		
    }
    catch(err)
    {
        alert("The following may have cause this error. Please check below and try again : \n"+
         "1. Microsoft Outlook 2003 or later installed.\n"+
         "2. The Initialize and Scripts ActiveX controls not marked as safe is not set to enable.")
    }
}

// Validate the form values
	function FormValidator(theForm)
	{
		var errMsg = "";

/*		var commentsStr = theForm.comments.value;
		commentsStr = commentsStr.replace(/^\s+/,''); //Trim white spaces
		if ( isEmpty(commentsStr) )
		{
			errMsg = " - enter Comments\n" + errMsg;
			theForm.comments.focus();
		}

if ( theForm.product_name.selectedIndex == 0 )
		{
			errMsg = " - select a Product\n" + errMsg;
			theForm.product_name.focus();
		}

		if ( theForm.subject.selectedIndex == 0 )
		{
			errMsg = " - select a Subject\n" + errMsg;
			theForm.subject.focus();
		}

*/		var emailAddr = theForm.getElementById('email').value;        
		if ( (isEmpty(emailAddr)) || (!isEmailAddr(emailAddr)) )
		{
			errMsg = " - enter a valid Email Address\n" + errMsg;
			theForm.email_address.focus();
		}
		else if ( (emailAddr.indexOf('|')>-1) || (emailAddr.indexOf('~')>-1) || (emailAddr.indexOf('!')>-1) )
		{
				errMsg = " - invalid character in Email Address\n" + errMsg;
				theForm.email_address.focus();
		}

		var lastName = theForm.last_name.value;
		if ( isEmpty(lastName) )
		{
			errMsg = " - enter Last Name\n" + errMsg;
			theForm.last_name.focus();
		}
		else if ( (lastName.indexOf('|')>-1) || (lastName.indexOf('~')>-1) || (lastName.indexOf('!')>-1) )
		{
			errMsg = " - invalid character in Last Name\n" + errMsg;
			theForm.last_name.focus();
		}

		var firstName = theForm.first_name.value;
		if ( isEmpty(theForm.first_name.value) )
		{
			errMsg = " - enter First Name\n" + errMsg;
			theForm.first_name.focus();
		}
		else if ( (firstName.indexOf('|')>-1) || (firstName.indexOf('~')>-1) || (firstName.indexOf('!')>-1) )
		{
			errMsg = " - invalid character in First Name\n" + errMsg;
			theForm.first_name.focus();
		}


		if ( isEmpty(errMsg) )
		{
			return true;
		}
		else
		{
			errMsg = "Please correct the following error(s): \n" + errMsg;
			alert( errMsg );
			return false;
		}
	}