/*
Javascript Function Index
------------------------------
toggleDiv(): Hide/show a DIV by its id attribute
toggleMenu(): Hide/show a menu and its related items
printReady(): Print friendly version of content section
*/

/*
Function:   toggleDiv
Description:Toggles the hide/show of the div
Parameters: "divid", id attribute of the target div element
Return:     [nothing]
Browser Compatability (tested): IE6
*/
function toggleDiv(divid){ 
    if(document.getElementById(divid).style.display == 'none'){ 
        document.getElementById(divid).style.display = 'block'; 
    }else{ 
        document.getElementById(divid).style.display = 'none'; 
    } 
} 

/*
Function:   toggleMenu
Description:Hide/show a menu and its related items
Parameters: "divid", id attribute of the target div element
				 "number", number of elements to action
Return:     [nothing]
Browser Compatability (tested): IE6
*/
function toggleMenu(divid){
   if (divid=='Marketing')
   {
		document.getElementById('Marketing').style.display = 'block';
		/*document.getElementById('liMarketing').style.background='#EEEEEE';*/
		if (document.getElementById('Need').style.display == 'block')
	   {
			document.getElementById('Need').style.display = 'none';
		}
		if (document.getElementById('Sales_Management').style.display == 'block')
	   {
			document.getElementById('Sales_Management').style.display = 'none';
		}
		if (document.getElementById('Technology').style.display == 'block')
	   {
			document.getElementById('Technology').style.display = 'none';
		}
		if (document.getElementById('Finance').style.display == 'block')
	   {
			document.getElementById('Finance').style.display = 'none';
		}
		if (document.getElementById('Marketing_Strategy').style.display == 'block')
	   {
			document.getElementById('Marketing_Strategy').style.display = 'none';
		}
	}
	if (divid=='Sales_Management')
   {
		document.getElementById('Sales_Management').style.display = 'block';
		if (document.getElementById('Need').style.display == 'block')
	   {
			document.getElementById('Need').style.display = 'none';
		}
		if (document.getElementById('Marketing').style.display == 'block')
	   {
			document.getElementById('Marketing').style.display = 'none';
		}
		if (document.getElementById('Technology').style.display == 'block')
	   {
			document.getElementById('Technology').style.display = 'none';
		}
		if (document.getElementById('Finance').style.display == 'block')
	   {
			document.getElementById('Finance').style.display = 'none';
		}
		if (document.getElementById('Marketing_Strategy').style.display == 'block')
	   {
			document.getElementById('Marketing_Strategy').style.display = 'none';
		}
	}
	if (divid=='Technology')
   {
		document.getElementById('Technology').style.display = 'block';
		if (document.getElementById('Need').style.display == 'block')
	   {
			document.getElementById('Need').style.display = 'none';
		}
		if (document.getElementById('Sales_Management').style.display == 'block')
	   {
			document.getElementById('Sales_Management').style.display = 'none';
		}
		if (document.getElementById('Marketing').style.display == 'block')
	   {
			document.getElementById('Marketing').style.display = 'none';
		}
		if (document.getElementById('Finance').style.display == 'block')
	   {
			document.getElementById('Finance').style.display = 'none';
		}
		if (document.getElementById('Marketing_Strategy').style.display == 'block')
	   {
			document.getElementById('Marketing_Strategy').style.display = 'none';
		}
	}
	if (divid=='Finance')
   {
		document.getElementById('Finance').style.display = 'block';
		if (document.getElementById('Need').style.display == 'block')
	   {
			document.getElementById('Need').style.display = 'none';
		}
		if (document.getElementById('Sales_Management').style.display == 'block')
	   {
			document.getElementById('Sales_Management').style.display = 'none';
		}
		if (document.getElementById('Technology').style.display == 'block')
	   {
			document.getElementById('Technology').style.display = 'none';
		}
		if (document.getElementById('Marketing').style.display == 'block')
	   {
			document.getElementById('Marketing').style.display = 'none';
		}
		if (document.getElementById('Marketing_Strategy').style.display == 'block')
	   {
			document.getElementById('Marketing_Strategy').style.display = 'none';
		}
	}
	if (divid=='Marketing_Strategy')
   {
		document.getElementById('Marketing_Strategy').style.display = 'block';
		if (document.getElementById('Need').style.display == 'block')
	   {
			document.getElementById('Need').style.display = 'none';
		}
		if (document.getElementById('Sales_Management').style.display == 'block')
	   {
			document.getElementById('Sales_Management').style.display = 'none';
		}
		if (document.getElementById('Technology').style.display == 'block')
	   {
			document.getElementById('Technology').style.display = 'none';
		}
		if (document.getElementById('Finance').style.display == 'block')
	   {
			document.getElementById('Finance').style.display = 'none';
		}
		if (document.getElementById('Marketing').style.display == 'block')
	   {
			document.getElementById('Marketing').style.display = 'none';
		}
	}
}

