Event.observe(window,'load',pageLoaded,false);

var btns = new Array();
var keywordFocusFound = "N";
function pageLoaded(e)
{
	if ($('emailAddress')) {
		$('emailAddress').value ='For Special Offers -- Enter email address';
		Event.observe('emailAddress','focus',inputEvent,false);
		Event.observe('emailAddress','blur',inputEvent,false);		
	}
	if ($('keyword')) {
		if (keywordFocusFound == "N")
			$('keyword').value='Enter item # or keyword';	
		Event.observe('keyword','focus',inputEvent,false);
		Event.observe('keyword','blur',inputEvent,false);
	}		
}
function inputEvent(e) {
	var el = Event.element(e);
	el.removeClassName('txtError');
	el.addClassName('txt');
	initElement(el,e);
}
function initElement(el,e){
	if(el.id =='emailAddress')
			initMessage(el,'For Special Offers -- Enter email address',e);
	else if(el.id =='keyword')
		initMessage(el, 'Enter item # or keyword',e);
}
function initMessage(el,mess,e){
	if(el.value == mess || (e && e.type=='focus') || keywordFocusFound == "Y")
		el.value = '';
	else if(el.value == '')
		el.value = mess;
}
/*
function menuClickEvent(e) {
	$('navSub').addClassName('redBg');	
}
*/
function setActiveMenu(id,className)
{
 	// We do not need however IFS html pages still have this script				
}

function openPopupImage(evt){
	var link = Event.element(evt);

	alert (link.tagName);
	return false;
}

//attributes section
function Attribute(prdKey, atrId,atrDsc,atrLink,atrLinkDsc, atrDepUpn,atrDepMod,options,dependents ){
	this.prdKey = prdKey;
	this.atrId = atrId;
	this.atrDsc = atrDsc;
	this.atrLink = atrLink;
	this.atrLinkDsc = atrLinkDsc;
	this.atrDepUpn = atrDepUpn;
	this.atrDepMod = atrDepMod;
	this.options = options;
	this.dependents = dependents;
	
}

function MyOption(prdKey, atrId,atrValId,atrValDsc, appItmNum, appItmNumVal,incOrdNot){
	this.prdKey = prdKey;
	this.atrId = atrId;
	this.atrValId = atrValId;
	this.atrValDsc = atrValDsc;
	this.appItmNum=appItmNum;
	this.appItmNumVal = appItmNumVal;
	this.incOrdNot = incOrdNot;
}
function DependentOption(prdKey, depAtrId, depAtrValId,ctlAtrId,ctlAtrValId)
{
	this.prdKey=prdKey;
	this.depAtrId=depAtrId;
	this.depAtrValId = depAtrValId;
	this.ctlAtrId = ctlAtrId;
	this.ctlAtrValId = ctlAtrValId;
}

new MyOption();
new Attribute();
new DependentOption();

function getAttributesOptions(attributes,attrName)
{
	var attr = getAttribute(attributes, attrName);
	if(attr != null)		  
		return attr.options;
	return null;
	
	
}

function getAttribute(attributes, attrName)
{
	attrName = attrName.toUpperCase();
	for(var i = 0; i<attributes.length; i++)
	{	
		var attr = attributes[i];
		//alert(attr.atrDsc);
		if(attr!= null && attr.atrDsc.toUpperCase() == attrName){
			  
			return attr;
		}
	}
	return null;
}

function setSelectOptions(options, field)
{
	var fieldDesc = field;
	
	if(field.substring(0,2)=='b_')
	fieldDesc = field.substring(2);
	
	if(options==null || $(field) == null  )
		return;
		
	// 05/06/2008 ksa/rwp
	// Livevalidation 1.3 includes support for disable and enable (see livevalidation.js)
	// Following if/else added to support attribute dependency where selection of certain 
	//  controlling attribute values would exclude all dependent attribute values.
	if(options=="") {
		$(field).disable();
		$(field).hide();
		var f = new LiveValidation($(field),{onlyOnSubmit: true});
		f.disable(); 
		return;
	}
	else {
		$(field).enable();
		$(field).show();
		var f = new LiveValidation($(field),{onlyOnSubmit: true});
		f.enable();
		f.add(Validate.Presence,{failureMessage:"Select "+element});
	}
		
	$(field).innerHTML="";
	$(field).options.add(new Option("--- "+fieldDesc+" ---",''));
	for(var i = 0; i < options.length; i++ )
	{
	var opt = options[i];
	
	$(field).options.add(new Option(opt.atrValDsc,opt.atrValId));
	
	}	
}

