var isOpera = Boolean(navigator.userAgent.match("Opera"));

function openBlogWindow(obj) {
	var $d = new Date();
	var $m = (($d.getMonth() + 1) < 10) ? ('0' + ($d.getMonth() + 1)) : ($d.getMonth() + 1);
	var $h = '' + $d.getFullYear() + $m + $d.getDate() + $d.getHours() + $d.getMinutes();
    var url = "http://www.coqule.com/blog/index.html?" + $h;
    
    /*if(isOpera) {
        var $h = 431;
        var $l = obj.x + Math.floor((obj.sw - 1024) / 2) + 15;
        var $t = obj.y + 150;
        var $w = window.open(url, 'external', 'width=550,height='+$h+',scrollbars=auto,left='+$l+',top='+$t);
        $w.focus();
        return;
    }*/

    var div = document.getElementById("external");
    div.orgLeft = obj.x //+ Math.floor((obj.sw - 1024) / 2) + 15;
    div.orgTop = obj.y //+ 135;
    div.orgWinWidth = getWindowWidth();
    div.orgWinHeight = getWindowHeight();
    div.style.visibility = "visible";
    div.style.left = div.orgLeft + 'px';
    div.style.top = div.orgTop + 'px';
    div.style.left = div.orgLeft + 'px';
    div.style.top = div.orgTop + 'px';
    
    var ifm = div.getElementsByTagName("iframe")[0];
    ifm.src = url;
    ifm.style.width = "930px";
    ifm.style.height = "431px";
    ifm.focus();
}

function openNewsWindow(obj) {
	var $d = new Date();
	var $m = (($d.getMonth() + 1) < 10) ? ('0' + ($d.getMonth() + 1)) : ($d.getMonth() + 1);
	var $h = '' + $d.getFullYear() + $m + $d.getDate() + $d.getHours() + $d.getMinutes();
    var url = "http://www.coqule.com/news/index.html?" + $h;
   
    var div = document.getElementById("external");
    div.orgLeft = obj.x //+ Math.floor((obj.sw - 1024) / 2) + 15;
    div.orgTop = obj.y //+ 135;
    div.orgWinWidth = getWindowWidth();
    div.orgWinHeight = getWindowHeight();
    div.style.visibility = "visible";
    div.style.left = div.orgLeft + 'px';
    div.style.top = div.orgTop + 'px';
    div.style.left = div.orgLeft + 'px';
    div.style.top = div.orgTop + 'px';
    
    var ifm = div.getElementsByTagName("iframe")[0];
    ifm.src = url;
    ifm.style.width = "930px";
    ifm.style.height = "431px";
    ifm.focus();
}

function openRecruitWindow(obj) {
	var $d = new Date();
	var $m = (($d.getMonth() + 1) < 10) ? ('0' + ($d.getMonth() + 1)) : ($d.getMonth() + 1);
	var $h = '' + $d.getFullYear() + $m + $d.getDate() + $d.getHours() + $d.getMinutes();
    var url = "http://www.coqule.com/recruit/index.html?" + $h;
   
    var div = document.getElementById("external");
    div.orgLeft = obj.x //+ Math.floor((obj.sw - 1024) / 2) + 15;
    div.orgTop = obj.y //+ 135;
    div.orgWinWidth = getWindowWidth();
    div.orgWinHeight = getWindowHeight();
    div.style.visibility = "visible";
    div.style.left = div.orgLeft + 'px';
    div.style.top = div.orgTop + 'px';
    div.style.left = div.orgLeft + 'px';
    div.style.top = div.orgTop + 'px';
    
    var ifm = div.getElementsByTagName("iframe")[0];
    ifm.src = url;
    ifm.style.width = "930px";
    ifm.style.height = "431px";
    ifm.focus();
}


function closeExternalWindow() {
    var div = document.getElementById("external");
    var ifm = div.getElementsByTagName("iframe")[0];
    div.style.visibility = "hidden";
    ifm.style.width = "0";
    ifm.style.height = "0";	
    ifm.src = "swf/blank.html";
}

function fixFramePosition() {
    var div = document.getElementById("external");
    var ifm = div.getElementsByTagName("iframe")[0];

    var offset_x = getWindowWidth() - div.orgWinWidth;
    var offset_y = getWindowHeight() - div.orgWinHeight;

    var div_left = div.orgLeft + Math.floor(offset_x/2);
    var ifm_height = ifm.orgHeight + offset_y;
    
    if(!div_left) { div_left = 0; }
    if(!ifm_height) { ifm_height = 0; }
    
    div.style.left = div_left + "px";
    ifm.style.height = ifm_height + "px";
}

function getWindowWidth() {
    var w = window.innerWidth  || document.documentElement.clientWidth  || document.body.clientWidth;
    return w;
}
function getWindowHeight() {
    var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
    return h;
}



