
	
	function linkMenu(menu,link){
		setCookie(menuCookie,menu);
		document.getElementById('mainmenuHeader').className = menu;
		window.location = link;
	}
	
	
	// =========================================================================
	//                          Cookie functions 
	// =========================================================================
	/* This function is used to set cookies */
	var menuCookie = "menusToSelected";
	function setCookie(name,value,expires,path,domain,secure) {
		
		return;
		// Fix path = "/" to keep Cookie accessiable for all Path in domain 
		// To fix menu unexpand across ROD Bug
		path = "/";
	  	var cookieValue = name + "=" + escape (value) +
	    ((expires) ? "; expires=" + expires.toGMTString() : "") +
	    ((path) ? "; path=" + path : "") +
	    ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	
	    document.cookie = cookieValue;      
	}
	
	/* This function is used to get cookies */
	function getCookie(name) {
		return;
		var prefix = name + "=" 
		var start = document.cookie.indexOf(prefix) 
	
		if (start==-1) {
			return null;
		}
		
		var end = document.cookie.indexOf(";", start+prefix.length) 
		if (end==-1) {
			end=document.cookie.length;
		}
	
		var value=document.cookie.substring(start+prefix.length, end); 
		return unescape(value);
	}
	
	/* This function is used to delete cookies */
	function deleteCookie(name,path,domain) {
		return;
	  if (getCookie(name)) {
	    document.cookie = name + "=" +
	      ((path) ? "; path=" + path : "") +
	      ((domain) ? "; domain=" + domain : "") +
	      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	  }
	}
	
	function setScrollBottom(status){
		isScrollBottom = status;
	}
	
	function Inint_AJAX() {
	  try{
	    if (window.XMLHttpRequest) {
	        return new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        isIE = true;
	        return new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }catch(e){
	  	alert("Exception in initRequest(): "+e);
	  }
	}
	
	function tabBarOnClick(id){
		clearInterval(objTabsNews);
		changeTabNewEveytingMinute(id);
	}
	
	function tabBarInterval(id){
		changeTabNewEveytingMinute(id);
	}
	
	function changeTabNewEveytingMinute(id){
		var tabAll = new Array('id_tab_blue','id_tab_violet','id_tab_green','id_tab_red','id_tab_yellow');
		for(var i=0;i<tabAll.length;i++){
			
			if( tabAll[i] == id ){
				hidden(tabAll[i],false);
			}else{
				hidden(tabAll[i],true);
			}
		}
	}
	
	function hidden(elemantName,status){
		try{
			if( status ){
				document.getElementById(elemantName).style.display = 'none';
			}else{
				document.getElementById(elemantName).style.display = '';
			}
		}catch(e){
			
		}
	}
	
	function replaceAll( str, from, to ) {
	    var idx = str.indexOf( from );
	    while ( idx > -1 ) {
	        str = str.replace( from, to ); 
	        idx = str.indexOf( from );
	    }
	    return str;
	}
	
	function ajax_req(url,objRes,async){
	    var req=Inint_AJAX();
		  req.onreadystatechange = function () {
		    if (req.readyState==4) {
		      if (req.status==200) {
		      	var obj = document.getElementById(objRes);
		        //alert(req.responseText);
		        obj.innerHTML = req.responseText //แสดงเนื้อหาของส่วนนั้นๆ
		      }
		    }
		  };
		  async = async == null || async == '' ? true : async; 
		  req.open("GET", url, async);
		  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // set Header
		  req.send(null); //ส่งค่า
	}
	
	function changeTabsAllNewsFn(){
		var tabAll = new Array('id_tab_blue','id_tab_violet','id_tab_green','id_tab_red','id_tab_yellow');
		
		tabBarInterval(tabAll[currenttabsNews++]);
		
		if( currenttabsNews == 5 ){
			currenttabsNews = 0;
		}
		
	}

	function queryChatRoom(){
		
		//if( document.getElementById('name') == null ||  document.getElementById('name').value == '' ){
		//	return;
		//}
		
		if(isChatRefresh){
			isChatRefresh = false;
			
			var url = '../inc/chat/ChatRoomDetail.php';
		    
		    var req=Inint_AJAX();
			  req.onreadystatechange = function () {
			    if (req.readyState==4) {
			      if (req.status==200) {
			        var obj = document.getElementById('id_chat_room_detail');
			        //obj.style.backgroundImage = "url()" //ลบรูปรอโหลด
			        //obj.style.height = '200px;' //ปรับความสูงของพื้นที่ให้พอดีกับข้อความ
			        //alert(req.responseText);
			        obj.innerHTML = req.responseText //แสดงเนื้อหาของส่วนนั้นๆ
			        if( isScrollBottom ){
						obj.scrollTop = obj.scrollHeight;
						obj.scrollTop = obj.scrollHeight;
					}
					isChatRefresh = true;
			      }
			    }
			  };
			  req.open("GET", url, true);
			  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // set Header
			  req.send(null); //ส่งค่า
		}
	}
	
	function queryMarquee(){
		
		var url = "http://www.imusichit.com/inc/chat/Marqueen.php";
		
		if( (window.location+'').indexOf('localhost') != -1 ){
			url = "http://localhost/inc/chat/Marqueen.php";
		}
		
		
		var req=Inint_AJAX();
		  req.onreadystatechange = function () {
			if (req.readyState==4) {
			  if (req.status==200) {
				    //alert(req.responseText);
					document.getElementById('id_Marqueen').innerHTML = req.responseText;
			  }
			}
		  };
		  req.open("GET", url, true);
		  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // set Header
		  req.send(null); //ส่งค่า

	}

	
	function sendMessageChatRoom(){
		try{
		var message = document.forms[0].elements['mes'].value;
		var name = document.forms[0].elements['name'].value;
		var dateTime = document.getElementById('template-date-time').innerHTML;
		name = trim(name) == '' ? 'Guest' : name;
		
		if( name == 'adminpassword' ){
			name = 'admin';
		}else if( name == 'webmasterpassword' ){
			name = 'webmaster';
		}else if( (name.toUpperCase()).indexOf('ADMIN') != -1 || (name.toUpperCase()).indexOf('WEBMASTER') != -1 ){
			alert('ชื่อนี้ ใช้ได้เฉพาะ \nAdmin และ Webmaster เท่านั้น\nบุคคลทั่วไปไม่สามารถใช้ได้');
			return ;
		}
		
		
		if( trim(message) == '' ){
			alert('! กรุณาใส่ข้อความ ');
			return;
		} 
		
		//alert(name);
		var url = '../inc/chat/ChatSendMessage.php?msg='+encodeURI(message)+'&name='+encodeURI(name)+'&date='+dateTime;
		
	    var req=Inint_AJAX();
		  req.onreadystatechange = function () {
		    if (req.readyState==4) {
		      if (req.status==200) {
		      	var obj = document.getElementById('id_chat_room_detail');
		        //var obj = document.getElementById('id_chat_room_detail');
		        obj.style.backgroundImage = "url()" //ลบรูปรอโหลด
		        //obj.style.height = '100%' //ปรับความสูงของพื้นที่ให้พอดีกับข้อความ
		        //obj.innerHTML = req.responseText //แสดงเนื้อหาของส่วนนั้นๆ
		        //alert('send success');
		        //obj.style.height = '200px;' //ปรับความสูงของพื้นที่ให้พอดีกับข้อความ
		        obj.innerHTML = req.responseText //แสดงเนื้อหาของส่วนนั้นๆ
		        if( isScrollBottom ){
					obj.scrollTop = obj.scrollHeight;
				}
		        //alert(req.responseText);
		        document.forms[0].elements['mes'].value = '';//getElementByName('mes').value = '';
		        //alert(document.forms[0].elements['mes'].value);
		        //queryChatRoom();
		        document.forms[0].elements['mes'].focus();//document.getElementByName('mes').focus();
		        
		      }
		    }
		  };
		  req.open("GET", url, true);
		  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // set Header
		  req.send(null); //ส่งค่า
		  
		  document.forms[0].elements['mes'].value = '';
		}catch (e){
			
		}
	}
	
	function sendMessageMarqueen(){
		//alert('4'+document.getElementById('mesMaq').value);
		//try{
			var message = document.getElementById('id-mesMaq').value;
			var name = document.getElementById('id-nameMaq').value;
			var dateTime = document.getElementById('template-date-time').innerHTML;
			name = trim(name) == '' ? 'Guest' : name;
			
			if( name == 'adminpassword' ){
				name = 'admin';
			}else if( name == 'webmasterpassword' ){
				name = 'webmaster';
			}else if( (name.toUpperCase()).indexOf('ADMIN') != -1 || (name.toUpperCase()).indexOf('WEBMASTER') != -1 ){
				alert('ชื่อนี้ ใช้ได้เฉพาะ \nAdmin และ Webmaster เท่านั้น\nบุคคลทั่วไปไม่สามารถใช้ได้');
				return ;
			}
			
			if( trim(message) == '' ){
				alert('! กรุณาใส่ข้อความ ');
				return;
			} 
			
			//alert(name);
			var url = '/inc/chat/ChatSendMessage.php?msg='+encodeURI(message)+'&name='+encodeURI(name)+'&date='+dateTime;
			if( (window.location+'').indexOf('localhost')  != -1 ){
				url = 'http://localhost'+url;
				//alert(  window.location );
			}else{
				url = 'http://www.imusichit.com'+url;
				//alert(  window.location );
			}
			
			var req=Inint_AJAX();
			  req.onreadystatechange = function () {
				if (req.readyState==4) {
				  if (req.status==200) {
					  	
					var obj = document.getElementById('id_chat_room_detail');
					//var obj = document.getElementById('id_chat_room_detail');
					//obj.style.backgroundImage = "url()" //ลบรูปรอโหลด
					//obj.style.height = '100%' //ปรับความสูงของพื้นที่ให้พอดีกับข้อความ
					//obj.innerHTML = req.responseText //แสดงเนื้อหาของส่วนนั้นๆ
					//alert('send success'+req.responseText);
					//obj.style.height = '200px;' //ปรับความสูงของพื้นที่ให้พอดีกับข้อความ
					if( obj != null ){
						obj.innerHTML = req.responseText //แสดงเนื้อหาของส่วนนั้นๆ
						if( isScrollBottom ){
							obj.scrollTop = obj.scrollHeight;
						}
					}
					//alert(req.responseText);
					document.getElementById('id-mesMaq').value = '';//getElementByName('mes').value = '';
					//alert(document.forms[0].elements['mes'].value);
					//queryChatRoom();
					document.getElementById('id-mesMaq').focus();//document.getElementByName('mes').focus();
					
				  }
				}
			  };
			  req.open("GET", url, true);
			  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // set Header
			  req.send(null); //ส่งค่า
		
			  document.getElementById('id-mesMaq').value = '';
		//}catch (e){
			
		//}
	}
	
	function next_preview_mv_music_onclick(eventOnclick){
		var cookMenu = getCookie('menuid3');
		
		//--- music
		if( cookMenu == 'id_tab_music'){
			//--- set Tab station music
			gotoTabStation('id_tab_music');
			
			if( eventOnclick == 'prev' ){//--- prev
				show_id_obj_music--;
				loop_obj_music();
				//alert(show_id_obj_music);
				change_show_id_obj_music();
				//tmp_tooltip_show_onmouse_over = tooltip_show_onmouse_over-1;
				//set_mv_music_onmouse_over(eventOnclick);
			}else{ //--- next
				show_id_obj_music++;
				loop_obj_music();
				//alert(show_id_obj_music);
				change_show_id_obj_music();
				//tmp_tooltip_show_onmouse_over = tooltip_show_onmouse_over+1;
				//set_mv_music_onmouse_over(eventOnclick);
			}
			
		//--- radio  id_tab_radio
		}else{
			//--- set Tab station radio
			gotoTabStation('id_tab_radio');
			
			if( eventOnclick == 'prev' ){//--- prev
				show_id_obj_radio--;
				loop_obj_radio();
				change_show_id_obj_radio();
				
			}else{ //--- next
				show_id_obj_radio++;
				loop_obj_radio();
				change_show_id_obj_radio();
			}
		}
	}

	function change_show_id_obj_music(urlext){
		document.getElementById('id_radio_font').style.backgroundColor = "#000";
		document.getElementById('id_topic_h1').style.display = '';
		document.getElementById('id_button_fm').innerHTML = '';
		document.getElementById('id_gradient_station').style.display = "none";
		//document.getElementById('id_border_station').style.height = "280px";
		//document.getElementById('id_radio_back').style.height = "200px";
		//document.getElementById('id_radio_font').style.height = "200px";
		//ajax_req('../inc/music/MusicStation.php?urlext='+urlext,'id_music_station',true);
		
		document.getElementById('id_border_station').style.height = "250px";
		document.getElementById('id_radio_back').style.height = "180px";
		document.getElementById('id_radio_font').style.height = "180px";
		document.getElementById('id_music_station').innerHTML = '<div style="width:100%;height:100%;float:left;margin-left:-25px;" align="center"><a target="_blank" href="'+urlext+'" style="color: red;"><img width="246" height="150" src="http://i2.ytimg.com/vi/'+urlext+'/default.jpg"/><br>ดู MV Music Video จาก Youtube คลิ๊ก !!</a></div>';
	}
	
	function change_show_id_obj_radio(){
		document.getElementById('id_radio_font').style.backgroundColor = "#FFF";
		document.getElementById('id_topic_h1').style.display = 'none';
		document.getElementById('id_gradient_station').style.display = "";
		document.getElementById('id_border_station').style.height = "390px";
		
		document.getElementById('id_radio_back').style.height = "170px";
		document.getElementById('id_radio_font').style.height = "170px";
		//alert('1');
		ajax_req('../inc/radio/radio_station.php?radio='+show_id_obj_radio,'id_music_station',true);
		//ajax_req('../inc/radio/forward_radio.php?radio='+show_id_obj_radio,'id_music_station',true);
		googleAdsense(null);
	}
	
	function loop_obj_music(){
		if( show_id_obj_music > 1 ){
			show_id_obj_music = 1;
		}else if( show_id_obj_music < 1 ){
			show_id_obj_music = 1;
		}	
	}
	
	function loop_obj_radio(){
		if( show_id_obj_radio > totalradio ){
			show_id_obj_radio = 1;
		}else if( show_id_obj_radio < 1 ){
			show_id_obj_radio = totalradio;
		}	
	}

	
	function set_mv_music_onmouse_over(calculate){
		
		tmp_tooltip_show_onmouse_over = show_id_obj_music;
		
		if( calculate == 'prev' ){
			tmp_tooltip_show_onmouse_over--;
		}else{ //--- next
			tmp_tooltip_show_onmouse_over++;
		}
		
		//alert(tmp_tooltip_show_onmouse_over);
		if( tmp_tooltip_show_onmouse_over > 3 ){
			tmp_tooltip_show_onmouse_over = 1;
		}else if( tmp_tooltip_show_onmouse_over < 1 ){
			tmp_tooltip_show_onmouse_over = 3;
		}
		//alert(tmp_tooltip_show_onmouse_over);
		
		if( tmp_tooltip_show_onmouse_over == 1 ){
			document.getElementById('id_tooltip_mv_music').style.backgroundPosition = "0px -214px";
		}else if( tmp_tooltip_show_onmouse_over == 2 ){
			document.getElementById('id_tooltip_mv_music').style.backgroundPosition = "0px -107px";
		}else if( tmp_tooltip_show_onmouse_over == 3 ){
			document.getElementById('id_tooltip_mv_music').style.backgroundPosition = "0px 0px";
		}
		
		tooltip_show_onmouse_over = tmp_tooltip_show_onmouse_over;
		
		hidden('id_tooltip_mv_music',false);
		hidden('id_tooltip_mv_music2',false);
	}
	
	function set_mv_music_onmouse_out(calculate){
		hidden('id_tooltip_mv_music',true);
		hidden('id_tooltip_mv_music2',true);
	}

	function reqClip(urlClip){
		//alert(urlClip);
		ajax_req('../inc/clip/clip.php?url='+urlClip,'id_clip_vdo');
	}
	
	function gotopage(page){
		
		ajax_req('../inc/clip/Searchclip.php?page='+page,'id_title_clip');
	}
	
	/*function newsmarguee(){
		ajax_req('../inc/news/IncNewsMarguee.php','id_newsmarguee');
	}*/
	
	function gotoTab(id){
		if( id == 'id_month_first'){
			document.getElementById('id_month_first').style.backgroundPosition = "0px -37px";
			document.getElementById('id_month_second').style.backgroundPosition = "0px 0px";
			hidden('id_month_first_list',false);
			hidden('id_month_second_list',true);
		}else{ //--- id_month_second
			document.getElementById('id_month_first').style.backgroundPosition = "0px 0px";
			document.getElementById('id_month_second').style.backgroundPosition = "0px -37px";
			hidden('id_month_first_list',true);
			hidden('id_month_second_list',false);
		}
	}
	
	function gotoTabStation(id){
		if( id == 'id_tab_radio'){
			document.getElementById('id_tab_radio').style.backgroundPosition = "0px -44px";
			document.getElementById('id_tab_music').style.backgroundPosition = "0px 0px";
			document.getElementById('id_control_radio_station').style.display = "";
		}else{ //--- id_tab_music
			document.getElementById('id_tab_radio').style.backgroundPosition = "0px 0px";
			document.getElementById('id_tab_music').style.backgroundPosition = "0px -44px";
			document.getElementById('id_control_radio_station').style.display = "none";
		}
	}
	
	function nextprev(obj,position){
		//alert(id+'  '+position);
		obj.style.backgroundPosition  = position;
	}
	
	function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
	}
	 
	function ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	 
	function rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	var totalfmradio = 22;
	var openfm = 1;
	function re_loop_radio(){
		if( openfm > totalfmradio ){
			openfm = 1;
		}else if( openfm < 1 ){
			openfm = totalfmradio;
		}	
	}
	
	function changFontSize(size,height){
		document.getElementById('id_desc_song').style.fontSize = size+'px';
		document.getElementById('id_desc_song').style.lineHeight = height+'px';
	}
	
	function textCounter( field, countfield, maxlimit ) {
	  if ( field.value.length > maxlimit )
	  {
	    field.value = field.value.substring( 0, maxlimit );
	    alert( 'Textarea value can only be '+maxlimit+' characters in length.' );
	    return false;
	  }
	  else
	  {
	    countfield.value = maxlimit - field.value.length;
	  }
	}
	
	function validatemail(obj,msg){
		if( trim(obj.value) == '' ){
			alert(msg+' is require.');
			obj.focus();
			return false;	
		} 
		return true;
		
	}