/*
Function:   printReady
Description:Print friendly version of content section
Parameters: "divid", id attribute of the target div element 'printReady'
Return:     [nothing]
Browser Compatability (tested): 
*/
function printReady()
{
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n' + '\n<br>\n';
		
		var printReadyElem = document.getElementById("printReady");
						
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;				
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Only for IE 5.0+ or Netscape 6.0+");
	}
}

/*
Function:   checkForm
Description:Check that all input fields on the page are filled in
Parameters: "this", the current form that needs to be checked
Return:     [true/false]
Browser Compatability (tested): 
*/
function checkform(form_name)
{
    num_elements = form_name.elements.length;
    var flag = true;
	var checkthiselement; 
    var ename;     
    var tstfield=-1;
    for (i = 0; i < num_elements; i++)
    {    
	      checkthiselement = true; 
    	  ename = form_name.elements[i].name; 
//       	  if (ename == "name1" || ename == "name2")  //put exempt elements here 
       	  if (ename.substr(0,1) == "@")  //put exempt elements here 
           { 
				checkthiselement = false; 
            } 
                
        etype = form_name.elements[i].type;
//* Test if text field        
        if (etype == "text" && checkthiselement == true)
        {
            var ev = form_name.elements[i].value;
            if(ev == "" || ev == form_name.elements[i].defaultValue)
            {
                form_name.elements[i].style.backgroundColor = "#ffcc00";
                if (tstfield==-1)
                {tstfield=i;}
                flag = false;
            }
            else
            {
                form_name.elements[i].style.backgroundColor = "#ffffff";
            }
        }
        else
        {
//* Test if listbox        
        if (etype == "select-one" && checkthiselement == true)
        {
            var ev = form_name.elements[i].value;
            if(ev == "" || ev == "Please Select")
            {
                form_name.elements[i].style.backgroundColor = "#ffcc00";
                if (tstfield==-1)
                {tstfield=i;}
                flag = false;
            }
            else
            {
                form_name.elements[i].style.backgroundColor = "#ffffff";
            }
        }
        
//        	alert(form_name.elements[i].name+" : data type = "+etype+", value= "+form_name.elements[i].value);
        }
    }
    if (flag == false) {
     alert("Please complete the highlighted fields in order to submit the form");
     form_name.elements[tstfield].focus();
    }
    return flag;
}

/*
Function:   echeck
Description:Check that an email address is valid
Parameters: "el_name", the input element that contains the email address
Return:     [true/false]
Browser Compatability (tested): 
*/
function echeck(el_name) {
  
    var at = "@";
    var dot = ".";
    var str = el_name.value;
    var lat = str.indexOf(at);
    var lstr = str.length;
    var ldot = str.indexOf(dot);
    var flag = true;

    if(str.indexOf(at) == -1)
    {
        flag = false;
    }
    if(str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr)
    {
        flag = false;
    }
    if(str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr)
    {
        flag = false;
    }
    if(str.indexOf(at, (lat + 1)) != -1)
    {
        flag = false;
    }
    if(str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot)
    {
        flag = false;
    }
    if(str.indexOf(dot, (lat + 2)) == -1)
    {
        flag = false;
    }
    if(str.indexOf(" ") != -1)
    {
        flag = false;
    }
  
    if(flag == false)
    {
        alert("Invalid Email Address. Please try again");
        el_name.focus(); 
    }
  
    return flag;
}

