//<!--
// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4, 
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//     is_sun, is_sun4, is_sun5, is_suni86
//     is_irix, is_irix5, is_irix6
//     is_hpux, is_hpux9, is_hpux10
//     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//     is_linux, is_sco, is_unixware, is_mpras, is_reliant
//     is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater") 
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly  = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);
    var is_firefox = (agt.indexOf('firefox') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1); 

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) { is_js = 1.0; }
    else if (is_nav3) { is_js = 1.1; }
    else if (is_opera5up) { is_js = 1.3; }
    else if (is_opera) { is_js = 1.1; }
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) { is_js = 1.2; }
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) { is_js = 1.3; }
    else if (is_hotjava3up) { is_js = 1.4; }
    else if (is_nav6 || is_gecko) { is_js = 1.5; }
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (is_nav6up) { is_js = 1.5; }
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) { is_js = 1.3; }

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else { is_js = 0.0; }

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) || (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("windows 16-bit")!=-1) );  

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) || (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 || ((is_major >= 4) && (navigator.platform == "Win32")) || (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) { is_js = 1.4; }
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);    
    var is_aix2  = (agt.indexOf("aix 2") !=-1);    
    var is_aix3  = (agt.indexOf("aix 3") !=-1);    
    var is_aix4  = (agt.indexOf("aix 4") !=-1);    
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1); 
    var is_mpras    = (agt.indexOf("ncr")!=-1); 
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || is_sco ||is_unixware || is_mpras || is_reliant || is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

//--> end hide JavaScript

var currentActiveContainer = "";
var currentActiveHeight = 0;
var currentActiveWidth = 0;
var inSecurity = false;
var server = "";

window.onresize = resizeLauncher;

function resizeLauncher() {
	centerActiveContainer();
}

function windowSize() {
  var myWidth = 0, myHeight = 0, myScrollTop = 0; myScrollLeft = 0;

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
   if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    myScrollTop = window.pageYOffset;
    myScrollLeft = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    myScrollTop = document.body.scrollTop;
    myScrollLeft = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    myScrollTop = document.documentElement.scrollTop;
    myScrollLeft = document.documentElement.scrollLeft;
  }
  
  return {height : myHeight, width : myWidth, scrollTop : myScrollTop, scrollLeft : myScrollLeft};
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++) {
		if (x[i].id == name) {
		 	foundLayer = x[i];
		} else if (x[i].layers.length) {
			var tmp = getObjNN4(x[i],name);
		}
		if (tmp) { foundLayer = tmp; }
	}
	return foundLayer;
}

function getParentElement(Elem) {
	var elem;
	if ( is_nav ) {
		if (is_nav4up) {
			elem = parent.document.getElementById(Elem);
		} else {
			elem = getObjNN4(parent.document, Elem);
		}
	} else {
		if(document.getElementById) {
			elem = parent.document.getElementById(Elem);
		} else if (parent.document.all){
			elem = parent.document.all[Elem];
		}	
	}
	return elem;
}

function getElement(Elem) {
	var elem;
	if ( is_nav ) {
		if (is_nav4up) {
			elem = document.getElementById(Elem);
		} else {
			elem = getObjNN4(document, Elem);
		}
	} else {
		if(document.getElementById) {
			elem = document.getElementById(Elem);
		} else if (document.all){
			elem = document.all[Elem];
		}	
	}
	return elem;
}

