function isIE()
{
	return( window.navigator.userAgent.indexOf("MSIE") != -1 );
}

function isNetscape6()
{
	return( window.navigator.userAgent.indexOf("Netscape6") != -1 );
}

if ( isIE() )
{
	document.onkeypress = IEhandler; 
}
else if ( isNetscape6() )
{
	document.addEventListener("keypress", NS6Handler, true);
}


function IEhandler() 
{
	if ( (window.event.keyCode == 13) && (window.event.srcElement.tagName == 'INPUT') )
	{	
		
		var okToSubmit = false;
		var element = document.getElementById(window.event.srcElement.PostingControlID);
		
		if(element!=null)
		{
		
			if(element.type=='image')
			{
				document.getElementById('PostingFacade1').name=element.name+".x";
				document.getElementById('PostingFacade1').value=1;

				document.getElementById('PostingFacade2').name=element.name+".y";
				document.getElementById('PostingFacade2').value=1;
				okToSubmit = true;
			}

			if(element.type=='button')
			{
				document.getElementById('PostingFacade1').name=element.name;
				document.getElementById('PostingFacade1').value=element.value;
				okToSubmit = true;
			}

			if(element.type=='submit')
			{
				document.getElementById('PostingFacade1').name=element.name;
				document.getElementById('PostingFacade1').value=element.value;
				okToSubmit = true;
			}

			window.event.keyCode = 0;
			
			if(okToSubmit)
			{
				document.forms[0].submit();
			}
		}
		else
		{
			window.event.keyCode = 0;
		}
	}	
}	

function NS6Handler(e)
{		
	if ( (e.which == 13) && (e.originalTarget.tagName == 'INPUT') )	
	{	
		e.cancelBubble = true;
	}			
}


function SwapImage(imageID, imageFile)
{
	document.getElementById(imageID).src = '/Internet/Images/' + imageFile;
}

function RedirectBrowser(redirectURL)
{
	location = redirectURL;
}

function PopupWindow(URL, width, height)
{
	var page = location.href;
	var popup;
	var windowprops = 'width='+width + ',height=' + height +',toolbar=no,titlebar=no,scrollbars=no,resizable=no,location=no,status=no,menubar=no'; 
	windowprops += ',top=' + parseInt((screen.availHeight/2)-(350/2)) + ',';
	windowprops += 'left=' + parseInt((screen.availWidth/2)-(350/2));
	popup = window.open(URL,page,windowprops); 
}

function PopupWindowOptions(URL, options)
{
	var page = location.href;
	var popup;
	var windowprops = options;
	
	if(options == '')
	{
		window.open(URL);
	}
	else
	{
		windowprops += ',top=' + parseInt((screen.availHeight/2)-(350/2)) + ',';
		windowprops += 'left=' + parseInt((screen.availWidth/2)-(350/2));
		popup = window.open(URL, page, windowprops);
	}
}
function ConfirmDelete()
{
	if (confirm("Are you sure you want to delete this item?"))
		return true;
	else
		return false;
}

function externalLinkClickHandler(link, culture)
{
    var host = location.host.toLowerCase();
    var protocol = location.protocol.toLowerCase();
    
	var link = eval(link);
    var linkUrl = link.href;
    var linkProtocol = (linkUrl.indexOf("https:")>=0) ? "https:" : "http:";
    var linkHostName = linkUrl.substring(linkProtocol.length+2, linkUrl.indexOf('/', linkProtocol.length+3));
    
    var isLocalSite = (host == linkHostName || linkHostName.toLowerCase().indexOf('novelis.co') > 0) ? 1 : 0;
    var isNovelisRelativeSite = false;
    
    if (linkHostName.indexOf('ohlerflexrohr.de') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('www.ohlerpackaging.de') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('alcangoettingen.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('pae.pechiney.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('www.thinkcans.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('phx.corporate-ir.net') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('webcasts.streamcanada.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('msds.arielresearch.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('www.novelis-painted.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('novelis.investorroom.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('novelis.mediaroom.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('evermorerecycling.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('rackspacecloud.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('3eonline.com') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('novelis-goettingen.de') >= 0)
		isNovelisRelativeSite = true;
	else if (linkHostName.indexOf('novelisfoileurope.com') >= 0)
		isNovelisRelativeSite = true;
		
    if (isLocalSite || isNovelisRelativeSite)
    {
        var containsPdf = linkUrl.indexOf(".pdf") >= 0;
        var containsWord = linkUrl.indexOf(".doc") >= 0;
        
		if (containsPdf || containsWord)
		{
			link["target"] = "_blank";
		}
		else
		{
			return true;
		}
	}
	else
	{
        if(linkUrl.indexOf("mailto:") >= 0)
        {
			return true;
        }
        else
        {
			var encodedHtml = escape(linkUrl);
			encodedHtml = encodedHtml.replace(/\//g,"%2F");
			encodedHtml = encodedHtml.replace(/\?/g,"%3F");
			encodedHtml = encodedHtml.replace(/=/g,"%3D");
			encodedHtml = encodedHtml.replace(/&/g,"%26");
			encodedHtml = encodedHtml.replace(/@/g,"%40");
		    
			var redirectUrl = "/Internet/"+culture+"/LeaveSite.htm?RedirectUrl="+encodedHtml;
			
			link["target"] = "_blank";
			
			if (link.href.indexOf('/LeaveSite.htm') == -1)
				link.href = redirectUrl;
		}
    } 
}
