function popup(url, name, features) {
    window.open(url, name, features);
}

function popupCustomerService(url, name) {
    popup(url, name, 'toolbars=no,resizable=no,overflow-x=hidden,overflow-y=auto,left=50,top=50,width=400,height=500');
}

function popupGlossary(url, name) {
    popup(url, name, 'toolbars=no,resizable=no,overflow-x=hidden,overflow-y=auto,left=50,top=50,width=447,height=524');
}

function email_a_friend(url) {
    popup(url, '', 'toolbars=no,status=1,resizable=0,overflow-x=hidden,overflow-y=hidden,left=50,top=50,width=437,height=520');
}

function popupBanner(url) {
    popup(url, 'banner', 'toolbars=no,status=1,resizable=0,overflow-x=hidden,overflow-y=hidden,left=50,top=50,width=437,height=520');
}

function popupProductVideo(url) {
    popup(url, 'popdb','toolbars=no,left=50,top=50,width=430,height=322');
}

function popupPaymentSchedule(url, name) {
    popup(url, name, 'toolbars=no,resizable=yes,overflow-x=hidden,overflow-y=auto,left=50,top=50,width=600,height=525');
}

function goToProduct() {

	document.getElementById("product_chosen").value = document.getElementById("relatedProduct").value;
	document.forms.select_related_product.submit();
}

function setVisible(elemID) {
    if (document.getElementById) {
        var styleObj = document.getElementById(elemID).style;
        if (styleObj.display == "block") {
            styleObj.display = "none";
        } else {
            styleObj.display = "block";
        }
        return false;
    } else {
        return true;
    }
}

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 MM_swapImgRestore() { //vr 3.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() { //vr 3.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_findObj(n, d) { //vr 4.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 setActionSubmitForm(formName, action, useSSL) {
	var form = document.forms[formName];
	var prefix = "https://";
	if(useSSL != null && useSSL == "false") {
		prefix = "http://";
	}
	var pHost = document.location.host;
	var inx = pHost.indexOf(":");
	if(inx > -1 && prefix == "https://") {
		//This is a just for local environments not prod.
		pHost = pHost.substring(0,inx) + ":8" + pHost.substring(inx+2);
	}

	if(form != null) {
		var fullAction = prefix + pHost + action;
		form.action = fullAction;
		return true;
	}
	return false;
}

var mmOpenContainer = null;
var mmOpenMenus = null;
var mmHideMenuTimer = null;

function MM_menuStartTimeout(hideTimeout) {
	mmHideMenuTimer = setTimeout("MM_menuHideMenus()", hideTimeout);
}

function MM_menuHideMenus() {
	MM_menuResetTimeout();
	if(mmOpenContainer) {
		var c = document.getElementById(mmOpenContainer);
		c.style.visibility = "";
		mmOpenContainer = null;
	}
	if( mmOpenMenus ) {
		for(var i = 0; i < mmOpenMenus.length ; i++) {
			var m = document.getElementById(mmOpenMenus[i]);
			m.style.visibility = "hidden";
		}
		mmOpenMenus = null;
	}
}

function MM_menuHideSubmenus(menuName) {
	if( mmOpenMenus ) {
		var h = false;
		var c = 0;
		for(var i = 0; i < mmOpenMenus.length ; i++) {
			if( h ) {
				var m = document.getElementById(mmOpenMenus[i]);
				m.style.visibility = "hidden";
			} else if( mmOpenMenus[i] == menuName ) {
				h = true;
			} else {
				c++;
			}
		}
		mmOpenMenus.length = c+1;
	}
}

function MM_menuOverMenuItem(menuName, subMenuSuffix) {
	MM_menuResetTimeout();
	MM_menuHideSubmenus(menuName);
	if( subMenuSuffix ) {
		var subMenuName = "" + menuName + "_" + subMenuSuffix;
		MM_menuShowSubMenu(subMenuName);
	}
}

function MM_menuShowSubMenu(subMenuName) {
	MM_menuResetTimeout();
	var e = document.getElementById(subMenuName);
	e.style.visibility = "inherit";
	if( !mmOpenMenus ) {
		mmOpenMenus = new Array;
	}
	mmOpenMenus[mmOpenMenus.length] = "" + subMenuName;
}

function MM_menuResetTimeout() {
	if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
	mmHideMenuTimer = null;
}

function MM_menuShowMenu(containName, menuName, xOffset, yOffset, triggerName) {
	MM_menuHideMenus();
	MM_menuResetTimeout();
	MM_menuShowMenuContainer(containName, xOffset, yOffset, triggerName);
	MM_menuShowSubMenu(menuName);
}

function MM_menuShowMenuContainer(containName, x, y, triggerName) {
	var c = document.getElementById(containName);
	var s = c.style;
	s.visibility = "inherit";

	mmOpenContainer = "" + containName;
}

