var mainserver = "";									// Uncomment this for www.wdc.com
if (typeof mainserver == "undefined") mainserver="";    // This is to make sure the mainserver is defined.

//var mainserver = "http://websupport.wdc.com";										// Uncomment this for websupport.wdc.com
//if (typeof mainserver == "undefined") mainserver="http://websupport.wdc.com";		// This is to make sure the mainserver is defined.

var insection = 0;


// detect browser version
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById) ? true : false;
var ie4 = (document.all) ? true : false;

// detect platform
var agent = navigator.userAgent.toLowerCase();

var win = ((agent.indexOf("win") != -1) || (agent.indexOf("16bit") != -1)) ? true : false;
var mac = (agent.indexOf("mac") != -1) ? true : false;
var linux = (agent.indexOf("linux") != -1) ? true : false;

// write the css link
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainserver + "/css/win_ie.css\">");

// -------------------------

function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function setSection(server)
{
	var path = new String();
	var delim, stop, token, tokenlink;

 	path = location.pathname;
	delim = "/";
	stop = 0;
	token = "";

	path = path.substring(stop+4, path.length);
	stop = path.indexOf(delim);
	token = path.substring(0, stop);

	switch(server)
	{
		case "websupport" : case "rightnow" : case "young-america" : case "support" :
			{ insection = 2; strImage = "imgSupport"; break; }
		case "localInvestor" : case "jobpost" : case "investor" :
			{ insection = 4; strImage = "imgCompany"; break; }
		case "wdcStore" :
			{ insection = 3; strImage = "imgBuy"; break; }

			
		default :
			switch (token.toLowerCase())
			{
				case "products" :
					{ insection = 1; strImage = "imgProducts"; break;}
				case "support" : case "library" :
					{ insection = 2; strImage = "imgSupport"; break; }
				case "buy" : 
					{ insection = 3; strImage = "imgBuy"; break;}
				case "company" :
					{ insection = 4; strImage = "imgCompany"; break;}
				case "partners" :
					{ insection = 5; strImage = "imgPartners"; break;}

				default:
					insection = 0;
			}
	}	
	
	if (insection != 0) 
		eval('document.images["'+strImage+'"].src="'+mainserver+'/global/images/header/en/on'+insection+'.gif"');	
}


function GetDateString(time)
{
// CB Global Edge - added this function for international date formatting
	var intYear = time.getFullYear();
	var intMonth = time.getMonth();
	var intDate = time.getDate();
	var strToday = "%M %d, %Y"; // date formatting
		 
	switch(intMonth)
	{
		case 0:
			strMonth = "January";
			break;
		case 1:
			strMonth = "February";
			break;
		case 2:
			strMonth = "March";
			break;
		case 3:
			strMonth = "April";
			break;
		case 4:
			strMonth = "May";
			break;
		case 5:
			strMonth = "June";
			break;
		case 6:
			strMonth = "July";
			break;
		case 7:
			strMonth = "August";
			break;
		case 8:
			strMonth = "September";
			break;
		case 9:
			strMonth = "October";
			break;
		case 10:
			strMonth = "November";
			break;
		case 11:
			strMonth = "December";
			break;
	 }

	 re = /%M/;
	 strToday = strToday.replace(re, strMonth);
	 re = /%d/;
	 strToday = strToday.replace(re, intDate);
	 re = /%Y/;
	 strToday = strToday.replace(re, intYear);
	return strToday;
}


// show today's date in the header part
function showDate(plaintext)
{
// CB Global Edge - changed this to call GetDateString for localized date string
	var time = new Date();
	strToday = GetDateString(time);
	
	
	if (plaintext == 1) 
	{
		document.write(strToday);
	}
	else
	{		 
		document.write("<span class=date>" + strToday + "</span>");
	}
	
}


