﻿/// <reference path="~/Scripts/jquery-1.4.2.js"/>
/// <reference name="MicrosoftAjax.js"/>
/// <reference path="~/Scripts/MicrosoftAjax.debug.js"/>
/// <reference path="~/Scripts/MicrosoftMvcAjax.debug.js"/>
/// <reference path="~/Scripts/MicrosoftMvcJQueryValidation.js"/>
/// <reference path="~/Scripts/jquery.helper.js"/>
/// <reference path="~/Scripts/jquery.history.js"/>
/// <reference path="~/Scripts/jquery.selectbox.js"/>
/// <reference path="~/scripts/jquery.scrollTo.js"/>
/// <reference path="~/Scripts/scrolling.js"/>
/// <reference path="~/Scripts/bfdc.js"/>
/// <reference path="~/Scripts/jquery.js"/>


function OpenCenteredWindow(windowname, href, width, height, scroll, resize) {
    /// <summary>Opens Centered Windows.</summary>
    /// <param name="windowname" type="String">The name of the window.</param>
    /// <param name="href" type="String">Url to Loads</param>
    /// <param name="width" type="String">Width of window</param>
    /// <param name="height" type="String">Height of window</param>
    /// <param name="scroll" type="String">enable scroll bar</param>
    /// <param name="resize" type="String">Allow the window to be resized.</param>

	var _top = 300;
	var _left = 300;

	try {
		_top = (screen.height / 2) - (height / 2) - 25
		_left = (screen.width / 2) - (width / 2)
	} catch (e) { }

	openWindow(windowname, href, "", _top, _left, width, height, scroll, resize);
	eval(windowname + '.window.select();');
	eval(windowname + '.select();');
	eval(windowname + '.focus();');
}

function openWindow(windowname, href, windowtitle, top, left, width, height, scroll, resize) {
	eval(windowname + ' = window.open(href,windowname,"top="+top+",left="+left+",width="+width+",height="+height+",toolbar=0,directories=0,status=0,scrollbars="+scroll+",resize="+resize+",menubar=0");')
	eval(" try { " + windowname + '.creator = self; } catch(e) { }');
	eval(" try { " + windowname + '.document.title = "' + windowtitle + '"; } catch(e) { }');
	eval(windowname + '.window.focus();');
}

var _global_CancelClick = false;
function OpenUrl(url) {
    /// <summary>Will stop the browser attempting to load a url more than once. you can click a link many times but will only load it once.</summary>
	if (_global_CancelClick) return;
	document.location.href = url;
}

function disprops2_noAleart(object, split) {
	var HTMLstr = "";
	var x;
	  
	try {
		if (object.toString().startsWith("function")) {
			HTMLstr += 'Raw: \'{function}\'' + split + '---------------' + split;
		} else {
			HTMLstr += 'Raw: \'' + object + '\'' + split + '---------------' + split;
		}
	} catch (e) {
		HTMLstr += 'Raw: \'' + object + '\'' + split + '---------------' + split;
	}


	for (x in object) {
		HTMLstr += x;

		try {
			var i = eval("object." + x);

			if (i.toString().startsWith("function")) {
			    HTMLstr += " = {function} ";
			} else {
				HTMLstr += " = " + i.toString();
			}

		} catch (e) {
			try {
				var j = eval("object." + x);

				if (!isGlobalDefined(j)) {
					HTMLstr += " = {undefined} ";
				} else {
					HTMLstr += " = " + j;
				}

			} catch (e1) {
				HTMLstr += " = {nothing}";
			}
		}

		HTMLstr += split;
	}
	return HTMLstr
}


function disprops2(object) {
	alert(disprops2_noAleart(object, "\n"));
}

function disprops(object) {
	var HTMLstr = '', x
	for (x in object) HTMLstr += x + "\n"
	alert(HTMLstr)
	return HTMLstr
}
function displayprops(object) {
    DisplayProps(object);
}

function DisplayProps(object) {
	if (Sys.Browser.name.indexOf("Opera") != -1) return disprops2(object);

	var WindowWidth = 300;
	var WindowHeight = 600;
	var WindowTop = 30;
	var WindowLeft = 30;

	//try { WindowHeight = window.document.clientHeight; } catch (e) { }
	try { WindowTop = window.screenTop; } catch (e) { }
	try { WindowLeft = window.screenLeft - WindowWidth; } catch (e) { }


	if (!isGlobalDefined("DisplayPropsWindow")) {
		openWindow("DisplayPropsWindow", "about:blank", "Display Properties", WindowTop, WindowLeft, WindowWidth, WindowHeight, 1, 1);
	} else {
		if (DisplayPropsWindow.closed) {
			openWindow("DisplayPropsWindow", "about:blank", "Display Properties", WindowTop, WindowLeft, WindowWidth, WindowHeight, 1, 1);
		}
	}

	try {
		DisplayPropsWindow.document.body.innerHTML = disprops2_noAleart(object, "<br />");
		DisplayPropsWindow.moveTo(WindowLeft, WindowTop);
		DisplayPropsWindow.document.body.style.backgroundColor = "#EEEEEE";
		DisplayPropsWindow.document.body.style.fontFamily = "Arial";
		DisplayPropsWindow.document.body.style.fontSize = "12px";

	} catch (e) {
		try {
			DisplayPropsWindow.close();
			openWindow("DisplayPropsWindow", "about:blank", "Display Properties", WindowTop, WindowLeft, WindowWidth, WindowHeight, 1, 1);

			DisplayPropsWindow.document.body.innerHTML = disprops2_noAleart(object, "<br />");

			DisplayPropsWindow.document.body.style.backgroundColor = "#EEEEEE";
			DisplayPropsWindow.document.body.style.fontFamily = "Arial";
			DisplayPropsWindow.document.body.style.fontSize = "12px";
		} catch (e) { }
	}

	window.focus();

}


function isGlobalDefined(variable) {
	return eval("(typeof(" + variable + ") != 'undefined');");
}

Number.prototype.addCommas = function() {
	nStr = this;
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

Date.prototype.toShortDate = function() {
	var d = this;
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	curr_month++;
	var curr_year = d.getFullYear();
	return curr_date + "/" + curr_month + "/" + curr_year;
}

function GetHtmlLink(data, CssClass) {
    var CssClassText = "";
    if (CssClass == null || typeof (CssClass) == "undefined") {
        if (data.CssClass != null && typeof (data.CssClass) != "undefined") {
            CssClassText = "class=\"" + data.CssClass + "\"";
        }
    } else {
        CssClassText = "class=\"" + CssClass + "\"";
    }

    var StringFormat = "";

    if (data.Type == "HtmlLiteral") {
    	StringFormat = "<span {0}>{1}</span>"
    } else {
    	StringFormat = "<a href=\"{0}\" title=\"{1}\" alt=\"{1}\" {2} {4} onclick='ShowAjaxWait();' >{3}</a>"
    }

    return String.format(StringFormat,
					        data.Href,
					        data.Title,
					        CssClassText,
					        data.Content
				        );

}