/**
 * not used
 */
function initAttributes()
{
var colors = getAttributesOptions(attributes,'color');
var sizes = getAttributesOptions (attributes,'size');
var strands = getAttributesOptions(attributes,'strand');
setSelectOptions(colors,'color');
setSelectOptions(sizes,'size');
setSelectOptions(strands,'strand');
}

/**
 * Finds the options for the targetAttrName select button
 * based on the value of the cnotrolling select crtAttrId
 */
function getAttributesOptionsFor(targetAttrName,crtAttrId)
{
	//alert("controling "+crtAttrId+": " +$F(crtAttrId));
	if($F(crtAttrId)=='')
		return;
	var driver = parseInt($F(crtAttrId));
	//alert('hi');
	var attr = getAttribute(attributes,targetAttrName);
	//alert(driver + ", "+attr.atrDepMod);
	//alert(attr.atrDsc);
	//alert("ctlId "+driver+", attr depen mod "+attr.atrDepMod+ ", attr depen upon "+attr.atrDepUpn);
	var atrDepMod = attr.atrDepMod;
	if(atrDepMod ==null || atrDepMod =="")
		return;
	
	
	var options = attr.options;
	var dependents = attr.dependents;
	var newOptions = new Array();
	for (var i =0; i < options.length; i++)
	{
		var opt = options[i]
		
		
		var found = isFound(opt,dependents,driver );
		
		if(atrDepMod =='I' && found)
		{
			newOptions[newOptions.length] =opt;
			 
		}		
		else if(atrDepMod =='E' && !found)
		{	//alert("one excluded");
			newOptions[newOptions.length] =opt;
		}
		
			
			
			
	}
		
	setSelectOptions(newOptions,targetAttrName);
}

function getBonusAttributesOptionsFor( targetAttrName,crtAttrId)
{
	//alert("controling "+crtAttrId+": " +$F(crtAttrId));
	if($F(crtAttrId)=='')
		return;
	var driver = parseInt($F(crtAttrId));
	//alert('hi');
	var attr = getAttribute(bonAttributes,targetAttrName);
	//alert(driver + ", "+attr.atrDepMod);
	//alert(attr.atrDsc);
	//alert("ctlId "+driver+", attr depen mod "+attr.atrDepMod+ ", attr depen upon "+attr.atrDepUpn);
	var atrDepMod = attr.atrDepMod;
	if(atrDepMod ==null || atrDepMod =="")
		return;
	
	
	var options = attr.options;
	var dependents = attr.dependents;
	var newOptions = new Array();
	for (var i =0; i < options.length; i++)
	{
		var opt = options[i]
		
		
		var found = isFound(opt,dependents,driver );
		
		if(atrDepMod =='I' && found)
		{
			newOptions[newOptions.length] =opt;
			 
		}		
		else if(atrDepMod =='E' && !found)
		{	//alert("one excluded");
			newOptions[newOptions.length] =opt;
		}
		
			
			
			
	}
		
	
	setSelectOptions(newOptions,targetAttrName);
}

function isFound(opt,dependents,driver )
{
	//alert(dependents.length);
	var prdKey = opt.prdKey;
	var atrId = opt.atrId;
	var atrValId = opt.atrValId;
	for(var j = 0; j < dependents.length; j++)
		{
			var dep = dependents[j];
			if (dep.prdKey == prdKey && dep.depAtrId == atrId && dep.depAtrValId == atrValId && dep.ctlAtrValId == driver )
						
					return true;
				 
		}
		return false;
}

function ajaxCall(url, params,callback)
{
	new Ajax.Request( url, { method: 'post', parameters: params, onSuccess: callback });
}

function alertMessage(){
alert('Your requested has been submitted');
}

