//  *****************************************************************
//  *   Version 1.0                                                 *
// js to create breadcrumb in the templated pages
//  *   Kailash 19/01/07                                        *
//  *****************************************************************
	
	// .............extracting relative url from the complete url .....
	var urlPage=window.location.href;

	/* hgoel:25Apr07- Add below div id=rate to display content as per CQ#11890 */
	//document.write('<div id="rate">');
	//document.write("<p><a href='http://www.surveymonkey.com/s.asp?u=354383657725&c=" + urlPage + "' target='_blank'>Rate this page</a></p>");
	//document.write("</div>");

	// *********** CQ 11890 code ends here ********************************

	var indexFile="index.html";
	var relUrl= urlPage.match(/^[A-Za-z]+:\/\/\S+?\//);

		
	var finalUrl=urlPage.replace(/^[A-Za-z]+:\/\/\S+?(\/){1}/,"");
	finalUrl="/"+finalUrl;
	var	sectionUrltoSplit =finalUrl.split('/');
	//var sectionUrl =  '/' + sectionUrltoSplit[1]+ '/' + sectionUrltoSplit[2]+ '/' + sectionUrltoSplit[3] +  '/';
	var sectionUrl =  sectionUrltoSplit[1]+ '/' + sectionUrltoSplit[2]+ '/' + sectionUrltoSplit[3] +  '/';


	// ..................ends here ....................................

	var BodyIDSplit=new Array();
	var EntireBodyID;
	var FirstFlag=0;
	var FirstBC = "";
	var SecondFlag=0;
	var SecondBC = "";
	var ThirdFlag=0;
	var ThirdBC = "";
	var FourthFlag=0;
	var FourthBC = "";

	var objhead = document.getElementById('header'); //header object to get home link
	var bodyTagList = document.getElementsByTagName('body'); // getting the body id
	for(var bodytag=0; bodytag<bodyTagList.length; bodytag++)
		{
					// spliting the body id and storing in the array
					BodyIDSplit=bodyTagList[bodytag].getAttribute('id').replace(/-$/g,'').split('-');
					EntireBodyID=bodyTagList[bodytag].getAttribute('id');

					document.write("<div id='breadcrumb'>");
					document.write("<a href=" + objhead.childNodes[0] + ">Home</a>");
		}
		if (EntireBodyID.match("(dow-)"))
		{
			// do nothing since there would be no Li ID for this 
		}
		else if (EntireBodyID.match("(sup-)"))
		{
			// do nothing since there would be no Li ID for this
		}
		else if (EntireBodyID.match("(sec-)"))
		{
			// do nothing since there would be no Li ID for this
		}
		else
		{

		for (x in BodyIDSplit) // iterating each element of body id to match the corresponding Li ID in page
			{
				 if ( x == 1 &&  BodyIDSplit[0] != "abo") // main if
				 {
					var segment = BodyIDSplit[0]; 
					var section = BodyIDSplit[1];
 			            var segObj=document.getElementById(segment);
					//Start searching all the child li tag for section name and its Url
					 for (var i = 0; i < segObj.getElementsByTagName('LI').length; i++) {
						//skip those li which does not have a child for eg <li class="top"></li>
						if ( typeof (segObj.getElementsByTagName('LI')[i]).childNodes[0] != "undefined" )
						{
						  //skip those li which does have a child but it is not a href <li id="desc-sma"><p><span>10 to 50 computers</span>

						 if ((segObj.getElementsByTagName('LI')[i]).childNodes[0].getAttribute('href') != null )
						  {
							var matchUrl=(segObj.getElementsByTagName('LI')[i]).childNodes[0].getAttribute('href').replace(/^[A-Za-z]+:\/\/\S+?(\/){1}/,"");
							if (matchUrl.indexOf('/')  == 0 )
							 {
								matchUrl=matchUrl.substring(1,matchUrl.length);
  							 }

							var reg= new RegExp("index");
							if ( reg.test(matchUrl) )
							{
								//remove index.asp index.html
								matchUrl=matchUrl.replace(/index\.[A-Za-z]{4}/,"");
								matchUrl=matchUrl.replace(/index\.[A-Za-z]{3}/,"");
								
							}

							var reg= new RegExp("default");
								
							if ( reg.test(matchUrl) )
							{	
								//remove default.asp default.html
								matchUrl=matchUrl.replace(/default\.[A-Za-z]{4}/,"");
								matchUrl=matchUrl.replace(/default\.[A-Za-z]{3}/,"");
								
							}
							
							if((segObj.getElementsByTagName('LI')[i].getAttribute('id')) == section  && sectionUrl == matchUrl )//&& reg.test(str) )
							{
								
								var cObj = segObj.getElementsByTagName('LI')[i];
								linkObj=cObj;
						 		break;
							}
						

					     }//end null	
					   }//end undefined
					} //end for
					
				} //end main if
				else // main else
				{
					if ( x == 0 &&  BodyIDSplit[0] != "abo")

					{
						var linkObj=document.getElementById(BodyIDSplit[0]);
					}
					else
					{			

						 var linkObj=document.getElementById(BodyIDSplit[x]);
					
					  if  ( (BodyIDSplit[0] == "par") && x != BodyIDSplit.length - 2   && !linkObj.childNodes[0].getAttribute('href').match(finalUrl) )
					  { 
						 var leftNavObj=document.getElementById(BodyIDSplit[x-1]);	
					     
						//alert( ' leftNavObj not null length ' +  leftNavObj.getElementsByTagName('LI').length + ' ' +BodyIDSplit[x-1]);
						for (var i = 0; i < leftNavObj.getElementsByTagName('LI').length; i++) {
						//skip those li which does not have a child 
						if ( typeof (leftNavObj.getElementsByTagName('LI')[i]).childNodes[0] != "undefined" )
						{
						

						  //skip those li which does have a child 
						 if ((leftNavObj.getElementsByTagName('LI')[i]).childNodes[0].getAttribute('href') != null )
						  {
						

							 var link =leftNavObj.getElementsByTagName('LI')[i].childNodes[0].getAttribute('href');
							 if ( link.match(finalUrl))
								{
								linkObj=leftNavObj.getElementsByTagName('LI')[i];
								}

						   }
						   
						}
					    }//for
					 } //if
						
					} //inner else

						
					
				}//outer main else
				//When No Reference to Section is found in Top Nav Dropdown search in left Nav (other than about)

				if ( x == 1 && linkObj == null &&  BodyIDSplit[0] != "abo" &&  BodyIDSplit[0] != "par"   ) //main if
				{
					 var segObj=document.getElementById("nav-page");
					 var NoSectionURLInLeftNav = true; 
						 for (var i = 0; i < segObj.getElementsByTagName('LI').length; i++) {
							if ( typeof (segObj.getElementsByTagName('LI')[i]).childNodes[0] != "undefined" )
							{
	
								
								var matchUrl =  segObj.getElementsByTagName('LI')[i].childNodes[0].getAttribute('href').replace(/^[A-Za-z]+:\/\/\S+?(\/){1}/,"");
								if (matchUrl.indexOf('/')  == 0 )
								 {
									matchUrl=matchUrl.substring(1,matchUrl.length);
  								 }

								//To make sure the match is correct  compare the sections and compare the Url
								if((segObj.getElementsByTagName('LI')[i].getAttribute('id')) == section && ( sectionUrl + indexFile)  == matchUrl)
								{
									var cObj = segObj.getElementsByTagName('LI')[i];
									linkObj=cObj;
									NoSectionURLInLeftNav =false;
									break;
								}
							}	
						}
						//When No Reference to Section is found in page put section name as URLText of  section & URL Link as SectionURL plus index page
						if ( NoSectionURLInLeftNav )
						{
						 	 //document.write(" \\ <a href=" + relUrl +  sectionUrl + indexFile  + ">" + toUpperCase(section) + </a>");
							
							
							//FirstBC = " / <a style='color:yellow; ' href=" + relUrl +  sectionUrl + indexFile  + ">" + toUpperCase(section) + "</a>";
							SecondFlag = 1;
							SecondBC = SecondBC+" / <a href=" + relUrl +  sectionUrl + indexFile  + ">" + toUpperCase(section) + "</a>";
							if (SecondBC.match(/products_a_to_z/)){
								SecondBC= SecondBC.replace(/\/index\.html/,"");
							}
						
					
							//document.write(" / <a style='color:yellow; ' href=" + relUrl +  sectionUrl + indexFile  + ">" + toUpperCase(section) + "</a>");
	
						}		
 
				} // end main if

				// process the linkObj got from Either Top Navigation or the Left Navigation since the URL existed there
				if (linkObj != null) // if body id elment finds a Li ID match //main if
				{
					
					var link=linkObj.childNodes[0].getAttribute('href'); // get the url
					// if current url page match the li id url we dont want to show it in BC.
					if (link.match(finalUrl))
							{
								
								//alert("breaking out-2");
								break;
							}
							else
							{
								if ( BodyIDSplit[x] != BodyIDSplit[x-1] ) //Handle us/segment/products/products.html
								{
										
									   FirstFlag=1;   
								
									   FirstBC = FirstBC+" / <a href=" + link + ">" + linkObj.childNodes[0].firstChild.nodeValue + "</a>";
								

										//document.write(" / <a style='color:red;' href=" + link + ">" + linkObj.childNodes[0].firstChild.nodeValue + "</a>");
										linkObj=null;
								}
							}
				} // main if
				// looking for product & services info match
				else if ((linkObj == null) && 
				//(EntireBodyID.match("(hho-products|ent-products|sma-products|ent-services|sma-services|med-products|med-services)")) && 
				//(!(EntireBodyID.match("(hho-products-index|ent-products-index|ent-services-index|sma-services-index|sma-products-index|med-services-index|med-products-index)"))))
				(EntireBodyID.match("(hho-solutions|ent-solutions|sma-solutions|med-solutions|hho-products|ent-products|sma-products|ent-services|sma-services|med-products|med-services)")) && 
				(!(EntireBodyID.match("(hho-solutions-index|ent-solutions-index|med-solutions-index|sma-solutions-index|hho-products-index|ent-products-index|ent-services-index|sma-services-index|sma-products-index|med-services-index|med-products-index)"))))
				
				{
					
					// add ln to body id since left nav has ln with li ids
					var leftnavID = "ln-"+EntireBodyID;
					 
					var pos=leftnavID.indexOf(BodyIDSplit[x]);
					
					var toBeReplaced=leftnavID.slice(pos);
					var replaceWith=(BodyIDSplit[x] +"-index");
					leftnavID=leftnavID.replace(toBeReplaced,BodyIDSplit[x] +"-index");
					var linkProducts=document.getElementById(leftnavID);
				
						if (linkProducts != null)
						{
							var linkPage=document.getElementById(leftnavID).childNodes[0].getAttribute('href');
							// if current url page match the li id url we dont want to show it in BC.
							if (linkPage.match(finalUrl))
							{
								//alert("breaking out-3");
								
								break;
							}
							else
							{
								if ( BodyIDSplit[x] != BodyIDSplit[x-1] ) //Handle us/enterprise/products/data_loss_prevention/data_loss_prevention.html
								{
									
									ThirdFlag = 1;
									ThirdBC = ThirdBC+" / <a href=" + linkPage + ">" + document.getElementById(leftnavID).childNodes[0].firstChild.nodeValue + "</a>";
								
									//document.write(" / <a style='color:blue' href=" + linkPage + ">" + document.getElementById(leftnavID).childNodes[0].firstChild.nodeValue + "</a>");
									linkProducts =null;
								}
							}
						}
						else if (document.getElementById("ln-"+EntireBodyID))
						{
							// do nothing
						}
						else
						{
							// do nothing
						}
									
				} // main else if
				else // Ruby 2
				{
					// for non-products pages
					if (BodyIDSplit[x] == "index")
					{
						// this will never match a li id
					}
					else // Ruby 1
					{
					var nonprID = EntireBodyID;
					var pos=nonprID.indexOf(BodyIDSplit[x]);
					var toBeReplaced=nonprID.slice(pos);
					var replaceWith=(BodyIDSplit[x] +"-index");
					
					nonprID=nonprID.replace(toBeReplaced,BodyIDSplit[x] +"-index");
					var linkPageNext=document.getElementById(nonprID);
					exceptionURL(BodyIDSplit[x],finalUrl);
					

					
					if (EntireBodyID == nonprID)
					 {
					//	document.write("</div>");
						//alert("breaking out-4");
						break;
					 }
					 else //Ruby
					 {
						if (linkPageNext != null)
						{
							var linkPage=document.getElementById(leftnavID).childNodes[0].getAttribute('href');
							// if current url page match the li id url we dont want to show it in BC.
							if (linkPage.match(finalUrl))
							{
								//alert("breaking out-5");
								break;
							}
							else
							{
								if (linkPage != null)
									{
										FourthFlag = 1;
										FourthBC = FourthBC+"<a href=" + linkPage + ">" + document.getElementById(leftnavID).childNodes[0].firstChild.nodeValue + "</a> > ";
										
										//document.write("<a style='color:green;' href=" + linkPage + ">" + document.getElementById(leftnavID).childNodes[0].firstChild.nodeValue + "</a> > ");
										linkPageNext=null;
									}
								else
									{
									//	document.write("</div>");
										//alert("breaking out-6");
										break;
									}
							}
						}
						else
						{
							//alert('document .write 5');
						//	document.write("</div>");
							break;
							
						}
					  } // End Ruby
					} // End Ruby1
					
				} // End Ruby 2 main else 
				
				
			}

			//alert("FirstFlag:"+FirstFlag);
			//alert("SecondFlag:"+SecondFlag);
			//alert("ThirdFlag :"+ThirdFlag);
			//alert("FourthFlag :"+FourthFlag);
			//alert("FirstBC:"+FirstBC);
			//alert("SecondBC:"+SecondBC);
			//alert("ThirdBC:"+ThirdBC);
			//alert("FourthBC:"+FourthBC);

			var temp;
			if(FirstFlag == 1) {
			
				temp = new Array();
				temp = FirstBC.replace(/ \/ <a/g,"split / <a");
				temp = temp.split('split'); 
				if((SecondFlag != 1) && (ThirdFlag != 1)){
				        temp[temp.length-1] = temp[temp.length-1].replace(/<a/g,"<a class=\"selected\"");
				}
				FirstBC = temp.join("");
				//alert(SecondFlag);
				//alert("FirstBC:"+FirstBC);
					document.write(FirstBC);
			}
			if(SecondFlag == 1) {
				temp = new Array();
				temp = SecondBC.replace(/ \/ <a/g,"split / <a");
				temp = temp.split('split'); 		
				if(ThirdFlag != 1) {					
					  temp[temp.length-1] = temp[temp.length-1].replace(/<a/g,"<a class=\"selected\"");
				}
				SecondBC = temp.join("");
				      //alert("SecondBC:"+SecondBC);
					document.write(SecondBC);
			}
			if(ThirdFlag == 1) {
				temp = new Array();
				temp = ThirdBC.replace(/ \/ <a/g,"split / <a");
				temp = temp.split('split'); 		
				if(FourthFlag != 1) {
				        temp[temp.length-1] = temp[temp.length-1].replace(/<a/g,"<a class=\"selected\"");
				}
				ThirdBC = temp.join("");
					//alert("ThirdBC:"+ThirdBC);
					document.write(ThirdBC);
			}
			if(FourthFlag == 1) {
				temp = new Array();
				temp = FourthBC.replace(/ \/ <a/g,"split / <a");
				temp = temp.split('split'); 		
				temp[temp.length-1] = temp[temp.length-1].replace(/<a/g,"<a class=\"selected\"");
				
				FourthBC = temp.join("");
					//alert("FourthBC:"+FourthBC);
					document.write(FourthBC);
			}
			document.write("</div>");
			
			
}

function exceptionURL(exceptionkey,finalUrl)
{
	
var checkUrl = new RegExp("/us/about/events/index.html");
var urlText = "Events";
   if ( exceptionkey == "events"  &&  ! checkUrl.test(finalUrl) )
	{
	checkUrl="/us/about/events/index.html";
	//document.write(" / <a href=" + checkUrl + ">" + urlText+ "</a>");
	SecondFlag = 1;
	SecondBC = SecondBC+ " / <a href=" + checkUrl + ">" + urlText+  "</a>";	
	}
var checkUrl = new RegExp("/us/threat_center/default.asp");
var urlText = "Threat Center";
   if ( exceptionkey == "thr"  &&  ! checkUrl.test(finalUrl) )
	{
	checkUrl="/us/threat_center/default.asp";
	document.write(" / <a href=" + checkUrl + ">" + urlText+ "</a>");

	}

}
function toUpperCase(UrlText) {
var UrlTextArray = UrlText.split(' ');
var newString = '';
for (var n=0; n<UrlTextArray.length; n++) {
	var firstChar = UrlTextArray[n].charAt(0).toUpperCase();
	var theRest = UrlTextArray[n].substring(1, UrlTextArray[n].length);
	newString += firstChar+theRest+' ';
	}
return newString.substring(0, newString.length - 1);
}


