//debugWin = window.open("","debugWin","height=500,width=400,resizable=yes,scrollbars=yes");

function println(str) {
  debugWin.document.writeln(str+"<br>");
}

function launchPopUp() {
  showLandingPagePopUp('/popup.html',400,230);
}

function showLandingPagePopUp(url, width, height, scrolling, name) {
  flag = true;
  now = new Date;
  exDate = new Date;
  exDate.setMonth( exDate.getMonth() + 6 );
  lastViewed = new Date;
  lastViewed.setMonth( lastViewed.getMonth() - 1 );

  if (document.cookie != "") {
    cooks = document.cookie.split(";");
    for (i=0; i<cooks.length; i++) {
      if ( cooks[i].split("=")[0].indexOf("lastViewed") != -1 ) {
        lastViewed = new Date( cooks[i].split("=")[1] );
        break;
      }
    }
    if ( lastViewed.getDate() == now.getDate() &&
         lastViewed.getMonth() == now.getMonth() ) {
      flag = false;
    }
  }

  //if (IE)
    //document.cookie = "lastViewed="+now+";expires="+exDate.toGMTString()+";domain=iomega.com;path=/;";
  //else
    document.cookie = "lastViewed=" + now + ";expires=" + exDate.toGMTString();

  if (flag) {
    openPopupWindow(url, width, height, scrolling, name);
    //window.focus();
  }
}

function openPopupWindow(url, width, height, scrolling, name) { //v2.0
    if (!width) width = 350;
    if (!height) height = 350;
    if (!scrolling) scrolling = "no";
    if (!name) name = "win"+Math.round(Math.random()*1000);
    features = "width="+width+","
             + "height="+height+","
             + "toolbar=no,"
             + "location=no,"
             + "status=no,"
             + "menubar=no,"
             + "scrollbars="+scrolling+","
             + "top="+(window.screen.height-height)/2+","
             + "left="+(window.screen.width-width)/2;
    nWin = window.open(url,name,features);
    nWin.focus();
}

/*     --- From IOD 'inc_header_nav' ---      */

/* Script to open toc page from original site */
function toc(which) {
	// The location of the URL to be opened in the remote window
	if(which.indexOf("regi")!=-1)theLocation = filePath+'/toc.html?pg=regi';
	else if(which.indexOf("clik")!=-1)theLocation = filePath+'/toc.html?pg=clik';
	else if(which.indexOf("zip")!=-1)theLocation = filePath+'/toc.html?pg=zip';
	else if(which.indexOf("zipcd")!=-1)theLocation = filePath+'/toc.html?pg=zipcd';
	else if(which.indexOf("jaz")!=-1)theLocation = filePath+'/toc.html?pg=jaz';
	else if(which.indexOf("buz")!=-1)theLocation = filePath+'/toc.html?pg=buz';
	else if(which.indexOf("ditto")!=-1)theLocation = filePath+'/toc.html?pg=ditto';
	else theLocation = filePath+'/toc.html';

	confirmWin = window.open(theLocation, 'confirmationWindow', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=440');

	// This is important for Netscape 2.0 to enable the opener property
	if (confirmWin.opener == null) {
	  confirmWin.opener = self;
	}

	// Bring focus to the window in browsers that support focus
	if (window.focus)
	    confirmWin.focus();
}

function close_this_page() {
  self.close();
}

function open_window(url) {
  LeftPosition = (screen.width) ? (screen.width - 425)/2 : 0;
  TopPosition = (screen.height) ? (screen.height - 300)/2 : 0;
  settings = "width=425,height=300,top="
       + TopPosition + ",left=" + LeftPosition
       + "toolbar=0,location=0,directories=0,status=0,menubar=0,"
       + "scrollbars=0,resizable=1";
  win = window.open(url, "IomegaDirect", settings);
  win.window.focus();
}

function open_logout_window(url) {
  LeftPosition = (screen.width) ? (screen.width - 550)/2 : 0;
  TopPosition = (screen.height) ? (screen.height - 450)/2 : 0;
  settings = "width=550,height=450,top="
       + TopPosition + ",left=" + LeftPosition
       + "toolbar=0,location=0,directories=0,status=0,menubar=0,"
       + "scrollbars=0,resizable=0";
  win = window.open(url, "IomegaDirect", settings);
  win.window.focus();
}

function open_login_window(url) {
  LeftPosition = (screen.width) ? (screen.width - 550)/2 : 0;
  TopPosition = (screen.height) ? (screen.height - 450)/2 : 0;
  settings = "width=550,height=450,top="
       + TopPosition + ",left=" + LeftPosition
       + "toolbar=0,location=0,directories=0,status=0,menubar=0,"
       + "scrollbars=0,resizable=0";
  win = window.open(url, "IomegaDirect", settings);
  win.window.focus();
}

/*   --- End From IOD 'inc_header_nav' ---     */


/*         --- From 'sleight.js' ---           */
var navPlatform = navigator.platform.toLowerCase();
if ((navPlatform == "win32" || navPlatform == "win64" || navPlatform == "wow64") && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	if (navigator.appVersion.indexOf("MSIE 6") > -1) {
		document.writeln('<style type="text/css">img, input.image { visibility:visible; } </style>');
		window.attachEvent("onload", fnLoadPngs);
	}
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && (Number(rslt[1]) >= 5.5 && Number(rslt[1]) <= 6));

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			fnFixPng(img);
			img.attachEvent("onpropertychange", fnPropertyChanged);
		}
		//img.style.visibility = "visible";
		
	}

	var nl = document.getElementsByTagName("INPUT");
	for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
		if (e.className && e.className.match(/\bimage\b/i) != null) {
			if (e.src.match(/\.png$/i) != null) {
				fnFixPng(e);
				e.attachEvent("onpropertychange", fnPropertyChanged);
			}
			//e.style.visibility = "visible";
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/x\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "/media/direct/images/css/shared/x.gif";
		}
	}
}

function dbg(o) {
	var s = "";
	var i = 0;
	for (var p in o) {
		s += p + ": " + o[p] + "\n";
		if (++i % 10 == 0) {
			alert(s);
			s = "";
		}
	}
	alert(s);
}

function fnFixPng(img) {
	var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "/media/direct/images/css/shared/x.gif";
}

/*        --- End From 'sleight.js' ---         */

/* Header Signup Functions */
function submitEmail(frm) {
  eml = frm.temail.value;
  atIndex = eml.indexOf('@');
  dotIndex = eml.indexOf('.', atIndex);
  if(atIndex < dotIndex) {
    frm.EMAIL.value = eml;
    frm.temail.value = '';
    openPopupWindow('', 450, 265, 'no', 'emlRegWin');
    return true;
  } else {
    alert("Please enter a valid email address");
    return false;
  }
}

function removeMsg(el, msg) {
  if(el.value == msg)
    el.value = '';
}
