function swapImgRestore() { //v3.0
	var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.p) d.p=new Array();
	var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.01
	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=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
	var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
 	if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function tempobj(url){
	this.href = url;		
	var lhref = url.indexOf(':\/\/');
	if ( lhref > 0 ){
		this.hostname = url.substring(lhref+3,url.length)
		this.hostname = this.hostname.substring(0,(this.hostname.indexOf('\/')))
	}
	else this.hostname = url;
}

function openDocWindow(url) {	
	var linkObj = new tempobj(url);
	convertHostListToLowerCase();
	if (isHostInternal(linkObj)) {
		window.open(url, '', 'location=no,status=no,toolbar=no,menubar=yes,directories=no,resizable=yes,scrollbars=yes');
	} else {
		writeLegalDisclaimer(linkObj);
	}
}

function openNewWindow(url) {
	window.open(url, '', 'width=700,height=450,location=no,status=no,toolbar=no,directories=no,resizable=yes,scrollbars=yes');
}

function closeDocWindow() {
	window.close();
}


function openLegalDisclaimer(linkObj) {
	
	
	// checks whether the domain of the Link object passed as a parameter is part of a list of internal domains.
	// If the domain is listed as being 'internal' or the same as in the currently displayed URL, the link
	// will be opened in the same window.
	// Otherwise, the function will generate HTML for the legal disclaimer with a link to continue to the
	// parameter URL.
	convertHostListToLowerCase();
		
	var intExtHost = isHostInternal(linkObj);
	
	if (intExtHost) {
		if (isNonHTMLExtension(linkObj.href)) {
			window.open(linkObj.href,'wHndNonHTMLWindow');
		} else if (intExtHost == 1) {
			window.document.location	= linkObj.href;
		} else {	
			window.open(linkObj.href,'wHndHTMLWindow');
		}
	} else {
		writeLegalDisclaimer(linkObj);
	}
}


function isNonHTMLExtension(theURL) {
	var Ext			= new Array();
	// graphics
	Ext[0]			= '.gif';
	Ext[1]			= '.jpg';
	Ext[2]			= '.jpeg';
	Ext[3]			= '.jpe';
	// other media
	Ext[4]			= '.avi';
	Ext[5]			= '.mpg';
	Ext[6]			= '.mpe';
	Ext[7]			= '.mpeg';
	Ext[8]			= '.qt';
	Ext[9]			= '.mov';
	Ext[10]			= '.mpv';
	Ext[11]			= '.mp3';
	// office docs
	Ext[12]			= '.pdf';
	Ext[13]			= '.doc';
	Ext[14]			= '.xls';
	Ext[15]			= '.ppt';
	Ext[16]			= '.vcd';
	Ext[17]			= '.vcf';
	// zip and exe files
	Ext[18]			= '.zip';
	Ext[19]			= '.exe';


	var theExt		= '';
	var dot			= false;
	var foundExt	= false;
	var i			= 0;
	var j			= theURL.length - 1;

	// attempt to find '.' in the last 6 characters of the url -- stop at dot, if found.
	while ((j > (theURL.length - 7)) & (!dot)) {
		if (theURL.charAt(j) == '.') {
			dot		= true;
		} else {
			j--;
		}
	}
	// if a '.' was found in the last 6 characters of the url,
	if (dot) {
		// get the last 6 chars,
		theExt	= theURL.substring(j, theURL.length);
		//make lowercase...
		theExt	= theExt.toLowerCase();
		// and check if url ends in one of the specified extensions
		while ((i < (Ext.length)) & (!foundExt)) {
			if (Ext[i] == theExt) {
				foundExt	= true;
			}
			i++;
		}
	}
	
	if (foundExt) {
		return true;
	} else {
		return false;
	}
}


function convertHostListToLowerCase() {
	// converts the array of internal hosts to lowercase for reliable string comparison.
	for (var i = 0; i < (intHost.length); i++) {
		intHost[i]	= intHost[i].toLowerCase();
	}
}


function isHostInternal(linkObj) {
	// tests whether the linkObject's href is the same as the current url. if not,
	// it tests against the entries in the internal host array.

	// extract hostname from current url
	var currentHost			= document.URL;
	var isInternalResult	= 0;
	// strip protocol
	var pos					= currentHost.indexOf(':\/\/');
	if (pos > -1) {
		currentHost			= currentHost.substring((pos + 3), (currentHost.length - 1));
	}
	// strip path / filename
	pos						= currentHost.indexOf('\/');
	if (pos > -1) {
		currentHost			= currentHost.substring(0, pos);
	}
	// convert to lowercase
	currentHost				= currentHost.toLowerCase();

	var linkHost			= linkObj.hostname;
	linkHost				= linkHost.toLowerCase();
	
	// is the linkObj hostname the same as the one of the current url?
	if (currentHost == linkHost || linkObj.href.indexOf(':\/\/') < 0) {
		isInternalResult	= 1;
	} else if (linkHost.indexOf('dupont.com') != -1) {
		isInternalResult	= 2;
	} else {
		// if not: is the linkObj hostname listed in the list of internal domains?
		var count			= 0;
		while ((count < (intHost.length)) & (!isInternalResult)) {
			if (intHost[count] == linkHost) {
				isInternalResult	= 1;
			}
			count++;
		}
		if (!isInternalResult) {
			var count			= 0;
			while ((count < (extHost.length)) & (!isInternalResult)) {
				if (extHost[count] == "") {
					count++;
					continue;
				}
				if ((extHost[count] == linkHost)) {
					isExtInternalResult	= 2;
					return isExtInternalResult;
				}
				count++;
			}
		}
	}
	return isInternalResult;
}


function writeLegalDisclaimer(linkObj) {
 /*Begin PQR#9911051*/
 		//var url				= '?&page=LegalDisclaimer&popup&url=' + escape(linkObj.href);
 		var url				= '?&page=LegalDisclaimer&popup&format=toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1&url='+ escape(linkObj.href);
 /*End PQR#9911051*/
 
	var wHndLegalDisc	= window.open(url, 'wHndLegalDisc', 'width=300,height=420,scrollbars=yes');	
}


function openLocation(formObj, opt) {
	if (formObj != null) {
		switch (opt) {
			case 'language':
				selectObj = formObj.languageSelect;	
				break;				
			case 'country':
				selectObj = formObj.countryRedirectList;
				break;				
			case 'countries':
				selectObj = formObj.countries;
				break;
		}			
		
		if (selectObj != null && selectObj.length > 0) {
			selectedOption = selectObj.options[selectObj.selectedIndex];
			if (selectedOption != null) {
				option = selectedOption.value;
				// only go to values that look like urls
				if (option != "" && (option.indexOf("/") == 0 || option.indexOf("http") == 0) && option.indexOf("####") == -1) {
					top.location.href = option;
				}
			}
		}
	}
}


function processSelect()
{
	var formObj;
  /* Look at all forms in the page */
  for( var i=0; i<document.forms.length;i++)
  {
    /* Loop through each element in the form */
    for( var j=0;j<document.forms[i].elements.length;j++)
    {
       /* Is it languageSelect? */
       if( document.forms[i].elements[j].name == "languageSelect" )
       {
			 	formObj = document.forms[i];
       }
     }
  }
	openLocation(formObj,'language');
}

function openLegalDisclaimer2(direction,format){
	var direction1=direction;
	var url				= '?&page=LegalDisclaimer&popup&format=' + format+ '&url='+ escape(direction1);
	var wHndLegalDisc	= window.open(url, 'wHndLegalDisc', 'width=300,height=420,scrollbars=yes');	
}

