﻿var popup_name = "firstwin";
var g_appname = "noappname";
var g_processing = 0;
var g_popup_parent = 0;
var dtsp_user_profile_window = null;

function dtsp_open_user_profile(parent_container, offsetx, offsety, w, h, callback) {
	if (dtsp_user_profile_window == null || !dtsp_user_profile_window.isVisible()) {
		var y = parent_container.offsetTop + offsety;
		var uri = "pages/userprofile.aspx?dtsp=true&onClose=" + callback + "&time=" + (new Date().getTime());
		dtsp_user_profile_window = new Popup(null, true, null, "userprofileframe");
		with (dtsp_user_profile_window.handle.style) {
			padding = "0px";
			margin = "0px";
			position = "absolute";
			right = "" + offsetx + "px";
			top = "" + y + "px";
			height = "" + h + "px";
			width = "" + w + "px";
		}
		dtsp_user_profile_window.setUrl(uri);
	}
	window.event.cancelBubble = true;
	return false;
}
function dtsp_close_user_profile() {
	if (dtsp_user_profile_window) {
		dtsp_user_profile_window.close();
	}
}

function Popup(url, discreet, scrolling, frameId) {
	this.handle = document.createElement("iframe");
	this.handle.style.visibility = "hidden";
	if ((discreet) && (discreet == true)) {
		this.handle.frameBorder = 0;
		this.handle.scrolling = "no";
		this.handle.vspace = "0px";
		this.handle.marginHeight = "0px";
		this.handle.marginWidth = "0px";
	}
	if ((scrolling) && (scrolling == true)) {
		this.handle.scrolling = "no";
	}
	if (frameId) {
		this.handle.id = frameId;
	}
	this.owner = document.body;
//	this.handle.src = "/fixedincome/apps/s/html/empty.html";
	this.owner.appendChild(this.handle);
	window.thelastpopup = this;
	this.minTop = 0;
	this.minLeft = 0;
	this.url = url;
	this.is_doing_move = false;
	this.is_doing_resize = false;
	this.handle.height = this.handle.scrollHeight;
}
function dump(msg, o) {
	for (p in o) {
		v = o[p];
		if (v != null)
			xbDEBUG.dump(msg + "." + p + "=" + v);
	}
}
Popup.prototype.setVisible = function(vis) {
	if (this.handle && this.handle.style) {
		if (vis) {
			this.handle.style.visibility = "visible";
			if (this.url) {
				this.handle.src = this.url;
				this.url = null;
			}
		}
		else
			this.handle.style.visibility = "hidden";
	}
}
Popup.prototype.isVisible = function() {
	return (this.handle && this.handle.style && this.handle.style.visibility == "visible") ? true : false;
}
Popup.prototype.toggle = function() {
	this.setVisible(!this.isVisible());
}
Popup.prototype.setUrl = function(url) {
	this.setVisible(true);
	this.handle.src = url;
}
Popup.prototype.setPosition = function(x, y, w, h) {
	this.handle.style.padding = "0px";
	this.handle.style.margin = "0px";
	this.handle.style.position = "absolute";
	this.handle.style.left = "" + x + "px";
	this.handle.style.top = "" + y + "px";
	this.handle.style.height = "" + h + "px";
	this.handle.style.width = "" + w + "px";
}
Popup.prototype.resizeBy = function(dw, dh) {
	this.handle.style.pixelWidth += dw;
	this.handle.style.pixelHeight += dh;
	if (this.minWidth && this.handle.style.pixelWidth < this.minWidth)
		this.handle.style.pixelWidth = this.minWidth;
	if (this.minHeight && this.handle.style.pixelHeight < this.minHeight)
		this.handle.style.pixelHeight = this.minHeight;
	if (window.xbDEBUG) xbDEBUG.dump("resizeBy xy(" + this.handle.style.pixelLeft
+ "," + this.handle.style.pixelTop
+ ") wh(" + this.handle.style.pixelWidth + ","
+ this.handle.style.pixelHeight + ")");
}
Popup.prototype.resizeToFit = function() {
}
Popup.prototype.moveBy = function(dx, dy) {
	this.handle.style.pixelLeft += dx;
	this.handle.style.pixelTop += dy;
	if (this.handle.style.pixelLeft < this.minLeft)
		this.handle.style.pixelLeft = this.minLeft;
	if (this.handle.style.pixelTop < this.minTop)
		this.handle.style.pixelTop = this.minTop;
	if (window.xbDEBUG) xbDEBUG.dump("moveBy xy(" + this.handle.style.pixelLeft
+ "," + this.handle.style.pixelTop
+ ") wh(" + this.handle.style.pixelWidth + ","
+ this.handle.style.pixelHeight + ")");
}
Popup.prototype.toString = function() {
	return "Popup[" + this.handle + "]";
}
Popup.prototype.close = function() {
	if (this.handle != null) {
		this.setVisible(false);
		this.owner.removeChild(this.handle);
		this.handle = null;
	}
}
Popup.prototype.getWidth = function() {
	return this.handle.style.pixelWidth;
}
Popup.prototype.getHeight = function() {
	return this.handle.style.pixelHeight;
}




