﻿function AppLoad() {
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
	Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequest);
}

function BeginRequest(sender, args) {
}

function EndRequest(sender, args) {
	if (args.get_error() != undefined) {
		var errorMessage = 'An unspecified error occurred.';
		if (args.get_response().get_statusCode() == '200') errorMessage = args.get_error().message;

		$get('ErrorMessage').innerHTML = errorMessage.replace('Sys.WebForms.PageRequestManagerServerErrorException:', '');

		var modalPopupBehavior = $find('ErrorDialogBehavior');
		modalPopupBehavior.show();

		args.set_errorHandled(true);
	}
	if (typeof (OnLoadEvent) == 'function') OnLoadEvent('AJAX');
	if (typeof (OnLoadEvent1) == 'function') OnLoadEvent1('AJAX');
	if (typeof (OnLoadEvent2) == 'function') OnLoadEvent2('AJAX');
	if (typeof (OnLoadEvent3) == 'function') OnLoadEvent3('AJAX');

	var DialogID = getCookie("TS.DialogClose");
	setCookie("TS.DialogClose", "");
	if (DialogID != null && DialogID != "") window.parent.DialogClose(DialogID);
}

function FocusOnEnterKey(ControlName) {
	if (window.event.keyCode != 13) return true;

	document.getElementById(ControlName).focus();
	return false;
}

function PostOnEnterKey(ControlName) {
	if (window.event.keyCode != 13) return true;

	__doPostBack(ControlName, '');
	return false;
}

///// DIALOG BOX 
function DialogClose(DialogID) {
	var DialogBox = $find(DialogID);
	DialogBox.hide();

	var DialogResult = getCookie("TS.DialogResult");
	setCookie("TS.DialogResult", "");

	return DialogResult == "OK" ? DialogOK(DialogID) : DialogCancel(DialogID);
}

function DialogCancel(DialogID) {
	var DialogCancelPage = $get(DialogID + '_CancelPage').value;
	if (DialogCancelPage != "") window.location = DialogCancelPage == "SAMEPAGE" ? window.location : DialogCancelPage;
}

function DialogOK(DialogID) {
	var DialogOKPage = $get(DialogID + '_OKPage').value;
	if (DialogOKPage != "") window.location = DialogOKPage == "SAMEPAGE" ? window.location : DialogOKPage;
}

function ShowDialog(DialogID) {
	var DialogBox = $find(DialogID);
	DialogBox.show();
}

function ShowDialog(DialogID, Title, DialogPage) {
	$get(DialogID + "_IFrame").src = DialogPage;
	$get(DialogID + "_Title").innerHTML = Title

	var DialogBox = $find(DialogID);
	DialogBox.show();
}
//// END DIALOG BOX

///// MESSAGE BOX
function ShowMessageBox(MessageBoxID, Title, Icon, Message) {
	$get(MessageBoxID + "_Title").innerHTML = Title
	$get(MessageBoxID + "_Icon").src = Icon
	$get(MessageBoxID + "_Message").innerHTML = Message

	var MessageBox = $find(MessageBoxID);
	MessageBox.show();
}

//// END MESSAGE BOX
function ParentOnLoad() {
	//Sys.Application.add_load(AppLoad); 
	AppLoad();
	if (typeof (OnLoadEvent) == 'function') OnLoadEvent('PAGE');
	if (typeof (OnLoadEvent1) == 'function') OnLoadEvent1('PAGE');
	if (typeof (OnLoadEvent2) == 'function') OnLoadEvent2('PAGE');
	if (typeof (OnLoadEvent3) == 'function') OnLoadEvent3('PAGE');
}

function ParentOnUnload() {
	if (typeof (OnUnloadEvent) == 'function') OnUnloadEvent();
}

function checkKey(aEvent) {
	if (window.event && window.event.keyCode == 13 && window.event.srcElement && window.event.srcElement.type != "textarea")
		return false;
	else if (aEvent && aEvent.which == 13) //&& aEvent.srcElement && aEvent.srcElement.type != "textarea" )
		return false;
	return true;
}

