﻿function SwitchLang(lang) {

var gopath;
	if (top.location.href.indexOf("#") != -1) {
		locationx = top.location.href.substring(0, top.location.href.indexOf("#"));
	} else {
		locationx = top.location.href;
	}
	if (lang == 'eng') {
		if (locationx.indexOf("/eng/") == -1) {
			if (locationx.indexOf("/chs/") != -1) {
				gopath = top.location.replace(locationx.replace("/chs/","/eng/"));
			} else if (locationx.indexOf("/chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/chi/","/eng/"));
			} else if (locationx.indexOf("/text_chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_chi/","/eng/"));
			} else if (locationx.indexOf("/text_chs/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_chs/","/eng/"));
			} else if (locationx.indexOf("/text_eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_eng/","/eng/"));
			}
		}
	} else if (lang == 'chs') {
		if (locationx.indexOf("/chs/") == -1) {
			if (locationx.indexOf("/eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/eng/","/chs/"));
			} else if (locationx.indexOf("/chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/chi/","/chs/"));
			} else if (locationx.indexOf("/text_chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_chi/","/chs/"));
			} else if (locationx.indexOf("/text_chs/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_chs/","/chs/"));
			} else if (locationx.indexOf("/text_eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_eng/","/chs/"));
			}
		}
	} else if (lang == 'chi') {
		if (locationx.indexOf("/chi/") == -1) {
			if (locationx.indexOf("/eng/") != -1) {
		 		gopath = top.location.replace(locationx.replace("/eng/","/chi/"));
			} else if (locationx.indexOf("/chs/") != -1) {
		 		gopath = top.location.replace(locationx.replace("/chs/","/chi/"));
			} else if (locationx.indexOf("/text_chi/") != -1) {
		 		gopath = top.location.replace(locationx.replace("/text_chi/","/chi/"));
			} else if (locationx.indexOf("/text_chs/") != -1) {
		 		gopath = top.location.replace(locationx.replace("/text_chs/","/chi/"));
			} else if (locationx.indexOf("/text_eng/") != -1) {
		 		gopath = top.location.replace(locationx.replace("/text_eng/","/chi/"));
			}
		}
	} else if (lang == 'text_chi') {
		if (locationx.indexOf("/text_chi/") == -1) {
			if (locationx.indexOf("/eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/eng/","/text_chi/"));
			} else if (locationx.indexOf("/chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/chi/","/text_chi/"));
			} else if (locationx.indexOf("/chs/") != -1) {
				gopath = top.location.replace(locationx.replace("/chs/","/text_chi/"));
			} else if (locationx.indexOf("/text_chs/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_chs/","/text_chi/"));
			} else if (locationx.indexOf("/text_eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_eng/","/text_chi/"));
			}
		}
	} else if (lang == 'text_chs') {
		if (locationx.indexOf("/text_chs/") == -1) {
			if (locationx.indexOf("/eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/eng/","/text_chs/"));
			} else if (locationx.indexOf("/chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/chi/","/text_chs/"));
			} else if (locationx.indexOf("/text_chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_chi/","/text_chs/"));
			} else if (locationx.indexOf("/chs/") != -1) {
				gopath = top.location.replace(locationx.replace("/chs/","/text_chs/"));
			} else if (locationx.indexOf("/text_eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_eng/","/text_chs/"));
			}
		}
	} else if (lang == 'text_eng') {
		if (locationx.indexOf("/text_eng/") == -1) {
			if (locationx.indexOf("/eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/eng/","/text_eng/"));
			} else if (locationx.indexOf("/chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/chi/","/text_eng/"));
			} else if (locationx.indexOf("/text_chi/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_chi/","/text_eng/"));
			} else if (locationx.indexOf("/text_chs/") != -1) {
				gopath = top.location.replace(locationx.replace("/text_chs/","/text_eng/"));
			} else if (locationx.indexOf("/chs/") != -1) {
				gopath = top.location.replace(locationx.replace("/chs/","/text_eng/"));
			}
		}
	} 
	
}