// showing the page's hierachy path
function showPath(server)
{
	var txtExternalOverview = "External Hard Drives Overview";
	var txtDesktopOverview = "Internal Hard Drives Overview";
	var txtEnterpriseOverview = "Enterprise Drives Overview";
	var txtMobileOverview = "Mobile Drives Overview";
	var txtCEOverview = "AV Drives Overview";
	var txtMyBookOverview = "Desktop Overview";
	var txtMyPassportOverview = "Portable Overview";
	var txtDVROverview = "Home Entertainment Overview";
	var txtWDTVOverview = "WD TV Overview";
	var txtInternalOverview = "Internal Hard Drive Overview";
	var txtNetworkOverview = "Network Overview";
	var txtSSDOverview = "Solid State Storage Overview";
	
	var path = new String();
	var title, tokens, classname;
	var strBegin, strBody, strEnd, strText;
	var depth = 0;
	
	// get the document's path and title
	title = document.title;
	title = title.replace(": Buy Western Digital hard drives, external drives, laptop drives, USB 2.0 drives.","");
	path = location.pathname;

	
	if ((path.indexOf("/products/") != -1) || (path.indexOf("/support/") == 0) || (path.indexOf("/library/") == 0) || (server == "websupport") || (server == "rightnow") || (server == "young-america") || (server == "support"))

		classname = "blackpath";	// show white color
	else
		classname = "blackpath";	// show black color
		
	if ((path.indexOf("/support/") == 0) || (server == "websupport") || (server == "rightnow") || (server == "young-america") || (server == "support"))

	{
		strBody = showPathSupport(path, classname, "http://support.wdc.com", server);  //defined in /support/includes/support.js
   		document.write ("<span class=" + classname + "><a href=\"http://www.wdc.com/\" class=\"" + classname + "\">Home</a> " + strBody + "</span>");
	}
	else if (server == "investor")
	{		
		document.write ("<span class=\"blackpath\"><a href=\"http://www.wdc.com\" class=\"blackpath\">Home</a> > <a href=\"http://www.wdc.com/company/\" class=\"blackpath\">About WD</a> > <a href=\"http://199.230.26.96/wdc/index.shtml\" class=\"blackpath\">Investor Relations</a> > " + title + "</span>");
	}	
	else if (server == "localInvestor")
	{
		document.write ("<span class=\"blackpath\"><a href=\"/\" class=\"blackpath\">Home</a> > <a href=\"/company/\" class=\"blackpath\">About WD</a> > <a href=\"http://199.230.26.96/wdc/index.shtml\" class=\"blackpath\">Investor Relations</a> > " + title + "</span>");
	}
	else if (server == "jobpost")
	{
		document.write ("<span class=\"blackpath\"><a href=\"http://www.wdc.com/\" class=\"blackpath\">Home</a> > <a href=\"http://www.wdc.com/company/\" class=\"blackpath\">About WD</a> > <a href=\"http://www.wdc.com/company/employment/\" class=\"blackpath\">Employment</a> > <a href=\"http://www.wdc.com/company/employment/jobpost/\" class=\"blackpath\">Job Posting</a> > " + title + "</span>");
	}
	else if (server == "wdcStore")
	{

		document.write ("<span class=\"blackpath\"><a href=\"http://www.wdc.com/\" class=\"blackpath\">Home</a> > <a href=\"http://www.wdc.com/buy/wheretobuy.asp\" class=\"blackpath\">Store</a> > " + path + "</span>");
	}
	else 
	{
	  delim = "/";
	  stop = 0;
	  token = "";
	  tokenlink = "/";
	  strBody = "";

	  while (stop != -1)
	  {

		if (token == "Press Releases") 
			{
			strBody = strBody + "<a href=\"" + tokenlink + "\" class=" + classname + ">" + token + "</a> ";
			}
		else if (token == "Where to Buy")
			{
				strBody = strBody + "<a href=\"http://www.wdc.com/buy/wheretobuy.asp\" class=" + classname + ">" + token + "</a> > ";
			}
		else if (token != "")
			{
				strBody = strBody + "<a href=\"" + tokenlink + "\" class=" + classname + ">" + token + "</a> > ";
			}
	  	if (++depth > 4) break;	  	
	  	path = path.substring(stop+1, path.length);
	  	stop = path.indexOf(delim);
	  	token = path.substring(0, stop);
	  	tokenlink = tokenlink + token + "/";
	  	token = getDescription(token);
	  	if (token == "Fillrup")
	  		break;
	  } 

	if (((title != "") && (strBody == "")) || ((strBody != "") && (strBody[0] != '>')))
	{
		strBody = "> " + strBody;
	}
	var lcPath = path.toLowerCase();

	if ((typeof MarketSegment !='undefined' && MarketSegment == 3))//Internal Desktop
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=15\" class=\"" + classname + "\">" + txtInternalOverview + "</a> " + strBody;
	}
	else if ((title.indexOf("SSD") != -1) || (title.indexOf("Silicon") != -1))//Solid State page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=20\" class=\"" + classname + "\">" + txtSSDOverview+ "</a> >&nbsp;";
	}	
	else if ((title.indexOf("Western Digital SiliconDrive") != -1))//Solid State page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=20\" class=\"" + classname + "\">" + txtSSDOverview+ "</a> >&nbsp;";
	}	 	
	else if ((typeof MarketSegment !='undefined' && MarketSegment == 4 && title.indexOf("Mobile") != -1))//Internal Desktop
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=15\" class=\"" + classname + "\">" + txtInternalOverview + "</a> " + strBody;
	} 

	else if ((typeof MarketSegment !='undefined' && MarketSegment == 7))//CE Desktop
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=15\" class=\"" + classname + "\">" + txtInternalOverview + "</a> " + strBody;
	} 		
	else if ((typeof MarketSegment !='undefined' && MarketSegment == 8))//External Desktop
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=5\" class=\"" + classname + "\">" + txtExternalOverview + "</a> " + strBody;
	} 
	
	
	else if ((typeof MarketSegment !='undefined' && title.indexOf("My Passport AV") != -1))//DVR drive Overview
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=10\" class=\"" + classname + "\">" + txtDVROverview + "</a> " + strBody;
	} 	
	else if ((typeof MarketSegment !='undefined' && MarketSegment == 9))//External Portable
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=5\" class=\"" + classname + "\">" + txtExternalOverview + "</a> " + strBody;
	} 		
	else if ((typeof MarketSegment !='undefined' && MarketSegment == 10))//Home Entertainment
	{
	} 
	else if ((typeof MarketSegment !='undefined' && MarketSegment == 13))//Mac Overview
	{
	} 
	else if ((typeof MarketSegment !='undefined' && MarketSegment == 14))//External Network Overview
	{
	} 	
	else if ((typeof MarketSegment !='undefined' && MarketSegment == 15))//Internal Hard drive Overview
	{
	} 
		else if ((typeof MarketSegment !='undefined' && MarketSegment == 16))//DVR drive Overview
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=10\" class=\"" + classname + "\">" + txtDVROverview + "</a> " + strBody;
	} 
		else if ((typeof MarketSegment !='undefined' && MarketSegment == 30))//WDTV family Overview
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=10\" class=\"" + classname + "\">" + txtDVROverview + "</a> " + strBody;
	} 			
		else if ((title.indexOf("WD TV") != -1)&& (lcPath.indexOf("products.asp") != -1))//WD TV product page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=10\" class=\"" + classname + "\">" + txtDVROverview+ "</a> >&nbsp;";
	} 
	else if ((title.indexOf("My DVR") != -1)&& (lcPath.indexOf("products.asp") != -1))//DVRproduct page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=10\" class=\"" + classname + "\">" + txtDVROverview+ "</a> >&nbsp;";
	}			
		

	
	else if ((typeof MarketSegment !='undefined' && MarketSegment == 4 )||(title.indexOf("Desktop") != -1)&& (lcPath.indexOf("index.asp") != -1)||(title.indexOf("Passport") != -1)&& (path.indexOf("index.asp") != -1))//External
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=5\" class=\"" + classname + "\">" + txtExternalOverview + "</a> " + strBody;
	} 
	else if (typeof MarketSegment !='undefined' && MarketSegment == 2)//Desktop
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=3\" class=\"" + classname + "\">" + txtDesktopOverview + "</a> " + strBody;
	} 
	else if (typeof MarketSegment !='undefined' && MarketSegment == 1)//Enterprise
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=2\" class=\"" + classname + "\">" + txtEnterpriseOverview + "</a> " + strBody;
	}
	else if (typeof MarketSegment !='undefined' && MarketSegment == 3)//Mobile
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=4\" class=\"" + classname + "\">" + txtMobileOverview + "</a> " + strBody;
	}  
	else if (typeof MarketSegment !='undefined' && MarketSegment == 5)//CE
	{
		strBody = "> &nbsp;<a href=\"/en/products/index.asp?cat=7\" class=\"" + classname + "\">" + txtCEOverview + "</a> " + strBody;
	} 
	
		
	
	

	<!-- PRODUCT PAGES -->
	if (((title.indexOf("World") != -1)|| (title.indexOf("ShareSpace") != -1)) && (lcPath.indexOf("products.asp") != -1))//MyBook World product page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=14\" class=\"" + classname + "\">" + txtNetworkOverview + "</a> >&nbsp;";
	}	
	else if ((title.indexOf("My Book") != -1)&& (lcPath.indexOf("products.asp") != -1))//MyBook product page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=8\" class=\"" + classname + "\">" + txtMyBookOverview + "</a> >&nbsp;";
	}
		
	else if ((title.indexOf("My Passport AV") != -1))//Do nothing for now for media drives
	{

	} 
 	else if ((title.indexOf("Passport") != -1)&& (lcPath.indexOf("products.asp") != -1))//passport product page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=9\" class=\"" + classname + "\">" + txtMyPassportOverview + "</a> >&nbsp;";
	} 				
 	else if ((title.indexOf("WD TV") != -1)&& (lcPath.indexOf("products.asp") != -1))//WD TV product page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=30\" class=\"" + classname + "\">" + txtWDTVOverview + "</a> >&nbsp;";
	} 				
 
	else if ((title.indexOf("Passport") != -1)&& (lcPath.indexOf("products.asp") != -1))//passport product page
	{
		strBody += "&nbsp;<a href=\"/en/products/index.asp?cat=9\" class=\"" + classname + "\">" + txtMyPassportOverview + "</a> >&nbsp;";
	} 

	
	if (strBody.indexOf("Press Releases") == -1)
	{
	  	if (typeof FamilyName !='undefined' && FamilyName !='')
		{
		strBody = strBody + FamilyName ;
		}
		else
		{
		strBody = strBody + title ;
		}
	 }

	  document.write ("<span class=" + classname + "><a href=\"/\" class=\"" + classname + "\">Home</a> " + strBody + "</span>");
	}

}