//*************************************************************
//* This function takes the two letter country code from a 
//* pull down list, constructs the URL and drives that in the 
//* _Top frame. 
//*************************************************************
function countryPage(selector) {
  var s = "http://www.dnb.com/" + selector.options[selector.selectedIndex].value;
  if (s) { parent.location = s  }
}

//*************************************************************
//* This function gets a cookie value
//*************************************************************
function Get_Cookie(name) {
  var start = document.cookie.indexOf(name+"=");
  var len = start+name.length+1;
  if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
  if (start == -1) return null;
  var end = document.cookie.indexOf(";",len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end));
}

//*************************************************************
//* This function sets a cookie value
//*************************************************************
function Set_Cookie(name,value,expires,path,domain,secure) {
  if (path == "undefined" || path == null) {
    path = "/" ;    	
  }
  document.cookie = name + "=" +escape(value) +
    ( (expires) ? ";expires=" + expires.toGMTString() : "") +
    ( (path) ? ";path=" + path : "") + 
    ( (domain) ? ";domain=" + domain : "") +
    ( (secure) ? ";secure" : "");
}

//*************************************************************
//* This function deletes a cookie value
//*************************************************************
function Delete_Cookie(name,path,domain) {
  if (Get_Cookie(name)) document.cookie = name + "=" +
    ( (path) ? ";path=" + path : "") +
    ( (domain) ? ";domain=" + domain : "") +
    ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

//*************************************************************
//* This function checks to see if cookies are enabled. 
//*************************************************************
function isCookieEnabled() {
   if (document.all) return navigator.cookieEnabled;
   var today = new Date();
   Set_Cookie('testcookie',today.getTime());
   var tc = Get_Cookie('testcookie');
   Delete_Cookie('testcookie');
   return (tc == today.getTime());
}

function Save_CompNo() {
	var CompNo = eval("DR1");
	document.cookie ="Companies_Number="+CompNo;	
}

//* Variables formally web parameters
var DnBCopyRight = "Copyright &copy; Dun &amp; Bradstreet Inc., 2008. All Rights Reserved"
function copyRight() {
  document.write(DnBCopyRight);
}

function MakeBlue(butn) {
  butnam="im"+butn
  document.getElementById(butnam).style.background = "url('Images/Homepage/empty_button_blue.png')" ;
//  document.getElementById(butnam).style.background = "url('Images/Homepage/buttonBlue1.gif')" ;
  texnam="tm"+butn
  document.getElementById(texnam).style.color='#FFFFFF';
//  document.getElementById(butn).style.fontWeight='normal';
}

function MakeYellow(butn) {
  butnam="im"+butn
  document.getElementById(butnam).style.background = "url('Images/Homepage/empty_button_yellow.png')" ;
//  document.getElementById(butnam).style.background = "url('Images/Homepage/buttonYellow1.gif')" ;
  texnam="tm"+butn
  document.getElementById(texnam).style.color='#000066';
//  document.getElementById(butn).style.fontWeight='bold';
}

//***************************************************************
//* This functions pops up the OLA search Window
//***************************************************************

function OlaPopup(Search) {
  olalink = "http://dnben.custhelp.com/cgi-bin/dnben.cfg/php/enduser/std_alp.php?p_new_search=1&p_scf_c_country_en=9" ;

 if (Search != null) {
    strSearch = ""
    for (i=0; i<Search.length; i++) {
      t = Search.charAt(i);
      if (t == '+') {
        t='%2B'
      }
      strSearch = strSearch + t
    }
//    olalink = olalink + '&p_search_text=xSTA %2B' + strSearch ;
    olalink = olalink + '&p_search_text=' + strSearch ;
  }

  window.open(olalink);
}

//*************************************************************
//* This function pops up a new window with no toolbars etc.
//*************************************************************
function popUpN(URL, ScrollBars, ReSizable, Width, Height) {
  if (ScrollBars == null) { 
    ScrollBars = "yes" ;
  }
  if (ReSizable == null) { 
    ReSizable = "yes" ;
  }
  if (Width == null) { 
    Width = "640" ;
  }
  if (Height == null) { 
    Height = "400" ;
  }
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbars=no,scrollbars=" + ScrollBars + ",location=no,statusbars=no,menubar=no,resizable=" + ReSizable + ",width=" + Width + ",height=" + Height + ",left=100,top=100');");
}

function XML_DOM_old(langcd, ctry) {
 pathn = "CountryList.xml";
 var txj = new Array();
 
//*** Code for IE ***
if (window.ActiveXObject) 
{
 var XMLDoc = new ActiveXObject("Microsoft.XMLDOM"); 
 }
//*** Code for Mozilla, Firefow, Opera, etc... ***
else if (document.implementation &&
 document.implementation.createDocument)
 {
 var XMLDoc = document.implementation.createDocument("","doc",null);
 }
else
 {
 alert('Your browser cannot handle this script!');
 }
 XMLDoc.async = "false";
 XMLDoc.load(pathn);  

//'*** Create XPath selection with Language code *** 
 xpath = "/Languages/lang[@code='"+langcd+"']";
 var x = XMLDoc.selectNodes(xpath);

// '*** Find attribute "boxtxt" value = attribute 2 ***
  txj[0]="<option selected>" + x[0].getAttribute('boxtxt') + "</option>";
 
 //'*** Create XPath for Countries in this Language *** 
 xpath = xpath + "/country";
 var x = XMLDoc.selectNodes(xpath);

//*** This doesn't work with NetScape and Firefox ??? ***
 for (i = 0; i < x.length; i++)
 {
  ctrycd = x[i].getAttribute('code')
  if (ctrycd != ctry) {
	  j=i+1;
	  //*** Only Select Elements for this language code ***
	  txj[j]="<option value='"+ ctrycd + "'>" +x[i].childNodes[0].nodeValue+"</option>";
 	 }
  }
  
 for (i = 0; i < j+1; i++)
  document.write(txj[i]+'\r');
  
}
//*************************************************************
//* This function checks to see if the Loc parameter is 
//* specifed on the frame URL and then selects the correct
//* page.  It is used when a user calls a page in the web directly
//* so that the Frame environment can be loaded. 
//*************************************************************
function checkLoc() {
 var NewLink="../Default.asp";    
//* Find parameter, else goto default page
  if (parent.location.search) {
    sArray = parent.location.search.split("=") ;
  var NewLoc = sArray[1].toUpperCase() ;
    if (NewLoc=="ABOUT/CONDS.HTM") {
	    NewLink="../about/legal.asp";
	    }
    if (NewLoc=="SITE_MAP.HTM") {
	    NewLink="../about/sitemap.asp";
	    }
	}   	
  location.replace(NewLink) ;    
}

//*** Change button Colors ***
function TopBlue(butn) {
  butnam="imt"+butn
  document.getElementById(butnam).style.backgroundColor= '#000066';
  texnam="tmt"+butn
  document.getElementById(texnam).style.color='#FFFFFF';
}

function TopYellow(butn) {
  butnam="imt"+butn
  document.getElementById(butnam).style.backgroundColor= '#ffcc00' ;
  texnam="tmt"+butn
  document.getElementById(texnam).style.color='#000066';
}
function Move_Center(objnam) {
 var xx=document.getElementById(objnam);
// xw = 460 - (xx.offsetWidth/2);
// xh = 245 - (xx.offsetHeight/2);
 xw = (document.body.offsetWidth - xx.offsetWidth)/2;
 xh = (document.body.offsetHeight - xx.offsetHeight)/2;
 xx.style.left = xw;
 xx.style.top = xh;
 xx.style.visibility='visible';
}

function Move_Div(objnam) {
 var xx=document.getElementById(objnam);
 xh = 30;
 xz = (document.body.offsetWidth-document.getElementById('header').offsetWidth)/2;
 if (xz<0)  xz = 0;
 xw = xz + 160;
 xx.style.left = xw;
 xx.style.top = xh;
 xx.style.visibility='visible';
}

//*************************************************************
//* This function shows the specified layer
//*************************************************************
function showLayer(lName) {
  document.getElementById([lName]).style.visibility='visible';
}

//*************************************************************
//* This function hides the specified layer
//*************************************************************
function hideLayer(lName) {
  document.getElementById([lName]).style.visibility='hidden';
}

function StartClock() {
 var Logo1= document.getElementById('Logo1').style;
 var Logo2= document.getElementById('Logo2').style;
 
if (Logo1.visibility == 'visible') {
 Logo1.visibility='hidden';
 Logo1.display='none';
 Logo2.visibility='visible';
 Logo2.display='block';
 }
else {
 Logo1.visibility='visible';
 Logo1.display='block';
 Logo2.visibility='hidden';
 Logo2.display='none';
 }

 var timer1 = setTimeout("StartClock();", 3000);
}

//******************************************
//*** New XML functions for Country list ***
//******************************************
function XML_DOM(langcd, ctry) {
xml=loadXMLDoc("CountryList.xml");

//*** Find records for this language ***
path = "/Languages/lang[@code='"+langcd+"']";

// Find text from header record, attribute='boxtxt'
//*** code for IE ***
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
document.write("<option selected>" + nodes[0].getAttribute('boxtxt') + "</option>");
}

//*** code for Mozilla, Firefox, Opera, etc. ***
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();
document.write("<option selected>" + result.getAttribute('boxtxt') + "</option>");

}
//*** Find all Countries for this language ***
path = path +"/country";