function MailTo(subject, body) {

    //If Language is 1 then and only then give the Title
    var matchNonAscii = new RegExp("^[\u0000-\u0080]+$"); 
    var URL = "mailto:?";

    if (subject != '') {
        if (matchNonAscii.test(subject)) {

            URL += "&subject=" + subject;
        }
        else {

            URL += "&subject=NOMURA%20Global%20Research%20Portal";
        }
    }
    if (body != '')
        URL += "&body=" + body;

    
    window.open(URL, '_blank', 'toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=600');
}
function CategoryChange(drpCategoryChange,languageId)
{   
    var index = drpCategoryChange.selectedIndex;
    var val = drpCategoryChange.options[drpCategoryChange.selectedIndex].value;
    var txt = drpCategoryChange.options[drpCategoryChange.selectedIndex].text;
    drpCategoryChange.options[drpCategoryChange.selectedIndex].text;
     jQuery.ajax({
                type:"POST",
                contentType: "application/json; charset=utf-8"
                ,url: basePath + '/WebServices/SectorIndustry.asmx/SectorIndustryList'
                ,data:"{categoryType:'" + val + "',languageId:'" + languageId +"'}"
                ,success: function(strContent) 
                {
                    ListIndustrySector(strContent);
                }
                ,error: function(xmlHttpRequest, status, err) 
                {                
                    alert(xmlHttpRequest.responseText);
                    alert('Sorry! Error happened.');
                }
            }
            );

}

function ListIndustrySector(content)
{
    window.document.getElementById("tblSectorIndustryList").parentNode.innerHTML = $.parseJSON(content).d;
}

function openLink()
{
    var languageId = window.document.getElementById(hdnLanguageId).value;
    var url = basePath + "/resource/files";

    var windowSpecification = "height=650,width=800,status=yes,left=400,top=150,toolbar=no,menubar=no,location=no"
    var windowName = 'Earning_Announce_schedule';
    var win;

    if (languageId == 2)
    {
        url += "/kessan.xls";
        win = window.open(url, windowName);
    }
    else
    {
        url += "/Asia_Previews.pdf";
        win = window.open(url, windowName, windowSpecification);
        win.focus();
    }
}

function getCategoryFromDropDown(dropDownId)
{
    if (document.getElementById(dropDownId) != null)
    {
        var catId = document.getElementById(dropDownId).value;
        if (catId != '0')
            return catId;
        else
            return '';
    }
    return '';
}
function showPopup()
{
    var windowsizex = f_clientWidth() - 340 + f_scrollLeft();
    var windowsizey = 100 - f_scrollTop();
    var frame = document.getElementById('frameUserProfile');
    frame.src = basePath + '/Pages/UserProfile.aspx?a=' + Math.random();
    frame.style.display = '';
    frame.style.top = windowsizey;
    frame.style.left = windowsizex;
    return (false);
}

function closePopup()
{
    var frame = document.getElementById('frameUserProfile');
    frame.src = basePath + '/Pages/UserProfile.aspx';
    frame.style.display = 'none';
}

function f_clientWidth()
{
    return f_filterResults(window.innerWidth ? window.innerWidth : 0, document.documentElement ? document.documentElement.clientWidth : 0, document.body ? document.body.clientWidth : 0);
}

function f_scrollLeft()
{
    return f_filterResults(window.pageXOffset ? window.pageXOffset : 0, document.documentElement ? document.documentElement.scrollLeft : 0, document.body ? document.body.scrollLeft : 0);
}

function f_scrollTop()
{
    return f_filterResults(window.pageYOffset ? window.pageYOffset : 0, document.documentElement ? document.documentElement.scrollTop : 0, document.body ? document.body.scrollTop : 0);
}

function f_filterResults(n_win, n_docel, n_body)
{
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
    {
        n_result = n_docel;
    }
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

var refreshWindow = false;
function ConfirmLogout()
{
    refreshWindow = window.showModalDialog(basePath + '/Logout.aspx?rand=' + Math.random(),null,'status: No; center: Yes; resizable: No; help: no; dialogHeight: 100px; dialogWidth: 300px;scroll: no;');

    if (refreshWindow)
    {
        window.location.href = basePath + "/Login.aspx";
    }
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    return false;
}

function Set_Cookie(name, value, expires, path, domain, secure)
{
    var today = new Date();
    today.setTime(today.getTime());

    if (expires)
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }

    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
            ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
            ((path) ? ";path=" + path : "") +
            ((domain) ? ";domain=" + domain : "") +
            ((secure) ? ";secure" : "");
}

function ShowNuggetParameters(pageId, languageId, nuggetControlId)
{
    window.open(basePath + "/ShowDebugInformation.aspx?pageId=" + pageId + "&languageId=" + languageId + "&nuggetControlId=" + nuggetControlId);
}