function EditAsHTML( EditorName )
{
	var Return  = window.showModalDialog('/Admin/Protected/Vendor/HtmlEditor.aspx',document.getElementById(EditorName).value,'dialogHeight:500px;dialogWidth:700px;resizable:yes;edge:raised'); 
	if (typeof Return == 'undefined' ) return;
	
	document.getElementById(EditorName).value = Return; 
	return false;
}

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 showheight(height)   
{    
	//document.getElementById('flashdiv').style.height=var1;document.myflash.height=height;                     
    //document.myflash.myembed.height=height;          
} 

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;
	} //End While
	return null;
}

function setCookie(name, value)
{ 
	document.cookie = name + "=" + escape(value)
}

function deleteCookie(name)
{ 
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = getCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function CheckCookies()
{
	var gCookieName;
	var gCookieValueRet;
	gCookieName="AVCOOKIETEST";

	gCookieValue="AV_TESTING_COOKIE";
	gCookieValueRet="???"

	setCookie(gCookieName,gCookieValue,1);
	gCookieValueRet=getCookie(gCookieName);
	
	if (gCookieValueRet == null)
	{
		window.alert("To login, please change your Privacy Level on your browser to accept cookies. To learn how to do that please press OK and follow instructions on the following popup page.");
		window.open("NoCookies.htm","smallwindow","top=20,height=550px,resizable=yes,scrollbars=yes");
		return false;
	}
	return true;
}

function AppLoad()
{
	if( typeof Sys == 'undefined' ) return;
	
	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();
	if (typeof (OnLoadEvent1) == 'function') OnLoadEvent1('AJAX');
	if (typeof (OnLoadEvent2) == 'function') OnLoadEvent2('AJAX');
	if (typeof (OnLoadEvent3) == 'function') OnLoadEvent3('AJAX');
}

function ParentOnLoad() {
    AppLoad(); 
	if (typeof (OnLoadEvent) == 'function') OnLoadEvent();
	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 PostOnEnterKey(ControlName) {
    if (window.event.keyCode != 13) return true;

    __doPostBack(ControlName, '');
    return false;
}

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 = '';
    }
}

///// DIALOG BOX
function DialogClose( DialogCancelID, DialogOKID ) {
	var DialogResult = getCookie("PF.DialogResult");
	setCookie("PF.DialogResult", "");
	return DialogResult == "OK" ? DialogOK(DialogOKID) : DialogCancel(DialogCancelID);
}
	
function DialogCancel( DialogCancelID )
{
	var DialogCancelPage = $get(DialogCancelID).value;
	if( DialogCancelPage != "" ) window.location = DialogCancelPage == "SAMEPAGE" ? window.location : DialogCancelPage;
}

function DialogOK( DialogOKID )
{
	var DialogOKPage = $get(DialogOKID).value;
	if( DialogOKPage != "" ) window.location = DialogOKPage == "SAMEPAGE" ? window.location : DialogOKPage;
}

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 MM_ReloadPage(init) 
{
	//reloads the window if Nav4 resized
	if (init==true) with (navigator) 
	{
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
		{
			document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
		location.reload();
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// function to launch upoc screen
function LaunchMsgr() {
	window.open("http://www.upoc.com/nysale", "upoc", "width=800,height=750, scrollbars, resizable");
}

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;
}
var PayPalCartWindow = null;

function AddtoPayPalCart(Title, Amount)
{
	PayPalCartWindow = window.open("https://www.paypal.com/cart/add=1&amp;business=mike@nysale.com&amp;item_name=" + Title + "&amp;amount=" + Amount + "&amp;return=http%3A//www.topbutton.com&amp;cancel_return=http%3A//www.topbutton.com","CARTWINDOW","dependent,width=750,height=550,scrollbars,location,resizable,status",true);
	if( PayPalCartWindow != null ) setTimeout("PayPalCartWindow.focus();",250);
}

function ShowPayPalCart()
{
	PayPalCartWindow = window.open("https://www.paypal.com/cart/display=1&amp;business=mike@nysale.com&amp;return=http%3A//www.topbutton.com&amp;cancel_return=http%3A//www.topbutton.com","CARTWINDOW","dependent,width=750,height=550,scrollbars,location,resizable,status",true);
	if( PayPalCartWindow != null ) setTimeout("PayPalCartWindow.focus();",250);
}

//////AD SERVING BEGINS
//configuration	OLD: oasc03001
OAS_url = 'http://OASC03016.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