function check(el, mess)
{
	// trim out blanks
	var inputValue = trim($(el).value);
	var messValue = trim(mess);
	if(inputValue == '' || inputValue == messValue)
	{
		alert(mess);
		$(el).focus();
		return false;
	}	
	return true;
}
function trim(value)
{
	if (isWhitespace(value))
		return "";
	
	var startPos;
	var endPos;
	
	for (startPos = 0; whitespace.indexOf(value.charAt(startPos)) != -1; startPos++);
	for (endPos = value.length - 1; whitespace.indexOf(value.charAt(endPos)) != -1; endPos--);

	return value.substring(startPos, endPos + 1);
}
function isWhitespace(value)
{
	// Is value empty?
	if (isEmpty(value))
		return true;

	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.

	for (var i = 0; i < value.length; i++)
	{
		// Check that current character isn't whitespace.
		var c = value.charAt(i);

		if (whitespace.indexOf(c) == -1)
			return false;
	}

	// All characters are whitespace.
	return true;
}

function resetCheckboxes()
{
	 $$('#clientRequestForm input.check').each(function (box){
	 											if (box.checked == false)
	 												box.value = "";
	 										//		alert(box.value);
	 											});
	return true;
}


function getAttributeById(atrs, id){
	if(!atrs || id) 
	return null;
	
	for(var i = 0; i < atrs.length; i++){
		var atr = atrs[i];
		if(atr.atrId ==id)
			return atr;
	}
	return null;
}


function getOptionByAtrValueId(opts, id){
	
	if(!opts || !id) 
	return null;
	
	for(var i = 0; i <opts.length; i++){
		var opt = opts[i];
		if(opt.atrValId ==id)
			return opt;
	}
	return null;
	
}


	    
function getTime(){
var date = new Date();
return  date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
}
function storeInSession(name,value,fn){
		var url = '/catalog/multiTasker.do';
		params={action:'storeInSession', name:name, value:value};
	    ajaxCall(url,params,fn)
		}
function setShoppingCartLink(link){
	//alert('here');
	var shop = $('shoppingCart');
	shop.href=link;
	shop = $('viewShoppingCart');
	shop.href=link;
	var currentUrl = window.location.href;
	//alert(currentUrl);
	if(currentUrl.indexOf("action=precedent") == -1)
			storeInSession("returnTo",currentUrl,function(){});
	//alert(shop.href);
	
	
}

function sendEmail(subject, message){
	//alert(subject);
	var url = '/catalog/clientRequest.do';
	params={requestType:'sendShoppingCartError', subject:subject, message:message};
	ajaxCall(url,params,function(transport){});
}

function getWindowSize(){
		var myWidth = 0, myHeight = 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;
	  }
	   var dim = {width:myWidth,height:myHeight};
	   return dim;
	}
	
	function show(el){
	var dim = getWindowSize();
    	var s_left = parseInt(dim.width/2);
     	var s_top = parseInt(dim.height/2 );
     	alert(s_left, s_top);
     	var element =  $(el);
     	element.setStyle({left: s_left, top:s_top} );
        element.show(); 
}

function hide(el){
	var element =  $(el);
     	
        element.hide(); 
}

function handleKeyEvent(e){
	var code;
	var targ;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) 
		targ = targ.parentNode;
		
}
//
//function findCtlAttributeIndex(attributes, depUpon){
//	var l = attributes.length;
//	for(var i = 0 ; i < l ; i++){
//		if(attributes[i].depUpn == depUpon)
//		return i;
//	}
//	
//	return -1;
//}

/**
 * retun the controlling attribute index
 * return -1 if not found 
 */
function findCtlAttributeIndex(attributes, depUpon){
	var l = attributes.length;
	for(var i = 0 ; i < l ; i++){
		if(attributes[i].atrId == depUpon)
		return i;
	}
	
	return -1;
}


// Finds the controlling attribute desc, which is used as the controlling 
// // attribute select  Dom Id.
function findCtlAttributeDesc(attributes, depUpon){
	var l = attributes.length;
	for(var i = 0 ; i < l ; i++){
		if(attributes[i].atrId == depUpon)
		return attributes[i].atrDsc;
	}
	
	return "";
}

// KSA/SLD 08/19/2010 Add links to share  with facebook, twitter
var shareUrl = "";
var shareTitle = "";
function faceBookShare(){
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(shareUrl),'facebook','width=550,height=450').focus();
}
function twitterShare() {
    window.open('http://twitter.com?status=Check out '+shareTitle+': ' + encodeURIComponent(shareUrl));
}
function stumbleUponShare(){
	window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(shareUrl)+'&title='+shareTitle);
}
function diggShare() {
	window.open('http://digg.com/submit?phase=2&url='+encodeURIComponent(shareUrl)+'&title='+shareTitle);	
}
function deliciousShare() {
	window.open('http://del.icio.us/post?url='+encodeURIComponent(shareUrl)+'&title='+shareTitle);	
}

