﻿function gup( name )
			{
				try{
					name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
					var regexS = "[\\?&]"+name+"=([^&#]*)";
					var regex = new RegExp( regexS );
					var results = regex.exec( window.document.URL.toString() );
					//var results = regex.exec( window.location.href.toString() );
					if( results != null )					
						return results[1];
					else
					{
					window.location.reload(true);
					}
				}
				catch(e){	
					//setTimeout( "window.location.href = "+window.document.URL.toString(), 0 );				
					//window.location = window.location.href.toString();
					window.location.reload(true);
				}	  
			}
function loadMenu(pos1, pos2, type) {
	var link = 'http://rapphim.org/';
    var menu = '';
    menu += '<a name="menuType" href="' + link +'" class="" onmouseover="activeMenu(this); loadSubmenu(0' + ',' + pos2 + ',' + type + ');">Trang chủ</a>';
    menu += '<a name="menuType" target="_blank" href="' + link +'category/19/chieu-rap/" class="" onmouseover="activeMenu(this); loadSubmenu(2' + ',' + pos2 + ',' + type + ');">Phim Chiếu Rạp</a>';
    menu += '<a name="menuType" target="_blank" href="' + link +'lich-chieu-rap.php" class="" onmouseover="activeMenu(this); clearSubMenu();">Lịch Chiếu Rạp</a>';
    menu += '<a name="menuType" target="_blank" href="' + link +'category/1/hanh-dong-xhd/" class="" onmouseover="activeMenu(this); clearSubMenu();">Phim Hành Động </a>';
	menu += '<a name="menuType" target="_blank" href="' + link +'category/14/phim-bo-han-quoc/" class="" onmouseover="activeMenu(this); loadSubmenu(1' + ',' + pos2 + ',' + type + ');">Phim Hàn Quốc</a>';

	menu += '<a name="menuType" target="_blank" href="' + link +'category/13/phim-bo-dai-loan/" class="" onmouseover="activeMenu(this); clearSubMenu();">Phim Đài Loan</a>';

	
    document.getElementById('mainmenu').innerHTML = menu;
    var arrType = document.getElementsByName('menuType');
    arrType[pos1].className = 'curnav';
    loadSubmenu(pos1, pos2, type, link);
}
function loadSubmenu(pos1, pos2, type) {
	var link = 'http://rapphim.org';
    var menu = '';
    switch (pos1) {
        case 0:
            menu += '<a name="submenuType" class="" href="' + link + '/list/phim-binh-chon/">Phim nổi bật</a>';
            menu += '<a name="submenuType" class="" href="' + link + '/list/phim-moi/">Phim điện ảnh mới nhất</a>';
            menu += '<a name="submenuType" class="" href="' + link + '/list/phim-bo-moi/">Phim Bo mới nhất</a>';
            menu += '<a name="submenuType" class="" href="' + link + '/list/phim-xem-nhieu/">Phim xem nhiều nhất</a>';
			
            break;
        case 1:
            menu += '';

            break;

    }
    document.getElementById('submenu').className = 'submenu';
    document.getElementById('submenu').innerHTML = menu;
    if (type == pos1) {
        var arrType = document.getElementsByName('submenuType');
        arrType[pos2].className = 'curnav';
    }
}
function clearSubMenu() {
    document.getElementById('submenu').innerHTML = '';
}
function activeMenu(obj) {
    var arrType = document.getElementsByName('menuType');
    for (var i = 0; i < arrType.length; i++) {
        arrType[i].className = '';
    }
    obj.className = 'curnav';
}
function applyType(obj, value) {
    var arrType = document.getElementsByName('searchType');
    for (var i = 0; i < arrType.length; i++) {
        arrType[i].className = '';
    }
    obj.className = 'curnav';
    $('t').value = value;
}
//Open popup
function openWindow(filename, winname, width, height, feature) {
    var features, top, left;
    var reOpera = /opera/i;
    var winnameRequired = ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) || reOpera.test(navigator.userAgent));

    left = (window.screen.width - width) / 2;
    top = (window.screen.height - height) / 2;
    if (feature == '')
        features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",status=0,location=0";
    else
        features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "," + feature;
    //	if(!winnameRequired)	winname = "";
    newwindow = window.open(filename, winname, features);
    newwindow.focus();
}
function SubmitVote(type) {
var link = 'http://rapphim.org';
    if (type == 1) {
        answers = document.getElementsByName('surveyresponse');
        id = -1;
        for (var i = 0; i < answers.length; i++) {
            if (answers[i].checked) {
                id = answers[i].value;
                break;
            }
        }
        if (id == -1) {
            alert("Hãy chọn một trong các mục trước khi bình chọn.");
        }
        else {
            var x = readCookie('rapphimvote')
            if (x) {
                alert("Bạn chỉ được bình chọn 1 lần ^^");
            }
            else {
               createCookie("rapphimvote", "rapphim", 1);
                openWindow(""+ link +"/survey.php?t=1&id=" + id, "", 600, 300, "");
            }
        }
    }
    else
        openWindow(""+ link +"/survey.php?t=0", "", 600, 300, "");
    return false;
}
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
function logout(currenturl) {
	var url = "http://rapphim.org/";
    if (confirm('Bạn thực sự muốn thoát?')) {
        window.location.href = url+'?action=logout&url='+currenturl;
    } else {
        return;
    }
}
	
