﻿function searchSong(){
    var objSong=document.getElementById("txtSongName");
    if (objSong.value==""){
        alert("กรุณาระบุชื่อเพลง");
        objSong.focus();
    }
    else{
        window.open("/searchsong.php?q="+escape(utf8_encode(objSong.value)));
    }
}
function utf8_encode(string){
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";
    for (var n = 0; n < string.length; n++){
        var c = string.charCodeAt(n);
        if(c < 128)utftext += String.fromCharCode(c);
        else if((c > 127) && (c < 2048)){
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else{
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }
    }
    return utftext;
}
function GetViewport(){
	this.windowX=(document.documentElement && document.documentElement.clientWidth)||
	window.innerWidth||self.innerWidth||document.body.clientWidth;
	this.scrollY = (document.documentElement && document.documentElement.scrollTop) ||
	window.pageYOffset || self.pageYOffset || document.body.scrollTop;
}
function addLoadEvent(func){
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    }
    else{
        window.onload = function(){
            if (oldonload)
                oldonload();
            func();
        }
    }
}
function addScrollEvent(func){
    var oldonload = window.onscroll;
    if (typeof window.onscroll != 'function'){
        window.onscroll = func;
    }
    else{
        window.onscroll = function(){
            if (oldonload)
                oldonload();
            func();
        }
    }
}
function addResizeEvent(func){
    var oldonload = window.onresize;
    if (typeof window.onresize != 'function'){
        window.onresize = func;
    }
    else{
        window.onresize = function(){
            if (oldonload)
                oldonload();
            func();
        }
    }
}