function openPage(url,width, height) {
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable=yes,scrollbars=yes,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open("", "Window", windowFeatures);
    myWindow.location.href = url;
    return myWindow;
}

/*  combined multiple js into 1 for faster page loading */

// KSA/SLD 08/24/2010 Add 3 recently viewed items to left navigation.  
// KSA/SLD 11/04/2010 Display 5 recently viewed items in new tab on product detail
function loadCurrentItem(itemName, itemImagePath, itemPath) {

	// Do not add cookie if NO image
	if (itemImagePath != "") {
		// do not load item if already in cookie
		if (document.cookie.length > 0 && document.cookie.indexOf(itemPath) > -1) 
			return;

		if (document.cookie.length == 0)
			setCookie(1,itemName, itemImagePath, itemPath);
		else if (document.cookie.indexOf(itemPath) == -1) {
			// Only want to save the last 5 items viewed
			if (document.cookie.indexOf("bandshoppeRecentImage1") == -1)
				setCookie(1,itemName, itemImagePath, itemPath);
			else if (document.cookie.indexOf("bandshoppeRecentImage2") == -1) 
				setCookie(2,itemName, itemImagePath, itemPath);
			else if (document.cookie.indexOf("bandshoppeRecentImage3") == -1) 
				setCookie(3,itemName, itemImagePath, itemPath);
			else if (document.cookie.indexOf("bandshoppeRecentImage4") == -1) 
				setCookie(4,itemName, itemImagePath, itemPath);
			else if (document.cookie.indexOf("bandshoppeRecentImage5") == -1) 
				setCookie(5,itemName, itemImagePath, itemPath);
			else {
				// remove 1
				removeCookie("bandshoppeRecentImage1");
				removeCookie("bandshoppeRecentName1");
				removeCookie("bandshoppeRecentPath1");
				
				// bump up each item and put this item at bottom
				var a_all_cookies = document.cookie.split( ';' );
				
				// Now remove 2 thru 5
				removeCookie("bandshoppeRecentImage2");
				removeCookie("bandshoppeRecentName2");
				removeCookie("bandshoppeRecentPath2");
				removeCookie("bandshoppeRecentImage3");
				removeCookie("bandshoppeRecentName3");
				removeCookie("bandshoppeRecentPath3");
				removeCookie("bandshoppeRecentImage4");
				removeCookie("bandshoppeRecentName4");
				removeCookie("bandshoppeRecentPath4");
				removeCookie("bandshoppeRecentImage5");
				removeCookie("bandshoppeRecentName5");
				removeCookie("bandshoppeRecentPath5");
				
				var a_temp_cookie = '';
				var cookie_name = '';
				var cookie_value = '';
				var b_cookie_found = false; // set boolean t/f default f
			
				for ( i = 0; i < a_all_cookies.length; i++ ) {
					// now we'll split apart each name=value pair
					a_temp_cookie = a_all_cookies[i].split( '=' );
					cookie_name = trim(a_temp_cookie[0]);
					cookie_value = trim(unescape(a_temp_cookie[1]));
  					
					// Move 2nd image to 1
					if (cookie_name == "bandshoppeRecentImage2")
						setCookie(1,null,cookie_value,null);
					if (cookie_name == "bandshoppeRecentName2")
						setCookie(1,cookie_value,null,null);
					if (cookie_name == "bandshoppeRecentPath2")
						setCookie(1,null,null,cookie_value);
						
					// Move 3rd image to 2
					if (cookie_name == "bandshoppeRecentImage3")
						setCookie(2,null,cookie_value,null);
					if (cookie_name == "bandshoppeRecentName3")
						setCookie(2,cookie_value,null,null);
					if (cookie_name == "bandshoppeRecentPath3")
						setCookie(2,null,null,cookie_value);
				
					// Move 4th image to 3
					if (cookie_name == "bandshoppeRecentImage4")
						setCookie(3,null,cookie_value,null);
					if (cookie_name == "bandshoppeRecentName4")
						setCookie(3,cookie_value,null,null);
					if (cookie_name == "bandshoppeRecentPath4")
						setCookie(3,null,null,cookie_value);
						
					// Move 5th image to 4
					if (cookie_name == "bandshoppeRecentImage5")
						setCookie(4,null,cookie_value,null);
					if (cookie_name == "bandshoppeRecentName5")
						setCookie(4,cookie_value,null,null);
					if (cookie_name == "bandshoppeRecentPath5")
						setCookie(4,null,null,cookie_value);
				}
			
				setCookie(5,itemName, itemImagePath, itemPath);			
			}
		} // item image found
	}
}
	