function getDescription(token)
{
	switch(token)
	{
			case "wdapps":
			token = "WD Apps";
			break;
			case "2010":
			token = "";
			break;
		case "serialata":
			token = "Serial ATA";
			break;
		case "productreviews":
			token = "Product Reviews";
			break;
		case "ce":
			token = "AV";
			break;
		case "company":
			token = "About WD";
			break;
		case "branding":
			token = "Trademark Information";
			break;
		case "buy":
			token = "Where to Buy";
			break;
		case "products":
			token = "";
			break;
		case "current":
			token = "";
			break;
		case "retailkits":
			token = "";
			break;
		case "support":
			token = "Service & Support";
			break;
		case "partners":
			token = "Partners";
			break;
		case "signup":
			token = "New member"
			break;
		case "jobpost":
			token = "Job Posting"
			break;
		case "pr":
			token = "Press Room"
			break;
		case "releases":
			token = "Press Releases"
			break;
		case "uk":
			token = "UK"
			break;
		case "selectwd":
			token = "SelectWD"
			break;
		case "dlg":
			token = "Data Lifeguard"
			break;
		case "eide":
			token = "PATA"
			break;
		case "pata":
			token = "PATA"
			break;
		case "firewire":
			token = "FireWire"
			break;
		case "ata":
			token = "ATA"
			break;
		case "ace":
			token = "ACE"
			break;
		case "faqs":
			token = "FAQs"
			break;
		case "techinfo":
			token = "Technical Information"
			break;
		case "scsi":
			token = "SCSI"
			break;
		case "ide":
			token = "IDE"
			break;
		case "mac":
			token = "For Macintosh"
			break;
		case "pc":
			token = "For PC"
			break;
		case "library":
			token = "Document Library"
			break;
		case "greenpower":
			token = "GreenPower"
			break;
		case "common":
			token = ""
			break;			
		case "translate":
			token = "";
			break;		
		case "en":
//			token = "English"
			token = "";
			break;
		case "fr":
//			token = "French"
			token = "";
			break;
		case "de":
//			token = "German";
			token = "";
			break;
		case "sp":
//			token = "Spanish";
			token = "";
			break;
		case "jp":
//			token = "Japanese"
			token = "";
			break;
		case "ch":
//			token = "Chinese"
			token = "";
			break;		
		case "kr":
//			token = "Korean";
			token = "";
			break;
		case "ru":
//			token = "Russian";
			token = "";
			break;
		case "ch":
			token = "";
			break;
		case "th":
			token = "";
			break;
		case "pt":
			token = "";
			break;
		case "cn":
			token = "";
			break;
		case "ssd":
			token = "";
			break;
		case "wdsmartware":
			token = ""
			break;
		case "win7":
			token = ""
			break;
		case "advancedformat":
			token = "Advanced Format"
			break;
		case "learninglab":
			token = ""
			break;
		
		default:				
			token = capitalize(token);
	}

	return token;
}

function capitalize(token)
{
	token = token.toLowerCase();
	first = token.charAt(0).toUpperCase();
	token = first + token.substring(1, token.length);
	return token;
}

function checkSearch(form)
{
	if (form.args.value == "" ) 
	{
		alert("Please enter your search text to do the search!");
		form.args.focus();
		return false;
	}
	return true;
}
