function checkSource() {
	var bypass = 'F';

	//alert(document.referrer);

	if (document.referrer != "")
	{
		
		if (document.referrer == "http://www.portwell.com/index.htm") { bypass = 'T';}
		if (document.referrer == "http://www.portwell.com/") { bypass = 'T' ;}
		if (document.referrer == "http://www.portwell.com/index2.htm") { bypass = 'T';}
		//if (document.referrer == "http://www.portwell.com/home/") { autoRedirect('US');}
		if (document.referrer == "http://www.portwell.com/home/index.htm") { bypass = 'T';}
		if (document.referrer == "http://www.portwell.com.tw") {bypass = 'T';}
		//Subsidiary start (20090423)
		if (document.referrer == "http://www.portwell.com.cn") {bypass = 'T';}
		if (document.referrer == "http://www.portwelllaxsons.com") {bypass = 'T';}
		if (document.referrer == "http://www.portwell.co.jp") {bypass = 'T';}
		if (document.referrer == "http://www.portwell.nl") {bypass = 'T';}
		if (document.referrer == "http://www.portwell.co.uk") {bypass = 'T';}
		//Subsidiary end
		if (document.referrer == "http://www.google-analytics.com/") { bypass = 'T';}
	}

	if (bypass == 'F')
	{
		
		if (readCookie('Country') == null)
		{ 
			//alert("CountryCookieNotSet_CheckingGoogleCookies");
			createCookie('Country','UNKNOWN');
			if (document.referrer == "http://www.portwell.com/index.htm") {alert("fromitself");} 
			else
			{
				checkCookie('__utmz');
				checkCookie('__utma');
				checkCookie('__utmc');
				checkCookie('__utmb');
			}
			
		}
		else
		{
			if (readCookie('Country') != "UNKNOWN")
			{	
				//alert("autoredirect from readcookie where country is not unknown");
				autoRedirect(readCookie('Country'));
			}
			else
			{	//alert("autoredirect from readcookie where country is UNKOWN");
				checkCookie('__utmz');
				checkCookie('__utma');
				checkCookie('__utmc');
				checkCookie('__utmb');
			}
		}
	}
}

function deleteCookie(name)
{
		document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}	
		



	  function readCookie(name) 
	  {
		var c_namePair = name + "=";
		var c_cookie = document.cookie.split(';');
		for (var i=0;i < c_cookie.length;i++) {
			var c = c_cookie[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(c_namePair) == 0) return c.substring(c_namePair.length,c.length);
		}
		return null;
	  }
	
	  function checkCookie(name)
	  {
		//alert("function:checkCookie :- " + name );
		if (readCookie(name) != null) {autoRedirect(readCookie(name))};
		return;
	  }
	
	  function createCookie(name,value)
	  {	
		var c_expDays = 700; 
		var c_expDate = new Date();
		var c_name = name;   
		var c_value = value;

		//(c_name  == null) ? "Country" : c_name  = name;
		//(c_value == null) ? "US" 	: c_value = value;
		
		//alert("function:createCookie :- name: " + c_name + " | value: " + c_value );

		c_expDate.setDate(c_expDate.getDate() + c_expDays);
		document.cookie =  c_name +  " = " + c_value  + " ; expires = " + c_expDate.toGMTString() + "; path=/";
		
		return null;
	}
			
	  function autoRedirect(loc)
	  {
	    var loc = loc;
	    //alert("function:autoRedirect :- " + loc );

				
		switch (loc) {
			case 'US': 
				//createCookie('Country', loc);
				window.location.href = "http://www.portwell.com/index.htm";
				break;
			case 'TW':
				window.location.href = "http://www.portwell.com.tw";
				break;
			//Subsidiary start 20090423
			case 'CN':
				window.location.href = "http://www.portwell.com.cn";
				break;
			case 'IN':
				window.location.href = "http://www.portwelllaxsons.com";
				break;
			case 'JP':
				window.location.href = "http://www.portwell.co.jp";
				break;
			case 'NL':
				window.location.href = "http://www.portwell.nl";
				break;
			case 'UK':
				window.location.href = "http://www.portwell.co.uk";
				break;//Subsidiary end			
			/*default:
				window.location.href = "#";
				break;*/
		}
		return true;
	  }