function getElementTop(Elem) {
	var elem = getElement(Elem);
	var yPos;
	var tempEl;
	if ( is_nav4 ) {
		return elem.pageY;
	} else {
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl !== null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}

function getElementTopObj(elem) {
	var yPos;
	var tempEl;
	if ( is_nav4 ) {
		return elem.pageY;
	} else {
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl !== null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}

function getElementLeft(Elem) {
	var elem = getElement(Elem);
	var xPos;
	var tempEl;
	if ( is_nav4 ) {
		return elem.pageX;
	} else {
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl !== null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}

function getElementLeftObj(elem) {
	var xPos;
	var tempEl;
	if ( is_nav4 ) {
		return elem.pageX;
	} else {
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl !== null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}

function replaceAll( str, searchTerm, replaceWith, ignoreCase )
{
var regex = "/"+searchTerm+"/g";
if( ignoreCase ) { regex += "i"; }

return str.replace( eval(regex), replaceWith );
}

var defaultColumn = 0;
var defaultOrder = 0;
var defaultLayout = 0;
var defaultKeyword = "";
var defaultAll = 0;
var defaultMerchantId = "";
var defaultBrand = "";

function url(mode, lineage, id, all, cookies, sessionid) {
	var buf = "";
	if (inSecurity) {
		buf = "http://"+server;
		if (server == "localhost") {
			buf += ":8080";
		}
	}
	if (mode == 1) {
		// product list page
		buf += "/products/";
		for (var i=0; i<lineage.length; i++) {
			var title = replaceAll(lineage[i], " ", "-", false);
			title = title.toLowerCase();
			buf += title;
			if (i < (lineage.length - 1)) {
				buf += "-";
			}
		}
		buf += "/";
		buf += id;
		buf += ":"+defaultLayout;
		buf += ":"+defaultColumn;
		buf += ":"+defaultOrder;
		buf += ":1:1";
		if (!cookies) buf += ";jsessionid="+sessionid;
		return buf;
	}
	if (mode == 2) {
		buf += "/keywordproducts/";
		for (var i=0; i<lineage.length; i++) {
			var title = replaceAll(lineage[i], " ", "-", false);
			title = title.toLowerCase();
			buf += title;
			if (i < (lineage.length - 1)) {
				buf += "-";
			}
		}		
		buf += "/"+defaultKeyword+":"+defaultAll;
		buf += "/";
		buf += id;
		buf += ":"+defaultLayout;
		buf += ":"+defaultColumn;
		buf += ":"+defaultOrder;
		buf += ":1:1";
		if (!cookies) buf += ";jsessionid="+sessionid;
		return buf;
	}
	if (mode == 21) {
		buf += "/keyword/"+lineage+"/"+id+":"+all;
		if (!cookies) buf += ";jsessionid="+sessionid;
		return buf;
	}
	if (mode == 3) {
		buf += "/storeproducts/";
		for (var i=0; i<lineage.length; i++) {
			var title = replaceAll(lineage[i], " ", "-", false);
			title = title.toLowerCase();
			buf += title;
			if (i < (lineage.length - 1)) {
				buf += "-";
			}
		}		
		buf += "/"+defaultMerchantId;
		buf += ":";
		buf += id;
		buf += ":"+defaultLayout;
		buf += ":"+defaultColumn;
		buf += ":"+defaultOrder;
		buf += ":1:1";
		if (!cookies) buf += ";jsessionid="+sessionid;
		return buf;	
	}
	if (mode == 4) {
		buf += "/brandproducts/";
		for (var i=0; i<lineage.length; i++) {
			var title = replaceAll(lineage[i], " ", "-", false);
			title = title.toLowerCase();
			buf += title;
			if (i < (lineage.length - 1)) {
				buf += "-";
			}
		}		
		buf += "/"+defaultBrand;
		buf += ":";
		buf += id;
		buf += ":"+defaultLayout;
		buf += ":"+defaultColumn;
		buf += ":"+defaultOrder;
		buf += ":1:1";
		if (!cookies) buf += ";jsessionid="+sessionid;
		return buf;	
	}
}

function initURL(layout, column, order) {
	defaultLayout = layout;
	defaultColumn = column;
	defaultOrder = order;
}

function initKeyword(keyword, all) {
	defaultKeyword = keyword;
	defaultAll = all;
}

function initMerchant(merchantid) {
	defaultMerchantId = merchantid;
}

function initBrand(brand) {
	defaultBrand = brand;
}

function showEmailClient(mode, url, product) {
	closeAllDialogs();

	var tite;
	var from = getElement("fromemail");
	var to = getElement("toemail");
	var subject = getElement("subjectemail");
	var comments = getElement("commentsemail");
	var emailerror = getElement("emailerror");
	from.value = "";
	to.value = "";
	to.className = "";
	to.disabled = false;
	comments.value = "";
	emailerror.innerHTML = "&nbsp;";
	to.className = "input";
	from.className = "input";
	if (is_firefox) {
		openDialog("emailwindow", 387, 400);
	} else if (is_nav) {
		openDialog("emailwindow", 360, 400);
	} else if (is_ie) {
		openDialog("emailwindow", 380, 400);	
	} else {
		openDialog("emailwindow", 380, 400);		
	}
	if (mode == 1) {
		title = "E-Mail This Page To A Friend";
		subject.value = "Interesting Page from ShopMighty.com";
		to.focus();
	}
	if (mode == 2) {
		title = "E-Mail This Product To A Friend";
		subject.value = "Interesting Product from ShopMighty.com";
		to.focus();
	}
	if (mode == 3) {
		to.value = "contact@shopmighty.com";
		to.className = "emaildisable";
		to.disabled = true;
		title = "Contact ShopMighty.com";
		subject.value = "Customer Contact or Comments to ShopMighty.com";	
		from.focus();
	}
	var emailObj = getElement("emailtitle");
	emailObj.innerHTML = title;
	
	var emailmode = getElement("emailmode");
	var emailurl = getElement("emailurl");
	var emailproduct = getElement("emailproduct");
	emailmode.value = mode;
	emailurl.value = url;
	if (product.length > 0) {
		emailproduct.value = product;
	}	

}

function closeEmailClient() {
	var objEmail = getElement("emailwindow");
	closeDialog(objEmail);
}

function submitEmailClient() {
	var from = getElement("fromemail");
	var to = getElement("toemail");
	var subject = getElement("subjectemail");
	var comments = getElement("commentsemail");
	var emailerror = getElement("emailerror");
	var emailmode = getElement("emailmode");
	var emailurl = getElement("emailurl");
	var emailproduct = getElement("emailproduct");
	var fail = 0;
	if (to.value.length == 0) {
		emailerror.innerHTML = "Please specify a To E-Mail address.";
		to.className = "inputerror";
		to.focus();
		fail = 1;
	} else {
		var validate = validateEmail(to.value);
		if (validate.length > 0) {
			emailerror.innerHTML = "Please enter a valid E-Mail adress.";
			to.className = "inputerror";
			to.focus();
			fail = 1;
		} else {
			if (to.className == "inputerror") {
				to.className = "input";
			}
			emailerror.innerHTML = "&nbsp;";
		}
	}
	if (fail == 0) {
		if (from.value.length == 0) {
			emailerror.innerHTML = "Please specify a From E-Mail.";
			fail = 1;
			from.className = "inputerror";
			from.focus();
		} else {
			var validate = validateEmail(from.value);
			if (validate.length > 0) {
				emailerror.innerHTML = "Please enter a valid E-Mail address.";
				from.className = "inputerror";
				from.focus();
				fail = 1;
			} else {
				from.className = "input";
				emailerror.innerHTML = "&nbsp;";
			}
		}
	}
	if (fail == 0) {
		var emailsubmitcontainer = getElement("emailsubmitcontainer");
		var url = "web_mitrya/emailsubmit.jsp?mode=";
		url += emailmode.value;
		url += "&fromemail=";
		url += escape(from.value);
		url += "&toemail=";
		url += escape(to.value);
		url += "&url=";
		url += escape(emailurl.value);
		if (subject.value.length > 0) {
			url += "&subject=";
			url += escape(subject.value);
		}
		if (comments.value.length > 0) {
			url += "&comments=";
			url += escape(comments.value);
		}
		if (emailproduct.value.length > 0) {
			url += "&product=";
			url += escape(emailproduct.value);
		}
		closeEmailClient();
		emailsubmitcontainer.innerHTML = "<iframe src='" + url + "'></iframe>";
	}
}

function clearEmailSubmitContainer() {
	var emailsubmitcontainer = getElement("emailsubmitcontainer");
	emailsubmitcontainer.innerHTML = "";
}

function showMessage(mode, text, perminant) {
	closeAllDialogs();

	var title;
	var messageicon = getElement("messageicon");
	if (mode == 1) {
		title = "Information";
		messageicon.src = "iconlibrary/graphite/orange/comment.gif";
	}
	if (mode == 2) {
		title = "Alert";
		messageicon.src = "iconlibrary/graphite/red/exclamation.gif";
	}
	if (mode == 3) {
		title = "Question";
		messageicon.src = "iconlibrary/graphite/orange/question.gif";
	}
	if (mode == 4) {
		title = "Alert";
		messageicon.src = "iconlibrary/graphite/red/exclamation.gif";
	}
	var titleObj = getElement("messagetitle");
	titleObj.innerHTML = title;
	var messagewindowtext = getElement("messagewindowtext");
	messagewindowtext.innerHTML = text;
	if (is_firefox) {
		openDialog("messagewindow", 163, 350);
	} else if (is_nav) {
		openDialog("messagewindow", 160, 350);
	} else if (is_ie) {
		openDialog("messagewindow", 160, 350);	
	} else {
		openDialog("messagewindow", 160, 350);		
	}
	if (perminant == null) {
		setTimeout('closeMessage()', 10000);
	}
}

function closeMessage() {
	var objMessage = getElement("messagewindow");
	closeDialog(objMessage);
}

function bookmarksite(){
	var url = "http://www.shopmighty.com";
	var title = "ShopMighty.com - Where Friends and Family Shop";
	if (document.all) {
		window.external.AddFavorite(url, title);
	} else if (window.sidebar) { window.sidebar.addPanel(title, url, ""); }

}

function KeywordSearch(sessionid) {
	var keyword = makeStaticURLReady(getElement("searchtext").value);
	var category = getElement("searchdepartment").value;
	var all = 0;
	var cookies = cookiesEnabled();
	if (keyword.length > 0) {
		if (category == 0) {
			all = 1;
		}
		defaultKeyword = getElement("searchtext").value;
		window.location = url(21, defaultKeyword, category, all, cookies, sessionid);
	}
}

function makeStaticURLReady(text) {
	var purgePattern = "[,|(|)]|&\\s|-\\s|\"|#|/|:";
	var reg;
	reg = new RegExp(purgePattern, "g");
	text = text.replace(reg, " ");
	return text;
}

var resizeWindowInterval = 30;
var resizeWindowItem;
var resizeWindowExtra = "";
var resizeWindowEndSize = 0;
var resizeWindowCurrentSize = 0;
var resizeWindowGrowMode = 0;
var resizeWindowFraction = 0;
var resizeWindowFocus = "";
var resizeWinfowPosMode = 0;

function resizeWindow(windowItem, startSize, endSize, extraContent, focuselement) {
	resizeWindowItem = getElement(windowItem);
	if (endSize > startSize) {
		resizeWindowGrowMode = 1;
		resizeWindowFraction = 20;
	} else {
	 	var extra = getElement(extraContent);
	 	extra.style.display = "none";
	 	var focusEle = getElement(focuselement);
	 	focusEle.focus();
		resizeWindowGrowMode = 0;
		resizeWindowFraction = -20;
	}
	resizeWindowCurrentSize = startSize;
	resizeWindowEndSize = endSize;
	resizeWindowExtra = extraContent;
	resizeWindowFocus = focuselement;
	resizeWinfowPosMode = 0;
	setTimeout('growWindow()', resizeWindowInterval);
}

function resizeWindowFixed(windowItem, startSize, endSize) {
	resizeWindowItem = getElement(windowItem);
	if (endSize > startSize) {
		resizeWindowGrowMode = 1;
		resizeWindowFraction = 9;
	} else {
		resizeWindowGrowMode = 0;
		resizeWindowFraction = -9;
	}
	resizeWindowCurrentSize = startSize;
	resizeWindowEndSize = endSize;
	resizeWinfowPosMode = 1;
	setTimeout('growWindow()', resizeWindowInterval);
}
function growWindow() {
	var objWindow = windowSize();
	resizeWindowCurrentSize = resizeWindowCurrentSize + resizeWindowFraction;
	var more = 1;
	if (resizeWindowGrowMode == 1) {
		if (resizeWindowCurrentSize > resizeWindowEndSize) {
			resizeWindowCurrentSize = resizeWindowEndSize;
			if (resizeWindowExtra.length > 0) {
			 	var extra = getElement(resizeWindowExtra);
			 	extra.style.display = "block";
			}
			if (resizeWindowFocus.length > 0) {
			 	var focusEle = getElement(resizeWindowFocus);
			 	focusEle.focus();
			}
			more = 0;
		}
	} else {
		if (resizeWindowCurrentSize < resizeWindowEndSize) {
			resizeWindowCurrentSize = resizeWindowEndSize;
			more = 0;
		}
	}
	if (resizeWinfowPosMode == 0) {
		var newtop = objWindow.scrollTop + ((objWindow.height - resizeWindowCurrentSize) / 2);
		var newleft = (objWindow.width - 400) / 2;
		resizeWindowItem.style.top = newtop;
		resizeWindowItem.style.left = newleft;
	}
	resizeWindowItem.style.height = resizeWindowCurrentSize;
	if (more == 1) setTimeout('growWindow()', resizeWindowInterval);
}

function openDialog(dialog, height, width) {
	var objWindow = windowSize();
	var objDialog = getElement(dialog);
	objDialog.style.height = height;

	var newtop = objWindow.scrollTop + ((objWindow.height - height) / 2);
	var newleft = (objWindow.width - width) / 2;
	objDialog.style.top = newtop;
	objDialog.style.left = newleft;
	objDialog.style.display = "block";	
}

function closeDialog(objDialog) {
	currentActiveContainer = "";
	objDialog.style.display = "none";
	objDialog.style.top = 0;
	objDialog.style.left = -1000;		
}

function closeAllDialogs() {
	var objEmail = getElement("emailwindow");
	if (objEmail != null) closeDialog(objEmail);
	var objMessage = getElement("messagewindow");
	if (objMessage != null) closeDialog(objMessage);
	var objNewAccount = getElement("newshopperwindow");
	if (objNewAccount != null) closeDialog(objNewAccount);
	var objList = getElement("listmightylistwindow");
	if (objList != null) closeDialog(objList);
}

function centerActiveContainer() {
	if (currentActiveContainer.length > 0) {
		var cnt = getElement(currentActiveContainer);
		
		var objWindow = windowSize();
		var newtop = objWindow.scrollTop + ((objWindow.height - currentActiveHeight) / 2);
		var newleft = (objWindow.width - currentActiveWidth) / 2;
		
		if (newtop < 0) newtop = 0;
		if (newleft < 0) newleft = 0;
		
		cnt.style.top = newtop
		cnt.style.left = newleft;
	}
}

function focusNext(form, elemName, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        form.elements[elemName].focus( );
        return false;
    }
    return true;
}

function cookiesEnabled() {
   var tmpcookie = new Date();
   chkcookie = (tmpcookie.getTime() + '');
   document.cookie = "chkcookie=" + chkcookie + "; path=/";
   if (document.cookie.indexOf(chkcookie,0) < 0) {
     return false;
   } else {
     return true;
   }
}

var followupSessionId;
var followuptry;
var followupSessionFromURL;
function securefollowup(sessionid, tryCount, sessionFromURL) {
	followupSessionId = sessionid;
	followuptry = tryCount;
	followupSessionFromURL = sessionFromURL;
	setTimeout('securefollowupsubmit()',1000);
}

function securefollowupsubmit() {
	var url = "web_mitrya/transitionsession.jsp?sid="+followupSessionId+"&try="+followuptry+"&fromurl="+followupSessionFromURL;
	securefollowupcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";		
}

function TipDetail() {
	this.title = "";
	this.content = "";
}

function opentips(ptr, xoffset, yoffset, key) {
	var objWindow = windowSize();
	var pointTop = getElementTop(ptr)+yoffset;
	var pointLeft = getElementLeft(ptr)+xoffset;
	var mode = 1;
	if (((objWindow.width / 2)+100) < pointLeft) mode = 2;
	if (((objWindow.width / 2)-100) > pointLeft) mode = 0;
	var slide = 245;
	if (mode == 2) { slide = 390; }
	if (mode == 0) { slide = 100; }
	var dialogLeft = pointLeft-slide-8;
	var objDialogSlide = getElement("tipcontainerSilde");
	objDialogSlide.style.width = slide;

	var tip = tipLibrary(key)
	getElement("tipstitle").innerHTML = tip.title;
	getElement("tipdetailscontent").innerHTML = tip.content;

	var objDialog = getElement("tipcontainer");
	objDialog.style.top = pointTop;
	objDialog.style.left = dialogLeft;
	objDialog.style.display = "block";	
	resizeWindowFixed("tipdetailscontent", 1, 160);
	
}

function closetips() {
	var moretip = getElement("tipcontainer");
	moretip.style.display = "none";
	moretip.style.left = -1000;
}

function tipLibrary(key) {
	tip = new TipDetail;
	if (key == 1) {
		tip.title = "Search Tips to help you find what you want quicker";
		var str = "<big><b>Phrases: </b></big><u>Find a phrase by surrounding multiple words in quotes</u><br><br>Example: <i>\"water quality control\"</i> will find documents that contain those three words together in that order";
		str += "<br><br><big><b>Plus (+): </b></big><u>Precede all your search terms with a plus (+) symbol to perform an AND search</u><br><br>Example: <i>+maternal +health</i> will find all documents that contain both 'maternal' and 'health'<br><br><i>+maternal health</i> will find all documents that contain 'maternal' and <b>possibly</b> 'health'";
		str += "<br><br><big><b>OR: </b></big><u>If you do not specify an operator between search terms, OR will be used by default</u><br><br>Example: <i>maternal health</i> will find all documents that contain 'maternal' or 'health'<br><br><i>health OR maternal</i> will provide the same results";
		str += "<br><br><big><b>NOT: </b></big><u>Precede your search term with a minus (-) symbol to exclude products that contain that word, or alternatively, use the word NOT</u><br><br>Example: <i>+maternal -health</i> will find all documents that contain 'maternal', but not 'health'<br><br><i>maternal NOT health</i> will provide the same results";
		tip.content = str;
	}
	return tip;
}