function getCookie(name) {
	var pos
	var token = name + "=";
	var tnlen = token.length;
	var cklen = document.cookie.length;
	var i = 0;
	var j;
	while (i < cklen) {
		j = i + tnlen;
		if (document.cookie.substring(i, j) == token) {
			pos = document.cookie.indexOf(";", j);
			if (pos == -1) pos = document.cookie.length;
			return unescape(document.cookie.substring(j, pos));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie(name, value) {
	document.cookie = name + "=" + escape(value) + ";path=/";
}

function removeCookie(name) {
	document.cookie = name + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function DateDiff(Date1, Date2) {
	date1 = new Date(Date1);
	date2 = new Date(Date2);
	diff = new Date();

	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();

	//	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	//	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);
	//	weeks = (weeks > 0 ? weeks + " weeks, " : "");

	days = Math.floor(timediff / (1000 * 60 * 60 * 24));
	timediff -= days * (1000 * 60 * 60 * 24);
	days = days > 0 ? days + (days == 1 ? " day " : " days ") : "";

	hours = Math.floor(timediff / (1000 * 60 * 60));
	timediff -= hours * (1000 * 60 * 60);
	hours = hours > 0 ? hours + (hours == 1 ? " hour " : " hours ") : "";

	mins = Math.floor(timediff / (1000 * 60));
	timediff -= mins * (1000 * 60);
	min = mins + " min ";

	secs = Math.floor(timediff / 1000);
	timediff -= secs * 1000;
	secs = secs + " sec";

	return days + hours + min + secs;
}

function SetDefaultText(field, text, OnFocus) {
    var txt = document.getElementById(field).value;
	if (txt == '' && !OnFocus ) {
		document.getElementById(field).value = text;
		document.getElementById(field).style.fontStyle = 'italic';
		document.getElementById(field).style.color = 'DarkGray';
	}
	if (txt == text) {
		document.getElementById(field).value = '';
		document.getElementById(field).style.fontStyle = 'normal';
		document.getElementById(field).style.color = '';
	}
}

//////AD SERVING BEGINS
//configuration
OAS_url = 'http://oasc03001.247realmedia.com/RealMedia/ads/';
//OAS_sitepage = window.location.hostname + window.location.pathname;
OAS_sitepage = 'www.topbuttontest.com';
OAS_listpos = 'Top,Right,Bottom';
OAS_query = '';
OAS_target = '_top';
//end of configuration

OAS_version = 10; // The code in Header.ascx changes it to the right version

OAS_rn = new String(Math.random());
OAS_rns = OAS_rn.substring(2, 11);

function OAS_NORMAL(pos) {
	document.write('<A HREF="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" TARGET=' + OAS_target + '>');
	document.write('<IMG SRC="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" BORDER=0></A>');
}

// MJX		
//function LOAD_RICH() { document.write('<SCRIPT LANGUAGE=JavaScript1.1 SRC="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '"><\/SCRIPT>'); }
//function LOAD_ADS( Page, Positions ) { OAS_sitepage = Page; OAS_listpos = Positions; if (OAS_version >= 11)	LOAD_RICH(); }
//function OAS_AD(pos) { if (OAS_version >= 11) OAS_RICH(pos); else OAS_NORMAL(pos); }

// RX substitution for MJX
function LOAD_ADS(Page, Positions) { OAS_sitepage = Page; }
function OAS_AD(pos) { SHOW_AD(OAS_sitepage, pos); }

//RX
function SHOW_AD(Page, Position) {
	OAS_sitepage = Page; OAS_listpos = Position;
	if (OAS_version < 11) OAS_NORMAL(Position); else document.write('<SCRIPT LANGUAGE="JavaScript1.1" SRC="' + OAS_url + 'adstream_jx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '"></SCRIPT>');
}
//////AD SERVING ENDS