//*** code for IE ***
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);

//*** Select Elements for this language code ***
for (i=0;i<nodes.length;i++)
  {
  ctrycd = nodes[i].getAttribute('code')
  //*** Exclude this country ***
  if (ctrycd != ctry) {
	  document.write("<option value='"+ ctrycd + "'>" +nodes[i].childNodes[0].nodeValue+"</option>");
 	 }
  }
}

//*** code for Mozilla, Firefox, Opera, etc. ***
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();

//*** Select Elements for this language code ***
while (result)
  {
  ctrycd = result.getAttribute('code')
  //*** Exclude this country ***
  if (ctrycd != ctry) {
	  document.write("<option value='"+ ctrycd + "'>" +result.childNodes[0].nodeValue+"</option>");
 	 }
  result=nodes.iterateNext();
  }
}
}
function loadXMLDoc(fname)
{
var xmlDoc;
//*** code for Chrome ***
if (window.XMLHttpRequest)
{
  xmlDoc=new window.XMLHttpRequest();
  xmlDoc.open("GET",fname,false);
  xmlDoc.send("");
  xmlDoc=xmlDoc.responseXML;
}
//*** code for IE ***
// IE 5 and IE 6
else if (window.ActiveXObject)
//if (ActiveXObject("Microsoft.XMLDOM"))
{
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.load(fname);
}
//*** code for Mozilla, Firefox, Opera, etc. ***
else if (document.implementation && document.implementation.createDocument)
  {
  xmlDoc=document.implementation.createDocument("","",null);
  xmlDoc.async=false;
  xmlDoc.load(fname);
  }
else
  {
  alert('Your browser cannot handle this script');
  }
return(xmlDoc);
}


