﻿function setVariables(){
if (navigator.appName == "Netscape") {
v=".top=";h=".left=";dS="document.";sD="";
y="window.pageYOffset";x="window.pageXOffset";}
else {h=".pixelLeft=";v=".pixelTop=";dS="";sD=".style";
y="document.body.scrollTop";x="document.body.scrollLeft";}checkLocationA()}
movex=0,movey=0,xdiff=0,ydiff=0,ystart=0,xstart=0

function checkLocation(){
object="floater";yy=eval(y);xx=eval(x);ydiff=ystart-yy;xdiff=xstart-xx;
if ((ydiff<(-1))||(ydiff>(1))) movey=Math.round(ydiff/10),ystart-=movey
if ((xdiff<(-1))||(xdiff>(1))) movex=Math.round(xdiff/10),xstart-=movex
eval(dS+object+sD+v+ystart);eval(dS+object+sD+h+xstart);
setTimeout("checkLocation()",10)}

function checkLocationA(){ystart=eval(y);xstart=eval(x);}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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 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_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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
 }

 var in_submit_order = false;

 $(document).ready(function() {
 	get_cart_timer();
 	var o = document.getElementById("ErrorMsg");
 	if (o && o.innerHTML.length > 0) {
 		if (o.innerHTML.length > 500)
 			errorwindow = showModalWindow('error-modal-panel', 'Error!', 200, 180, 400, 300, "error");
 		else if (o.innerHTML.length > 200)
 			errorwindow = showModalWindow('error-modal-panel', 'Error!', 200, 180, 350, 250, "error");
 		else
 			errorwindow = showModalWindow('error-modal-panel', 'Error!', 200, 180, 300, 200, "error");
 		errorwindow.find('.modal-content').html(o.innerHTML);

 	}
 	else {
 		o = document.getElementById("NoteMsg");
 		if (o && o.innerHTML.length > 0) {
 			if (o.innerHTML.length > 500)
 				notewindow = showModalWindow('note-modal-panel', 'Notification', 200, 180, 300, 250);
 			else if (o.innerHTML.length > 200)
 				notewindow = showModalWindow('note-modal-panel', 'Notification', 200, 180, 250, 180);
 			else
 				notewindow = showModalWindow('note-modal-panel', 'Notification', 200, 180, 200, 140);
 			notewindow.find('.modal-content').html(o.innerHTML);
 			NotificationTimeout = setTimeout("NotificationClose()", NotificationAutoTimeout);
 			NotificationVisible = true;
 		}
 	}
 	var a_prob_link = $g("a_prob_link");
 	var vcust = readCookie("VCUST");
 	if (vcust && vcust.length > 0 && a_prob_link)
 		a_prob_link.href += ("%26vc=" + vcust);
 });


 // ------------------------- mouse tracking -------------------------

 function trackMouse(i)
 {
 	if (i == 'start')
 	{
 		if (!document.all)
 			document.captureEvents(Event.MOUSEMOVE)
 		document.onmousemove = getMouseXY;
 	}
 	else
 	{
 		if (!document.all)
 			document.captureEvents(Event.NONE)
 		document.onmousemove = null;
 	}
 }


 var mouseX = 0;
 var mouseY = 0;

 function getMouseXY(e)
 {
 	if (document.all)
 	{
 		mouseX = event.clientX + document.body.scrollLeft;
 		mouseY = event.clientY + document.body.scrollTop;
 	}
 	else
 	{
 		mouseX = e.pageX;
 		mouseY = e.pageY;
 	}
 	return true;
 }


 var counter = 0;

 function hidemessage()
 {
 	//alert("counter: " + counter);

 	if (counter > 0)
 	{
 		$("#msg").fadeOut("slow");
 		counter = 0;
 	}
 }

 function hiderules()
 {
 	$("#rules").fadeOut("slow");
 }

 function showrules(id)
 {
 	var loc = getxy(id);

 	$("#rules").css("top", loc.y + 20 + "px");
 	$("#rules").css("left", loc.x + 100 + "px");

 	$("#rules").html("Buy 3 Operas and Save!<br/>Get 10% off<br/><br/><a href='javascript:void(0);' onclick='hiderules();'>close</a>");
 	$("#rules").fadeIn("slow");
 }


 var veil_visible = false;
 var veil_count = 0;


 function show_veil()
 {
 	if (veil_count == 0)
 	{
 		try
 		{
 			var ww = getwindowsize();
 			var st = getscrolltop();
 			$('#veil').css("top", "" + st.y + "px");
 			$("#veil").css("width", "" + (ww.x - 1) + "px");
 			$("#veil").css("height", "" + (ww.y - 1) + "px");
 			$('#veil').css("filter", "alpha(opacity=10)");
 			$('#veil').fadeIn('slow');
 			try
 			{
 				veil_showing(); // may not exist;
 			}
 			catch (err) { }
 			veil_visible = true;
 		}
 		catch (err) { alert(err.description ? err.description : err); }
 	}
 	veil_count++;
 }

 function hide_veil()
 {
 	if (veil_count == 1)
 	{
 		if (veil_visible)
 		{
 			$('#veil').fadeOut('slow');
 			try
 			{
 				veil_hiding(); // may not exist;
 			}
 			catch (err) { }
 			veil_visible = false;
 		}
 		if (in_submit_order)
 		{
 			in_submit_order = false;
 			document.getElementById("btn_submit_order").value = submit_order_button_text;
 		}
 	}
 	veil_count--;
 }


 var itemvisibility = [];

 function hideModalWindow(id)
 {
 	if (itemvisibility[id] && (itemvisibility[id] == true))
 	{
 		$('#' + id).fadeOut("normal");
 		itemvisibility[id] = false;
 	}
 }

 var nextzindexid = 11111;

 function showModalWindow(id, title, x, y, width, height, style, dontCenter)
 {

 	if ($('#' + id).get(0))
 	{
 		try
 		{
 			adjustModalWindowPosition(id, width);
 		}
 		catch (err) { /* ignore */ }
 		$('#' + id).fadeIn("normal");
 	} else
 	{
 		if (!style)
 			style = "normal"
 		var newModalWindow = '';
 		newModalWindow += '<div class="dw" id="' + id + '" style="position: absolute; z-index: ' + nextzindexid + '; width: ' + (width + 8) + 'px; height: ' + (height + 8) + 'px; left: ' + x + 'px; top: ' + y + 'px;">';
 		newModalWindow += '<div class="dialogwindow ' + style + '" id="' + id + '_main" style="width: ' + (width) + 'px; height: ' + height + 'px; left: 0; top: 0; position:absolute; z-index: 100;">';
 		newModalWindow += '<div class="titlebar ' + style + '" style="width: ' + (width - 1) + 'px;"><span class="title" style="font-family:Arial;font-size:10pt;font-weight:bold;">' + title + '</span><div class="x"><a href="#" onclick="hideModalWindow(\'' + id + '\');" title="close">close</a></div></div>';
 		newModalWindow += '<div class="modal-content" style="width: ' + (width - 12) + '"></div></div>';
 		newModalWindow += '<div class="modal-shadow" style="z-index:99; position:absolute; top: 7px; left: 7px; width: ' + (width) + 'px; height: ' + height + 'px;" ></div>';
 		newModalWindow += '</div>';
 		$('body').append(newModalWindow);
 		try
 		{
 			if (dontCenter == null || !dontCenter)
 				adjustModalWindowPosition(id, width);
 		}
 		catch (err) { /* ignore */ }
 		$('#' + id).fadeIn("normal");
 		nextzindexid++;
 	}
 	itemvisibility[id] = true;
 	return $('#' + id);
 }

 function modalWindowSample()
 {
 	var acctmaintWindow = showModalWindow('acctmaint-modal-panel', 'Your account', mouseX - 100 < 0 ? 0 : mouseX - 100, mouseY - 16, 200, 140, "error");
 	var modalContent = "<p>This is a test</p>";
 	acctmaintWindow.find('.modal-content').html(modalContent);
 }

 var IE = document.all ? true : false;
 var mouseX = 0;
 var mouseY = 0;

 // start capturing mouse movement
 function mcstart()
 {
 	if (!IE)
 		document.captureEvents(Event.MOUSEMOVE);
 	document.onmousemove = getMouseXY;
 }

 // stop capturing mouse movement
 function mcstop()
 {
 	document.onmousemove = null;
 }
 var NotificationAutoTimeout = 8000; // 3 secs
 var NotificationTimeout;
 var NotificationVisible = false;

 var errorwindow;
 var notewindow;

 function ErrorMessage(msg, caption)
 {
 	if (!caption)
 	{
 		caption = "Error";
 	}

 	if (msg.length > 500)
 		errorwindow = showModalWindow('error-modal-panel', caption, 250, 150, 350, 280, "error");
 	else if (msg.length > 200)
 		errorwindow = showModalWindow('error-modal-panel', caption, 250, 150, 300, 230, "error");
 	else
 		errorwindow = showModalWindow('error-modal-panel', caption, 250, 150, 250, 200, "error");
 	errorwindow.find('.modal-content').html(msg);
 }
 function Notification(msg, caption)
 {
 	if (!caption)
 	{
 		caption = "Notification";
 	}
 	if (msg.length > 500)
 		notewindow = showModalWindow('note-modal-panel', caption, 250, 150, 350, 280);
 	else if (msg.length > 200)
 		notewindow = showModalWindow('note-modal-panel', caption, 250, 150, 300, 230);
 	else
 		notewindow = showModalWindow('note-modal-panel', caption, 250, 150, 250, 200);
 	notewindow.find('.modal-content').html(msg);
 	NotificationVisible = true;
 }

 function NotificationClose()
 {
 	if (NotificationVisible && itemvisibility["note-modal-panel"])
 	{
 		$('#note-modal-panel').fadeOut('slow');
 		NotificationVisible = false;
 	}
 }

 var cartreq = null;
 var secs_remaining = 99999;
 var cart_timer;
 var redirect_to_cart_timer;
 var stats = "";

 function format_time(i)
 {
 	o = document.getElementById("timeremaining");

 	if (o)
 	{
 		// alert("1: " + (i % 60));
 		j = i % 60;
 		// alert("2");
 		if (j == 0)
 			k = Math.ceil(i / 60);
 		else
 			k = Math.ceil(i / 60) - 1;
 		if (j < 10)
 			j = "0" + j;
 		o.innerHTML = "" + k + ":" + j;
 	}
 }

 function decrement_timer()
 {
 	secs_remaining--;
 	if (secs_remaining > -1)
 	{
 		format_time(secs_remaining);
 		clearTimeout(cart_timer);
 		begin_timer();

 		if (secs_remaining < 60)
 			$("#timeremaining").css("color", "red");
 	}
 	else
 	{
 		window.location.href = ROOT + "/Cart/expired.aspx";
 	}
 }

 function begin_timer()
 {
 	cart_timer = setTimeout("decrement_timer();", 1000);
 }

 function timer_retrieved()
 {
 	if (cartreq != null)
 		if (cartreq.readyState < 4)
 		return;

 	var cky = readCookie("FloridaUser");
 	if (cky != null)
 	{
 		// alert("cky=" + cky);
 		if (cky != "SUBS")
 		{
 			var msa = cky.split(":");
 			var mv = (parseInt(msa[0]) * 60) + parseInt(msa[1]);
 			secs_remaining = mv;
 			begin_timer();
 		}
 		if (document.getElementById("user-order-status") != null && cartreq.responseText != null)
 			$("#user-order-status").html(cartreq.responseText).show();
 	}
 	else
 		$("#user-order-status").hide();
 }

 function get_cart_timer()
 {
 	cartreq = getreq();
 	if (cartreq)
 	{
 		cartreq.onreadystatechange = timer_retrieved;
 		cartreq.open("GET", ROOT + "/Lib/Ajax/_timer.aspx", true);
 		cartreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
 		cartreq.send("");
 	}
 }

 var webreq = null;
 var wc_counter = 0;

 function hide_webcontent()
 {
 	if (wc_counter > 0)
 		$("#webcontent").hide();
 }

 function webcontent_retrieved()
 {
 	if (webreq.readyState < 4)
 		return;

 	$("#webcontent").html(webreq.responseText);
 	$("#webcontent").fadeIn("slow");
 	wc_counter++;
 }

 function show_info_message(id, target)
 {
 	var webcontent_placeholder = document.getElementById("webcontent");

 	webreq = getreq();
 	if (webreq)
 	{
 		var loc = getxy(target);
 		webcontent_placeholder.style.top = (loc.y + 17) + "px";
 		webcontent_placeholder.style.left = (loc.x + 60) + "px";

 		webreq.onreadystatechange = webcontent_retrieved;
 		webreq.open("GET", ROOT + "/Lib/Ajax/_webcontent.aspx?id=" + id, true);
 		webreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
 		webreq.send("");

 	}
 }

 function allow_email_contact(oCheckbox) {
 	if (oCheckbox.checked)
 		$('#operaclique_holder').slideDown("normal");
 	else
 		$('#operaclique_holder').slideUp("normal");
 	
 }