// Javascript written for the change of language in Practice Directions	
	function currentLocale() {
		//var loc = window.location;
		//var pathtmp = loc.pathname;
		var loc = document.location + "";
                //theIdx = theUrl.indexOf("lang=en");
		var pathtmp = loc;
		//alert(loc);
		var fromlang = '';
		if (pathtmp.indexOf('lang=CH')>=0) fromlang='chi';
		else if (pathtmp.indexOf('search')>=0){
		     if(pathtmp.indexOf('lang=CH')>=0){
		     	fromlang='chi';
		     }else{
		        fromlang='eng';
		     }
		}else fromlang='eng';
		return fromlang;
	}

		function changeLocale(tolang) {
			var loc = window.location;
			//var loc = document.location + "";
			var hostname = '';
			var pathprefix = '';
			var pathsuffix = '';
			var fromlang = '';
			
			if (tolang=='chi') tolang='chi';
			else tolang='eng';

			var pathtmp = loc.pathname;
			//var pathtmp=loc;
			var idx = -1;
			fromlang = currentLocale();
			//alert(pathtmp);			
			if (fromlang==tolang) return;
			hostname = loc.hostname;
			if (idx=pathtmp.indexOf('lang=CH') > 0 )
			{
				idx=pathtmp.indexOf('lang=CH');
				pathprefix=pathtmp.substring(idx, idx+11);		//	/CH/ 
				pathprefix="lang=EN";					//lang=EN
				pathsuffix=pathtmp.substring(idx+11);		
		        } else if (idx=pathtmp.indexOf('lang=EN') > 0 )
			{
				idx=pathtmp.indexOf('lang=EN');
				pathprefix=pathtmp.substring(idx, idx+10);		//	lang=EN 				
				pathprefix="lang=CH";					///CH/
				pathsuffix=pathtmp.substring(idx+10);		
			} else {
				var loc1=document.location + "";
				if (loc1.indexOf('lang=CH')>=0){
					pathsuffix=loc1.substring(loc1.indexOf('pdn=')+4,loc1.indexOf('.htm'));										
					window.top.location=loc.protocol + '//' + hostname + '/lrs/common/pd/pdcontent.jsp?pdn='+pathsuffix+'.htm&lang=EN';
					return;
				} else if (loc1.indexOf('lang=EN')>=0){
					pathsuffix=loc1.substring(loc1.indexOf('pdn=')+4,loc1.indexOf('.htm'));										
					window.top.location=loc.protocol + '//' + hostname + '/lrs/common/pd/pdcontent.jsp?pdn='+pathsuffix+'.htm&lang=CH';
					return;
				}else if (loc1.indexOf('search')>=0){
					pathsuffix=loc1.substring(loc1.indexOf('pdn=')+8,loc1.indexOf('#'));	
					if (tolang=='eng'){
					window.top.location=loc.protocol + '//' + hostname + '/lrs/common/pd/pdcontent.jsp?pdn='+pathsuffix;
					return;
					}else{
					window.top.location=loc.protocol + '//' + hostname + '/lrs/common/pd/pdcontent.jsp?pdn='+pathsuffix;
					return;
					}
				}
			}
			
			
			
			var destURL;
				destURL = loc.protocol + '//' + hostname + '/doc/' + pathprefix + pathsuffix;
			window.location = destURL;			
		}
		
	function genChiPD(Img0) {
		var tmp = '';
		var lcimgpath = '/lrs/images/';
		if (currentLocale()!='chi') {
			tmp = "<a href=\"javascript:changeLocale('chi')\" target=\"_self\">";
			tmp += "<img src=\""+lcimgpath+Img0+"\" alt=\"Switch to Chinese Practice Directions\" ";
			tmp += " border=\"0\"></a>";
		}
		document.write(tmp);
	}

	function genEngPD(Img0) {
		var tmp = '';
		var lcimgpath2 = '/lrs/images/';
		if (currentLocale()!='eng') {
			tmp = "<a href=\"javascript:changeLocale('eng')\" target=\"_self\">";
			tmp += "<img src=\""+lcimgpath2+Img0+"\" alt=\"Switch to English Practice Directions\" ";
			tmp += " border=\"0\"></a>";
		}
		document.write(tmp);
	}


	function genChiPDN(Img0) {
		var tmp = '';
		var lcimgpath = '/lrs/images/';
		if (currentLocale()!='chi') {
			tmp = "<a href=\"javascript:changeLocaleN('chi')\" target=\"_self\">";
			tmp += "<img src=\""+lcimgpath+Img0+"\" alt=\"Switch to Chinese Practice Directions\" ";
			tmp += " border=\"0\"></a>";
		}
		document.write(tmp);
	}

	function genEngPDN(Img0) {
		var tmp = '';
		var lcimgpath2 = '/lrs/images/';
		if (currentLocale()!='eng') {
			tmp = "<a href=\"javascript:changeLocaleN('eng')\" target=\"_self\">";
			tmp += "<img src=\""+lcimgpath2+Img0+"\" alt=\"Switch to English Practice Directions\" ";
			tmp += " border=\"0\"></a>";
		}
		document.write(tmp);
	}

	

	function changeLocaleN(tolang) {
			var loc = window.location;
			//var loc = document.location + "";
			var hostname = '';
			var pathprefix = '';
			var pathsuffix = '';
			var fromlang = '';
			
			var fname = 'PD18.1.htm';
			
			if (tolang=='chi') tolang='chi';
			else tolang='eng';

			var pathtmp = loc.pathname;
			//var pathtmp=loc;
			var idx = -1;
			fromlang = currentLocale();
			//alert(pathtmp);			
			if (fromlang==tolang) return;
			hostname = loc.hostname;
			
			//window.top.location=loc.protocol + '//' + hostname + '/doc/prac_dir/html/' + fname;			
			
			if (idx=pathtmp.indexOf('lang=CH') > 0 )
			{
				idx=pathtmp.indexOf('lang=CH');
				pathprefix=pathtmp.substring(idx, idx+11);		//	/CH/ 
				pathprefix="lang=EN";					//lang=EN
				pathsuffix=pathtmp.substring(idx+11);		
		        } else if (idx=pathtmp.indexOf('lang=EN') > 0 )
			{
				idx=pathtmp.indexOf('lang=EN');
				pathprefix=pathtmp.substring(idx, idx+10);		//	lang=EN 				
				pathprefix="lang=CH";					///CH/
				pathsuffix=pathtmp.substring(idx+10);		
			} else {
				var loc1=document.location + "";
				if (loc1.indexOf('cprac_dir')>=0){
					pathsuffix=loc1.substring(loc1.indexOf('pdn=')+4,loc1.indexOf('.htm'));										
					window.top.location=loc.protocol + '//' + hostname + '/doc/prac_dir/html/' + fname;
					return;
				} else if (loc1.indexOf('prac_dir')>=0){
					pathsuffix=loc1.substring(loc1.indexOf('pdn=')+4,loc1.indexOf('.htm'));										
					window.top.location=loc.protocol + '//' + hostname + '/doc/cprac_dir/html/' + fname;
					return;
				}else if (loc1.indexOf('search')>=0){
					pathsuffix=loc1.substring(loc1.indexOf('pdn=')+8,loc1.indexOf('#'));	
					if (tolang=='eng'){
					window.top.location=loc.protocol + '//' + hostname + '/doc/prac_dir/html/' + fname;
					return;
					}else{
					window.top.location=loc.protocol + '//' + hostname + '/doc/prac_dir/html/' + fname;
					return;
					}
				}
				
				
			}
			
			
			
			var destURL;
				destURL = loc.protocol + '//' + hostname + '/doc/' + pathprefix + pathsuffix;
			window.location = destURL;			
		}