function doPredefineSearchRedirect(searchWords){
	searchWords = searchWords.toLowerCase();
	var keyURLs= [];
	keyURLs['customer'] = '/common/customer_service.jsp';
	keyURLs['mommy'] = '/personalized_jewelry/family_jewelry_collection.jsp';
	keyURLs['mom'] = '/personalized_jewelry/family_jewelry_collection.jsp';
	keyURLs['mother'] = '/personalized_jewelry/family_jewelry_collection.jsp';
	keyURLs['daughter'] = '/personalized_jewelry/family_jewelry_collection.jsp';
	keyURLs['name'] = '/personalized_jewelry/family_jewelry_collection.jsp';
	keyURLs['family'] = '/personalized_jewelry/family_jewelry_collection.jsp';
	keyURLs['birthstone ring'] = '/birthstones/';
	keyURLs['ice.com blog'] = 'http://blog.ice.com';
	keyURLs['blog'] = 'http://blog.ice.com';
	keyURLs['ice blog'] = 'http://blog.ice.com';
	keyURLs['business'] = '/common/affiliate.jsp';
	keyURLs['affiliate program'] = '/common/affiliate.jsp';
	keyURLs['business partner'] = '/common/affiliate.jsp';
	keyURLs['business affiliate'] = '/common/affiliate.jsp';
	keyURLs['program'] = '/common/affiliate.jsp';
	keyURLs['partner'] = '/common/affiliate.jsp';
	keyURLs['affiliate'] = '/common/affiliate.jsp';
	keyURLs['about ice'] = '/common/about_ice_overview.jsp';
	keyURLs['ice.com'] = '/common/about_ice_overview.jsp';
	keyURLs['about us'] = '/common/about_ice_overview.jsp';
	keyURLs['about'] = '/common/about_ice_overview.jsp';
	keyURLs['blood diamond'] = '/content/conflict_diamonds_faq.jsp';
	keyURLs['conflict diamond'] = '/content/conflict_diamonds_faq.jsp';
	keyURLs['conflict'] = '/content/conflict_diamonds_faq.jsp';
	keyURLs['telephone'] = '/common/contact_us.jsp';
	keyURLs['phone'] = '/common/contact_us.jsp';
	keyURLs['email address'] = '/common/contact_us.jsp';
	keyURLs['contact us'] = '/common/contact_us.jsp';
	keyURLs['contact ice'] = '/common/contact_us.jsp';
	keyURLs['phone number'] = '/common/contact_us.jsp';
	keyURLs['telephone number'] = '/common/contact_us.jsp';
	keyURLs['email'] = '/common/contact_us.jsp';
	keyURLs['contact'] = '/common/contact_us.jsp';
	keyURLs['customer service'] = '/common/customer_service.jsp';
	keyURLs['shipping'] = '/common/customer_service.jsp';
	keyURLs['assist'] = '/common/customer_service.jsp';
	keyURLs['fq'] = '/common/customer_service.jsp';
	keyURLs['help'] = '/common/customer_service.jsp';
	keyURLs['customer'] = '/common/customer_service.jsp';
	keyURLs['representative'] = '/common/customer_service.jsp';
	keyURLs['service'] = '/common/customer_service.jsp';
	keyURLs['faq'] = '/common/customer_service.jsp';
	keyURLs['help desk'] = '/common/customer_service.jsp';
	keyURLs['f&q'] = '/common/customer_service.jsp';
	keyURLs['information'] = '/education/education_center.jsp';
	keyURLs['4cs'] = '/education/education_center.jsp';
	keyURLs['clarity'] = '/education/education_center.jsp';
	keyURLs['learning'] = '/education/education_center.jsp';
	keyURLs['4c'] = '/education/education_center.jsp';
	keyURLs['education'] = '/education/education_center.jsp';
	keyURLs['learn'] = '/education/education_center.jsp';
	keyURLs['news'] = '/common/about_ice_news.jsp ';
	keyURLs['public relation'] = '/common/about_ice_news.jsp ';
	keyURLs['privacy'] = '/common/privacy_policy.jsp';
	keyURLs['privacy policy'] = '/common/privacy_policy.jsp';
	keyURLs['ring sizer'] = '/common/ring_sizer.jsp';
	keyURLs['map'] = '/common/site_map.jsp';
	keyURLs['site map'] = '/common/site_map.jsp';
	keyURLs['wish list'] = '/customers/wish_list.jsp';
	keyURLs['name'] = '/personalized-jewelry/';
	keyURLs['deal of the day'] = '/common/search.jsp?keywords=sale';
	keyURLs['return'] = '/common/refunds.jsp';
	keyURLs['refund'] = '/common/refunds.jsp';
	keyURLs['persona'] = '/persona-charm-bracelet/';

	redirectURL = null;
	for (key in keyURLs){
		if (searchWords.indexOf(key)!=-1) {
			redirectURL = keyURLs[key];
			break;
		}
	}
	if (redirectURL != null){
		window.location = redirectURL;
		return false;
	}

}