function setCookie(imageNbr,itemName, itemImagePath, itemPath, expiredays)
{
	var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);

	// save cookie for item displayed
	if (itemImagePath !=  null)
		document.cookie='bandshoppeRecentImage'+imageNbr+'='+escape(itemImagePath)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	if (itemName != null)
		document.cookie='bandshoppeRecentName'+imageNbr+'='+escape(itemName)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	if (itemPath != null)
		document.cookie='bandshoppeRecentPath'+imageNbr+'='+escape(itemPath)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
			
function removeCookie(c_name)
{
	document.cookie = c_name + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function loadRecentViewDiv() {
	var data1 = "<table id='recentViewTable'><tr><td height='3px' colspan='2'>&nbsp;</td></tr>";
 	var data3 = "<tr><td colspan='2'><h3 class='blueBold'>Recently Viewed Items </h3></td></tr>";
 
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var recentViewItemsImage = new Array(5);
	var recentViewItemsName = new Array(5); 
	var recentViewItemsPath = new Array(5);
	var startDescRow = 0;
			
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = trim(a_temp_cookie[0]);
		cookie_value = trim(unescape(a_temp_cookie[1]));
 	
		if (cookie_name == "bandshoppeRecentImage1")  {
			recentViewItemsImage[0] = cookie_value;	
			if (startDescRow < 1)
				startDescRow = 1;
		} else if (cookie_name == "bandshoppeRecentName1") 
			recentViewItemsName[0] = cookie_value;
		else if (cookie_name == "bandshoppeRecentPath1")
			recentViewItemsPath[0] = cookie_value;
		else if (cookie_name == "bandshoppeRecentImage2")  {
			recentViewItemsImage[1] = cookie_value;	
			if (startDescRow < 2)
				startDescRow = 2;
		} else if (cookie_name == "bandshoppeRecentName2")
			recentViewItemsName[1] = cookie_value;
		else if (cookie_name == "bandshoppeRecentPath2")
			recentViewItemsPath[1] = cookie_value;
		else if (cookie_name == "bandshoppeRecentImage3")  {
			recentViewItemsImage[2] = cookie_value;	
			if (startDescRow < 3)
				startDescRow = 3;
		} else if (cookie_name == "bandshoppeRecentName3")
			recentViewItemsName[2] = cookie_value;
		else if (cookie_name == "bandshoppeRecentPath3")
			recentViewItemsPath[2] = cookie_value;
		else if (cookie_name == "bandshoppeRecentImage4")  {
			recentViewItemsImage[3] = cookie_value;	
			if (startDescRow < 4)
				startDescRow = 4;
		} else if (cookie_name == "bandshoppeRecentName4")
			recentViewItemsName[3] = cookie_value;
		else if (cookie_name == "bandshoppeRecentPath4")
			recentViewItemsPath[3] = cookie_value;
		else if (cookie_name == "bandshoppeRecentImage5")  {
			recentViewItemsImage[4] = cookie_value;	
			if (startDescRow < 5)
				startDescRow = 5;
		} else if (cookie_name == "bandshoppeRecentName5")
			recentViewItemsName[4] = cookie_value;
		else if (cookie_name == "bandshoppeRecentPath5")
			recentViewItemsPath[4] = cookie_value;
	}
	if (startDescRow == 5) {
		// all 5 items found need to display 3 thru 5
		startDescRow = 3;  
	} else if (startDescRow == 4) {
		// 4 items found need to display 2 thru 4
		startDescRow = 2;  
	} else {
		// 1 to 3 items found need to display all 3
		startDescRow = 1;
	}
	startDescRow = startDescRow - 1;
 
	var data4 = "";	// recent view tab
	var data5 = "";	// recent view description tab
	var rowData = "";
	for ( i = 0; i < 5; i++ ) {
		if (recentViewItemsImage[i] != undefined) {
			rowData = "<tr><td>"+
			    "<a class='blue' style='text-align: left;  margin-left:0px; padding-left: 0px;' href='productDetail.do?p="+recentViewItemsPath[i]+"'>"+
				"<img src='"+recentViewItemsImage[i]+"' width='50' height='50'></a></td>"+
 				"<td><a class='blue' style='text-align: left;  margin-left:0px; padding-left: 0px;' href='productDetail.do?p="+recentViewItemsPath[i]+"'>"+recentViewItemsName[i]+"</a></td></tr>";
 			if (i >= startDescRow) {
 				data5 += rowData;
 			}
 			data4 += rowData;
		}
	}
	var data6 = "</table>";
 
	document.getElementById('recentView').innerHTML = data1+data3+data4+data6;
}		

