/*
linkCheck.js

Intercepts all links click requests and re-directs to a new window
if the link doesn't point to a page in a global directory with tax in the name.
(A directory under "gx/en/" that includes the word tax in the directory name)
Requires jQuery

Written by Brendon Hicks (brendon@elegantthought.com) for PricewaterhouseCoopers
Feb 2, 2010
*/



/*  The "newWindow " list contains text that, if found in a URL, will 
*   make the link open in a new window.
*   - Be careful not to put something very general, like ".jhtml" or "a" because
*   every URL with that text included anywhere in it will be affected.
*   - ONLY the part of the url AFTER the domain will be compared against.  So don't 
*   put in "http://www.pwc.com/gx/en/tax" as a value because it will never match.  Just
*   put in the part after the "www.pwc.com/".
*   - Don't forget:  commas after each value except the last.
*/


var newWindow = [  
	"publications/environmental-tax-regulation-monitor.jhtml",
	"tax/publications/assets/financing-sustainability-tax.pdf",
	"tax/publications/assets/eudtg-3rd-country-investors.pdf",
        "tax/publications/assets/income-tax-accounting-under-IFRS.pdf",
	"gx/pharma-life-sciences/pharma-2020/",
	"/legal/",
	"/hr-management-services/hr-international-assigment-services.jhtml"
];


/*  The "sameWindow" list contains text that, if found in a URL, will 
*   make the URL open in the same window (not a new one).
*   - Be careful not to put something very general, like ".jhtml" or "a" because
*   every URL with that text included anywhere in it will be affected.
*   - ONLY the part of the url AFTER the domain will be compared against.  So don't 
*   put in "http://www.pwc.com/gx/en/tax" as a value because it will never match.  Just
*   put in the part after the "www.pwc.com/".
*   - Don't forget:  commas after each value except the last.
*/

var sameWindow = [
	"internationaltp",
	"gx/en/automotive/transfer-pricing",
	"gx/en/international-transfer-pricing",
	"transfer-pricing-management-strategy",
	"taxfunctioneffectivenessbook",
	"gx/en/intellectual-property-life-cycle/index.jhtml",
	"gx/en/transfer-pricing-management-strategy/economic-uncertainty-recession.jhtml"
];




function inList(value, list){
// checks to see if any of the strings in the array "list" are contained in the string "value".
	value = value.toLowerCase();
	for(var i = 0; i < list.length; i++){
		if(value.indexOf(list[i].toLowerCase()) != -1){
			return true;
			break;
		}
	}
	
	return false;

}



$(function(){
	

	$("a").click(function(){

		

		
		
		if(this.protocol.toLowerCase() == "javascript:") return true;
		if(this.className.indexOf("yui") != -1) return true;

		var linkpath = this.pathname.toLowerCase();

		if(inList(linkpath,newWindow)) {
			window.open(this.href);
			return false;
		}

		if(inList(linkpath,sameWindow)) {
			location.href = this.href;
			return false;
		}

		if(linkpath.toLowerCase().indexOf(".pdf") != -1){
			window.open(this.href);
			return false;
		}

		if($(this).parents("#nav").length != 0){
			location.href = this.href;
			return false;
		}

		if(linkpath.indexOf("gx/en/") == -1 && linkpath.indexOf("en_gx/gx/")==-1) {
			window.open(this.href);
			return false;
		}
		else{
			if(linkpath.indexOf("tax") == -1){
				window.open(this.href);
				return false;
			} else{
				location.href = this.href;
				return false;
			}
		}
	});

});
