function loadXML(url) {
	var xmlhttp = null;
	function state_Change() {
		switch (xmlhttp.readyState) {
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				if (xmlhttp.status == 200) {
					//parse xml
					//parseXML(xmlhttp.responseXML);
					//parseXML(xmlhttp.responseText);
					//alert(xmlhttp.responseText);
				} else {
					alert("Not able to retrieve description" + xmlhttp.statusText);
				}
				break;
			default:
				break;
		}
	}
	// code for Mozila, Safari, ..., IE 7.0
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {  // code for IE 6.0, 5.0
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp != null) {
		//alert(url);
		xmlhttp.open("GET", url, true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
		xmlhttp.onreadystatechange = state_Change;
		xmlhttp.send(null);
	} else {
		alert("Your browser does not support XMLHTTP.");
	}
}

function getEventTarget(e) {
	var targ;
	// ie
	if (!e) var e = window.event;
	// firefox
	if (e.target) {
		targ = e.target;
	} else if (e.srcElement) {
		targ = e.srcElement;
	}
	if (targ.nodeType == 3) { // defeat Safari bug
		targ = targ.parentNode;
	}
	return targ;
}

//檢查物件是否存在，不存在就設定為"空值"
function checkNull(obj){
	if(obj){
		return obj;
	} else {
		return "";
	}
}

//變更標籤(tag)內容
function replaceElement(elementId, content, tagName) {
	var element = document.getElementById(elementId);
	while (element.hasChildNodes()) {
		//如果div中已經有HTML內容
		element.removeChild(element.childNodes[0]);
	}
	label = document.createElement(tagName);
	text = document.createTextNode(content);
	label.appendChild(text);
	element.appendChild(label);
}

//將xml轉成http
function XMLtoHTTP(str) {
	//str = Trim(str);
	str = ReplaceAll(str, "&amp;", "&");
	str = ReplaceAll(str, "&lt;", "<");
	str = ReplaceAll(str, "&gt;", ">");
	str = ReplaceAll(str, "&apos;", "'");
	str = ReplaceAll(str, "&quot;", "\"");
	return str;
	function ReplaceAll(strOrg, strFind, strReplace) {
		var index = 0;
		while (strOrg.indexOf(strFind, index) != -1) {
			strOrg = strOrg.replace(strFind, strReplace);
			index = strOrg.indexOf(strFind, index);
		}
		return strOrg
	}
}

//提供flash tag的id，可以指定flash object
function getFlashMovieObject(flashName) {
	if (window.document[flashName]) {
		return window.document[flashName];
	}
	if (navigator.appName.indexOf("Microsoft Internet") == -1) {
		if (document.embeds && document.embeds[flashName])
		return document.embeds[flashName];
	} else {
		return document.getElementById(flashName);
	}
}

function SubChange(q) {
	if(document.advanceForm.media_type[0].checked) {
		document.location.replace("st?media_type=v&keyWord="+q+"&page=1&videoid=&search_btn_go.x=0&search_btn_go.y=0&video=&videoId=&CID=&SUBID=&RID=&RIDId=&LID=&DID=&DIDId=&MID=&VNDID=&VNDIDId=&SDATE=&ENDATE=");
	}
	else if(document.advanceForm.media_type[1].checked) {
		document.location.replace("sm?media_type=m&keyWord="+q+"&page=1&music=&musicId=&SINGER=&SINGERId=&TID=&SOWID=&SOWIDId=&LID=&CID=&CIDId=&SPOLID=&ALBUM=&ALBUMId=&SDATE=&ENDATE=&VNDID=&VNDIDId=");
	}
}
function rChange() {
	if(document.advanceForm.media_type[0].checked) {
		document.location.replace("index");
	}
	else if(document.advanceForm.media_type[1].checked) {
		document.location.replace("tygmusic");
	}
	else {
		document.location.replace("Error");
	}
}
var hide_div = false;
function sndMail() {

	if (hide_div) {
		document.getElementById("sndmail").style.display = "none";
		hide_div =false;
	} else {
		document.getElementById("sndmail").style.display = "block";
		hide_div =true;
	}
}


//=============== checkbox 全部選取 ===============
function selectAllCheckbox(){	
	//變數checkItem為checkbox的集合
	var checkItem = document.getElementsById("checkbox");
	for(var i=0;i<checkItem.length;i++){
		checkItem[i].checked=true;		
	}	
}

//=============== checkbox 全部取消 ===============
function unSelectAllCheck(){
	//變數checkItem為checkbox的集合
	var checkItem = document.getElementsById("checkbox");
	for(var i=0;i<checkItem.length;i++){
		checkItem[i].checked=false;
	}
}

//=========================================
//  字數計數器
//=========================================
function words_counter(id){
    //alert('#'+id+'_msg'+','+$('#'+id).val().length);
    //$('#'+id+'_msg').innerHTML = 'counter:'+$('#'+id).val().length;
    document.getElementById(id+'_msg').innerHTML = LANG.WORD_COUNTER_OL+':'+document.getElementById(id).value.length;
}