/*  Image js */

var imageWindow;

function openPopup(url,width, height) {  

	// KSA/SLD 06/06/2011 Check to see if URL is an image
	var urlLowerCase = url.toLowerCase();
	if (urlLowerCase.indexOf(".jpg") == -1 && urlLowerCase.indexOf(".gif") == -1) {
		openNonImagePopup(url,width,height);
		return;
	}

    // default 450/450 width/height when no value sent
    if (width == '0' || width == '')
    	width = 450;
    if (height == '0' || height == '')
    	height = 450;
    	 
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));

    // KSA/SLD 04/08/2008 Create window to display image so the image will not be resized.  Also add Close link.
	var windowFeatures = "width=" + width + ",height=" + height + ",status,galleryimg=no,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
 
    imageWindow = window.open("", "imageWindow", windowFeatures);
    imageWindow.document.write("<HTML>");
    imageWindow.document.write("<HEAD>");
    imageWindow.document.write("<link type='text/css' rel='stylesheet' media='screen' href='/catalog/css/style.css' />");
    imageWindow.document.write("</HEAD>");
	imageWindow.document.write("<BODY>");
	imageWindow.document.write("<div class='blank'> </div>");
	imageWindow.document.write("<a href='javascript:window.close();'><div id='imgCloseBtn'>Close <img src='/pages/images/close_button.gif' border='0' onclick='window.close();'></div></a>");
 	imageWindow.document.write("<img src='"+url+"' galleryimg='no'>");
	imageWindow.document.write("</BODY>");
    imageWindow.document.write("</HTML>");	
    
    if( imageWindow)
    	imageWindow.focus();
}
function openNonImagePopup(url,width, height) {   
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    
    // default 450/450 width/height when no value sent
    if (width == '0' || width == '')
    	width = 450;
    if (height == '0' || height == '')
    	height = 450;

	var windowFeatures = "width=" + width + ",height=" + height + ",status,galleryimg=no,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    imageWindow = window.open(url, "imageWindow", windowFeatures);    
    if( imageWindow)
    	imageWindow.focus();
}
	
	/**
	 * src is the thumbnail for available colors
	 */
	function swapImage2(src,title ){
		var largeSrc = "";
		var index = src.lastIndexOf('.');
		// add '2' after base thumbnail
		var newSrc = src.substring(0, index) + '2' + src.substring(index, src.length);
		// See if main image exist
		ajaxCall("/catalog/multiTasker.do",{action:'isFileExisting',file:newSrc},swapCallBack2);
		
		function swapCallBack2(transport){			
			var res = transport.responseText;
			res = res.strip();
			if(res.indexOf("error") != -1)
				return;
			if(res == "true"){					
				// See if larger image exists add '_largerimage'
				largeSrc = src.substring(0, index) + '_largerimage' + src.substring(index, src.length);
				ajaxCall("/catalog/multiTasker.do",{action:'isFileExisting',file:largeSrc},swapCallBack3);
			}
		}
		function swapCallBack3(transport){			
			var res = transport.responseText;
			res = res.strip();
			if(res.indexOf("error") != -1)
				return;
			// apply new changes to our zoom 
         	//  new settings passed in the last parameter to update() function
         	//  will only extend existing settings
			if(res == "true"){				
		 		MagicZoomPlus.update('Zoomer', largeSrc, newSrc, 'show-title: false');  
			} else {
				// large image not found so set larger image to main image
         		MagicZoomPlus.update('Zoomer', newSrc, newSrc, 'show-title: false');
			}
		}		
	}	
