// common.js
// javascript functions

_objectMoving = "";
_objectMovingIF = "";

_isIE6 = false;
_isIE7 =(navigator.userAgent.indexOf('MSIE 7.0')>=0)?true:false;
_isFOX =(navigator.userAgent.indexOf('Firefox')>=0)?true:false;
_isSafari =(navigator.userAgent.indexOf('Safari')>=0)?true:false;
_isIE = (_isIE6||_isIE7)?true:false;
_callHasSpecialAction = false;

// Add to the string object method for trim(), ltrim and rtrim.
// Exemple: var test = "hello ";
//          test = test.trim();
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function updateButtonClass(amtValue)
{

}


function openShoppingBag(totAmount,MinAmount,addtoUrl,percentageOfTotal)
{
    
	if($('shopBag'))
	{
		document.body.removeChild($('shopBag'));
	}
	mainDiv = document.createElement('div');
	mainDiv.id = 'shopBag';
	mainDiv.className = 'shoppingBagContainer';
	
	overlay = document.createElement('div');
	overlay.className = 'overlayBG';
	mainDiv.appendChild(overlay);
	
	iframeEmpty = document.createElement('IFRAME');
	iframeEmpty.className = 'shoppingBagFrameInvisible';
	iframeEmpty.frameBorder = 0;
	iframeEmpty.name = 'iEmpty';
	iframeEmpty.id = 'iShoppingEmpty';
    iframeEmpty.src = '';
				
	mainDiv.appendChild(iframeEmpty);
	
	opaque = document.createElement('div');
	opaque.className = 'opaqueBG';
	mainDiv.appendChild(opaque);

	closeX = document.createElement('INPUT');
	closeX.id = 'windowClose';
	closeX.className = 'button buttonClose';
	closeX.type = 'submit';
	closeX.value = 'x';
	closeX.onclick = closeShopBag;
	opaque.appendChild(closeX);
	
	h2Header = document.createElement('h2');
	h2Header.innerHTML = translate.shoppingBag;
	opaque.appendChild(h2Header);	
		
	
	minimumOrder = document.createElement('div');
	minimumOrder.id = 'minOrder';
	minimumOrder.className = 'minimumOrder';
	opaque.appendChild(minimumOrder);
	minimumOrder.innerHTML = '';	
		
	
	orderSumBar = document.createElement('div');
	orderSumBar.id = 'orderSumBar';
	
	tab11 = document.createElement('div');
	tab11.className = 'prodTitle';
	tab11.innerHTML = translate.product;
	tab22 = document.createElement('div');
	tab22.className = 'brandTitle';
	tab22.innerHTML = translate.style;
	tab33 = document.createElement('div');
	tab33.className = 'colorTitle';
	tab33.innerHTML = translate.color;
	tab44 = document.createElement('div');
	tab44.className = 'sizeTitle';
	tab44.innerHTML = translate.size;
	
	tab55 = document.createElement('div');
	tab55.className = 'priceTitle';
	tab55.innerHTML = translate.price;
	
	tab66 = document.createElement('div');
	tab66.className = 'qtyTitle';
	tab66.innerHTML = translate.qty;
	
	tab77 = document.createElement('div');
	tab77.className = 'totalTitle';
	tab77.innerHTML = translate.total;
				
	tab88 = document.createElement('div');
	tab88.className = 'removeTitle';
	tab88.innerHTML = '';
	
	orderSumBar.appendChild(tab11);
	orderSumBar.appendChild(tab22);
	orderSumBar.appendChild(tab33);
	orderSumBar.appendChild(tab44);
	orderSumBar.appendChild(tab55);
	orderSumBar.appendChild(tab66);
	orderSumBar.appendChild(tab77);
	orderSumBar.appendChild(tab88);
	opaque.appendChild(orderSumBar);
				
	iframe = document.createElement('IFRAME');
	iframe.className = 'shoppingBagFrame';
	iframe.frameBorder = 0;
	iframe.name = 'iShopping';
	iframe.id = 'iShopping';
	iframe.src = '/sharedPages/frontEndComponents/specificComponents/b2c/shoppingCart/shoppingCartDetails.cfm';
				
	opaque.appendChild(iframe);
	
	
	  bannerHolder = document.createElement('div');
	  bannerHolder.className = 'savings';
	  bannerHolder.id = 'savings';
	  bannerHolder.style.display = 'none';
	  
	  amountHolder = document.createElement('span');
	  amountHolder.className = 'amount';
	  amountHolder.id = 'sigAmount';
	  percentageOfTotal = parseFloat(percentageOfTotal);
	  amountHolder.innerHTML = "$ " + percentageOfTotal.toFixed(2) ;
	  
	  purchaseHolder = document.createElement('span');
	  purchaseHolder.className = 'purchase';
	  purchaseHolder.innerHTML = translate.signatureCheckOutBannerText;
	  
	  signatureLink = document.createElement('div');
	  signatureLink.className = 'sigLink';
	  signatureLink.id = 'sigLink';
	  
	  bannerHolder.appendChild(amountHolder);
	  bannerHolder.appendChild(purchaseHolder);
	  bannerHolder.appendChild(signatureLink);
	  opaque.appendChild(bannerHolder);
	  
	buttonHolder = document.createElement('div');
	buttonHolder.className = 'buttonHolder clearfix';
				
	kshopping = document.createElement('BUTTON');
	kshopping.className = 'shoppingCartKeepShopping';
	kshopping.name = 'keepShopping';
	kshopping.id = 'keepShopping';
	kshopping.innerHTML = translate.keepShopping ;
	kshopping.onclick = closeShopBag;
		
	   if(totAmount >=MinAmount)
	   {
	     pclass='shoppingCartCheckout';
	   }
	   else
	   {
	     pclass='shoppingCartCheckoutGrey';
	   }
  
	pcheckOut = document.createElement('BUTTON');
	//pcheckOut.type = 'submit';
	pcheckOut.className = pclass;
	pcheckOut.name = 'checkoutB';
	pcheckOut.id = 'checkoutB';
	pcheckOut.innerHTML = translate.checkout ;
	 
	buttonHolder.appendChild(pcheckOut);
	buttonHolder.appendChild(kshopping);
	
	opaque.appendChild(buttonHolder);
	document.body.appendChild(mainDiv);		
	
	if(document.all&&(navigator.userAgent.indexOf('MSIE 7.0')<0))
	{
		mainDivIF = document.createElement('IFRAME');		
		mainDivIF.id = 'shopBagIF';
		mainDivIF.className = 'shoppingBagContainer';
		mainDivIF.style.display = 'block';	
		mainDivIF.style.border = "0";	
		mainDivIF.scrolling = "no";
		mainDivIF.frameborder = false;	
		
			
		 //<!--- TODO: write javascript function to get css for non included css. current hard coded--->
		mainDivIF.src = siteUrl + "/frontEndComponents/specificComponents/b2c/presentationLayer/blank.html";
		mainDivIF.zIndex = parseInt(100000)-1;	
		mainDivIF.style.filter = "alpha(opacity=0)";
		mainDivIF.style.position = 'absolute';
		mainDivIF.style.top = '100px';
		mainDivIF.style.left = '50%';
		mainDivIF.style.padding = '30';
		mainDivIF.frameBorder = false;
		mainDivIF.style.width = parseInt(780);		
		mainDivIF.style.height = parseInt(400)+25;
		mainDivIF.style.width = parseInt(780)+11;
		document.body.appendChild(mainDivIF);		
		
	}			
 
}




function openCoordinatesBag()
{
    
	if($('CoordinatesshopBag'))
	{
		document.body.removeChild($('CoordinatesshopBag'));
	}
	
	mainDiv = document.createElement('div');
	mainDiv.id = 'CoordinatesshopBag';
	mainDiv.className = 'shoppingBagContainer';
	
	overlay = document.createElement('div');
	overlay.className = 'overlayBG';
	mainDiv.appendChild(overlay);
	
	iframeEmpty = document.createElement('IFRAME');
	iframeEmpty.className = 'shoppingBagFrameInvisible';
	iframeEmpty.frameBorder = 0;
	iframeEmpty.name = 'iEmpty';
	iframeEmpty.id = 'iShoppingEmpty';
    iframeEmpty.src = '';
				
	mainDiv.appendChild(iframeEmpty);
	
	opaque = document.createElement('div');
	opaque.className = 'opaqueBG Coordinates';
	mainDiv.appendChild(opaque);

	closeX = document.createElement('INPUT');
	closeX.id = 'windowClose';
	closeX.className = 'button buttonClose';
	closeX.type = 'submit';
	closeX.value = 'x';
	closeX.onclick = closeCoordinatesshopBag;
	opaque.appendChild(closeX);
	
	h2Header = document.createElement('h2');
	h2Header.innerHTML = translate.coordinatesTitle;
	opaque.appendChild(h2Header);	

	minimumOrder = document.createElement('div');
	minimumOrder.id = 'selectMsg';
	minimumOrder.className = 'minimumOrder';
	opaque.appendChild(minimumOrder);
	minimumOrder.innerHTML = '';	
	
	orderSumBar = document.createElement('div');
	orderSumBar.id = 'orderSumBarCoordinates';
	
	
	tab1 = document.createElement('div');
	tab1.className = 'prodTitle';
	tab1.innerHTML = translate.product;
	
	tab2 = document.createElement('div');
	tab2.className = 'brandTitle';
	tab2.innerHTML = translate.style;
	
	tab3 = document.createElement('div');
	tab3.className = 'colorTitle';
	tab3.innerHTML = translate.color;
	
	tab4 = document.createElement('div');
	tab4.className = 'sizeTitle';
	tab4.innerHTML = translate.size;
	
	tab5 = document.createElement('div');
	tab5.className = 'qtyTitle';
	tab5.innerHTML = translate.qty;
	
					
	
				
	orderSumBar.appendChild(tab1);
	orderSumBar.appendChild(tab2);
	orderSumBar.appendChild(tab3);
	orderSumBar.appendChild(tab4);
	orderSumBar.appendChild(tab5);
	
	opaque.appendChild(orderSumBar);
				
	iframe = document.createElement('IFRAME');
	iframe.className = 'shoppingBagFrame';
	iframe.frameBorder = 0;
	iframe.name = 'iShopping';
	iframe.id = 'iShopping';
	iframe.src = '/sharedPages/frontEndComponents/specificComponents/b2c/coordinates/coordinatesDetails.cfm';
				
	opaque.appendChild(iframe);
				
	buttonHolder = document.createElement('div');
	buttonHolder.className = 'buttonHolder clearfix';
				
	addtobag = document.createElement('BUTTON');
	addtobag.className = 'shoppingCartCheckoutGrey';
	addtobag.name = 'addToBag';
	addtobag.id = 'addToBag';
	addtobag.innerHTML = 'Add to my bag'+ ' &raquo;';
	addtobag.onclick = closeCoordinatesshopBag;
		
	
	
	buttonHolder.appendChild(addtobag);
	
	opaque.appendChild(buttonHolder);
	document.body.appendChild(mainDiv);				
 
}



function closeShopBag() {
	

	//Fix for Ie7
	hiddenInput = document.createElement('INPUT');
	hiddenInput.type = 'text';
	hiddenInput.id = 'ieFix_hiddenField';
	hiddenInput.style.position = 'absolute';
	hiddenInput.style.top = '-33330px';
	hiddenInput.style.left = '-33330px';
	document.body.appendChild(hiddenInput)
		
	document.body.removeChild($('shopBag'));
	$('ieFix_hiddenField').focus();
	
	if(document.all&&(navigator.userAgent.indexOf('MSIE 7.0')<0))
	{
		document.body.removeChild($('shopBagIF'));
	}
	if($('alertbox')!=null)
		killAlertBox('alertbox');
	if($('pAlert')!=null)
		killAlertBox('pAlert'); 	
	
}


function closeCoordinatesshopBag() {
	

	//Fix for Ie7
    DWREngine._execute(_cfShoppingCartFunctions, null, 'deleteCoordinatesSession',Deletecoordinates_Result);
	hiddenInput = document.createElement('INPUT');
	hiddenInput.type = 'text';
	hiddenInput.id = 'ieFix_hiddenField';
	hiddenInput.style.position = 'absolute';
	hiddenInput.style.top = '-33330px';
	hiddenInput.style.left = '-33330px';
	document.body.appendChild(hiddenInput)
		
	document.body.removeChild($('CoordinatesshopBag'));
	$('ieFix_hiddenField').focus();
	
	if(document.all&&(navigator.userAgent.indexOf('MSIE 7.0')<0))
	{
		document.body.removeChild($('shopBagIF'));
	}
	
}


function Deletecoordinates_Result(result)
{
	//alert(result);
}
	




boxesToClose = new Array('searchBox','shoppingBagWindow','myAccountBox');

function showBoxAndSetPosition(e,id)
{   
  	for(x=0;x<boxesToClose.length;x++)
  	{
  		hideBox(boxesToClose[x]);
  	}

	if(_isSafari)
  	{
  		setLeft = e.offsetLeft
  	}
  	else
  	{
  	 	setLeft = (_isFOX)?e.offsetLeft:getLeftPos(e);
  	}
  	
  	//$(id).style.left = e.offsetLeft+'px';
  	
  	widthAdjust = (_isFOX)?1:-3;
  	leftAdjust = (_isFOX)?6:9;
  	
  	// $(id).style.left = (setLeft-leftAdjust)+'px';
  	// $(id).style.width = (e.offsetWidth-widthAdjust)+'px';
  	$(id).style.display = 'block';
  	
}

//Used for IE
function getLeftPos(e)
{
	z = 0;
  	myElement = e;
  	while(myElement.tagName != 'BODY')
  	{
  		z+=myElement.offsetLeft;
  		myElement = myElement.parentNode;
  	}
  	
  	return z;
}

function getTopPos(e)
{
	z = 0;
  	myElement = e;
  	while(myElement.tagName != 'BODY')
  	{
  	//	alert('Tag Name = ' + myElement.tagName + ' - Element Id = ' + myElement.id + ' - Element Name = '+ myElement.name + ' - Top = ' + myElement.offsetTop);
  	//	if( myElement.id != '')
  	//	{
	  		z+=myElement.offsetTop;
	//  	}	
	  	myElement = myElement.parentNode;
  	}
  	
  	return z;
}


function hideBox(id)
{   
  	$(id).style.display = 'none';
}

function getShoppingBagInfo(e,id,hascoordinates)
{
	passE = e;
	passId = id;
	_hasCoordinates = hascoordinates;
	DWREngine._execute(_cfCatLevelsLocation, null, 'getShoppingbagBoxInfo','',ShowShoppingBoxText);				
}

function ShowShoppingBoxText(result)
{
   
	showCountObj = $('shoppingBagCount');
	showCountObj.innerHTML = '('+result[0].AMOUNT+')';
	
	if (result[0].AMOUNT == 0)
		shoppingBagClick();
	else
	{
		divObj = $('ShoppingBagtext').innerHTML = result[0].SHOPPINGBAGTEXT;
		showBoxAndSetPosition(passE,passId);			
	}
	
	//if (_hasCoordinates=='TRUE')
	//{
	 //  $('coordinatesBag').innerHTML = '<a href="javascript:openCoordinatesBag();">'+translate.freeItemMenuLabel+'</a>';
		
	//}
	//else
	//{
	//	$('coordinatesBag').innerHTML ='';
		 
	//}
	
}


function changeClassName(theitem, NewclassName) {
  if((document.getElementById(theitem).className != NewclassName)) {
    document.getElementById(theitem).className = NewclassName;
  } else {
    document.getElementById(theitem).className = 'clearfix';
  }
}

function toggleOneItem(theitem) {
  if((document.getElementById(theitem).style.display == 'block') || (document.getElementById(theitem).style.display == -1))
  	{
    document.getElementById(theitem).style.display = 'none';
    document.getElementById('invisibleFrame').style.display = 'none';
    }
  else
    document.getElementById(theitem).style.display = 'block';
}


function openWindow(theURL,w,h) {
  posx=(screen.availWidth-w)/2;
  posy=(screen.availHeight-h)/2;
  window.open(theURL,'popup','toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable=yes'+',width='+w+',height='+h+',left='+posx+',top='+posy);
}

function getPageScroll(){

	var yScroll, arrayPageScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll, pageHeight, pageWidth, arrayPageSize;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function findClassProperties(style,rule)
{
	styles = document.styleSheets;
	for(x=0;x<styles.length;x++)
	{
		href = styles[x].href;
	
		if(href.indexOf(style))	
		{
			rules = (styles[x].rules)?styles[x].rules:styles[x].cssRules;
			
			for(zz=0;zz<rules.length;zz++)
			{
				temp1 = rules[zz];
				temp2 = rule;
					
				if(temp1.type!=3)
				{	
					if(temp1.selectorText.toUpperCase() == rule.toUpperCase())
					{
						return rules[zz];	
					}		
					
				}	
			}									
		}			
	}
}

_cssClass = "";

function showAlert(obj) {
	url = (!obj.url)?'':obj.url;
	message = (!obj.message)?'':obj.message;
	targetAlert = (!obj.target)?'alertbox':obj.target;	
	cssClass = (!obj.cssClass)?'alertbox':obj.cssClass;
	closeBText = (!obj.closeBText)?'X':obj.closeBText;
		
	checkObject = $(targetAlert);
	checkObjectIF = $(targetAlert+'IF');	
	
	if(checkObject!=null)
	{			
		killAlertBox();
	}
					
	_objectMoving = document.createElement('div');
	
	_objectMoving.id = targetAlert;
	_objectMoving.className = cssClass;
	_objectMoving.style.display = 'block';
	
	if(document.all&&(navigator.userAgent.indexOf('MSIE 7.0')<0))
	{
		_objectMovingIF = document.createElement('IFRAME');		
		_objectMovingIF.id = targetAlert+'IF';
		_objectMovingIF.className = cssClass;
		_objectMovingIF.style.display = 'block';	
		_objectMovingIF.style.border = "0";	
		_objectMovingIF.scrolling = "no";
		_objectMovingIF.frameborder = false;		
	}		
				
	_cssClass = '.'+cssClass;	
	
	 
	DWREngine._execute(_cfGenericFunctionsLocation, null, 'getText',escape( message ),url,closeBText,'1',targetAlert,callText_Result);
}

function showPopUp(obj) {
	
	url = (!obj.url)?'':obj.url;
	message = (!obj.message)?'':obj.message;
	targetAlert = (!obj.target)?'alertbox':obj.target;	
	cssClass = (!obj.cssClass)?'alertbox':obj.cssClass;
	closeBText = (!obj.closeBText)?'x':obj.closeBText;
	checkObject = $(targetAlert);
	checkObjectIF = $(targetAlert+'IF');	
	
	if(checkObject!=null)
	{			
		killAlertBox();
	}
					
	_objectMoving = document.createElement('div');
	
	_objectMoving.id = targetAlert;
	_objectMoving.className = cssClass;
	_objectMoving.style.display = 'block';
	
	if(document.all&&(navigator.userAgent.indexOf('MSIE 7.0')<0))
	{
		_objectMovingIF = document.createElement('IFRAME');		
		_objectMovingIF.id = targetAlert+'IF';
		_objectMovingIF.className = cssClass;
		_objectMovingIF.style.display = 'block';	
		_objectMovingIF.style.border = "0";	
		_objectMovingIF.scrolling = "no";
		_objectMovingIF.frameborder = false;		
	}		
				
	_cssClass = '.'+cssClass;	
	
	DWREngine._execute(_cfCatLevelsLocation, null, 'getProductInfo',message,closeBText,callText_Result);
}




function callText_Result(result)
{

	try{
		result = decodeURIComponent(result);
	}catch(err){
		;
	}
	
	_objectMoving.innerHTML = result;
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();
		
	var target_temp = arrayPageSize[3];
 	box = findClassProperties('style.css',_cssClass).style;
	
	boxHeight = parseInt(box.height);
	boxWidth = parseInt(box.width);
		
	targetY = ((arrayPageScroll[1])+(arrayPageSize[3]/2))-(boxHeight/2)-50;
	targetX = (arrayPageSize[2]/2)-(boxWidth/2);	
		
	_objectMoving.style.position = 'absolute';
	_objectMoving.style.top = targetY+'px';
	_objectMoving.style.left = targetX+'px';
				
	if(document.all&&(navigator.userAgent.indexOf('MSIE 7.0')<0))
	{		
		_objectMovingIF.src = siteUrl + "/frontEndComponents/specificComponents/b2c/presentationLayer/blank.html";
		_objectMovingIF.zIndex = parseInt(box.zIndex)-1;		
		_objectMovingIF.style.filter = "alpha(opacity=0)";
		_objectMovingIF.style.position = 'absolute';
		_objectMovingIF.style.top = targetY+'px';
		_objectMovingIF.style.left = targetX+'px';
		_objectMovingIF.style.padding = box.padding;
		_objectMovingIF.frameBorder = false;
		_objectMovingIF.style.width = parseInt(box.width);		
		_objectMovingIF.style.height = parseInt(box.height)+25;
		_objectMovingIF.style.width = parseInt(box.width)+11;
		document.body.appendChild(_objectMovingIF);	
	}
		
		
	document.body.appendChild(_objectMoving);
	
	
	if(_callHasSpecialAction)
	{
		eval(_callHasSpecialAction);
		_callHasSpecialAction = false;
	}			
		
	g_showQuickViewRunning = false;
}

function killAlertBox(divID,divIF)
{

	if (!divID || divID == '')
	{
		document.body.removeChild(_objectMoving);
		if(document.all&&(navigator.userAgent.indexOf('MSIE 7.0')<0))
		{
				document.body.removeChild(_objectMovingIF);			
		}	
	}
	else
	{
		DivObj = document.getElementById(divID);
		document.body.removeChild(DivObj);
     
     		
		if(document.all&&(navigator.userAgent.indexOf('MSIE 7.0')<0))
		{
			DivIFObj = document.getElementById(divID+'IF');
			document.body.removeChild(DivIFObj);
		}
	

     }
							
}					

lineCount = 0;
lastDrop = 2;
normCount = 1;


function deleteClone(o,msg)
{

	AmountOfRows = document.getElementById("lineItemsHolder").getElementsByTagName('DIV');
	
	countRows = 0;
	//lineCount--;
	for(i=0;i<AmountOfRows.length;i++)
	{
		if(AmountOfRows[i].id.indexOf('lineItem_color_') >= 0)
		{
			countRows++;
		}
	}
	
	

	if (countRows > 1)
	{
		count = parseInt(o.id.split('_')[1]);
		TopParent = document.getElementById("lineItemsHolder"); 
		
		ColorChild = document.getElementById("lineItem_color_"+count); 
		SizeChild = document.getElementById("lineItem_size_"+count); 
		QtyChild = document.getElementById("lineItem_qty_"+count); 
		
		TopParent.removeChild(ColorChild);
		TopParent.removeChild(SizeChild);
		TopParent.removeChild(QtyChild);
	}
	else
	{
		showAlert({message:msg,closeBText:'x',cssClass:'alertboxSmall'});
	}
}

function cloneItemLine(o)
{
	count = parseInt(o.id.split('_')[1]);
	idCount = lastDrop + 1;
	lineCount++
	
	//Color	
	toClone = $('lineItem_color_'+count).cloneNode(true);
	toCloneInner = toClone.innerHTML;
	
	toCloneInner = 	setDropDownObjects(toCloneInner,'colorId-',count*3,idCount,lineCount);
	
	
	
	div1 = document.createElement('DIV');
	div1.id = 'lineItem_color_'+normCount;	
	div1.className = 'selectBlockLong'; 
	div1.innerHTML = toCloneInner;
	
	
	$('lineItemsHolder').appendChild(div1);

	_listMenus.addMember('menuWrap_'+idCount);
			
	_listMenus.assignEvent("dropDownColorActions('colorId-"+lineCount+"');",idCount);
	
	menuColorWrapId = idCount;
	
	//Size
	toClone = $('lineItem_size_'+count).cloneNode(true);
	toCloneInner = toClone.innerHTML;
	idCount = parseInt(idCount)+1;
	
	
	toCloneInner = 	setDropDownObjects(toCloneInner,'sizeID-',count*3+1,idCount,lineCount);
	
	div2 = document.createElement('DIV');
	div2.id = 'lineItem_size_'+normCount;
	div2.className = 'selectBlockShort'; 
	div2.innerHTML = toCloneInner;
	$('lineItemsHolder').appendChild(div2);

	_listMenus.addMember('menuWrap_'+idCount);
	
	//Qty
	toClone = $('lineItem_qty_'+count).cloneNode(true);
	toCloneInner = toClone.innerHTML;
	idCount = parseInt(idCount)+1;
	
	toCloneInner = 	setDropDownObjects(toCloneInner,'qty-',count*3+2,idCount,lineCount);
	
	
	
	addImg = 'add_' + count;
	addImgNew = 'add_' + normCount;
	toCloneInner = toCloneInner.replace(addImg,addImgNew);
	
	minusImg = 'minus_' + count;
	minusImgNew = 'minus_' + normCount;
	toCloneInner = toCloneInner.replace(minusImg,minusImgNew);
	
	div3 = document.createElement('DIV');
	div3.id = 'lineItem_qty_'+normCount;
	div3.className = 'selectBlockMedium'; 
	div3.innerHTML = toCloneInner;
	$('lineItemsHolder').appendChild(div3);
	_listMenus.addMember('menuWrap_'+idCount);
	
	_affect = 'sizeID-'+lineCount;
	_resultKeys = new Array('SKU_ID','SIZE_DESC');
	_res = new Array();
	dropDownSetRelation(_res);
	
	setCurrentMenu($('menuSelect_'+menuColorWrapId));
	selectMenu($('colorId-'+lineCount+'_0'))
	
	normCount++;
	lastDrop +=3;
	
	 
}

function setDropDownObjects(str,valObj,c,idc,seq){
	
	str = str.replace('menuWrap_'+c,'menuWrap_'+idc);
	str = str.replace('menuSelect_'+c,'menuSelect_'+idc);
	str = str.replace('menuHeader_'+c,'menuHeader_'+idc);
	str = str.replace('menuArrow_'+c,'menuArrow_'+idc);
	str = str.replace('menuBody_'+c,'menuBody_'+idc);
	str = str.replace('add_'+c,'add_'+idc);
	
	RXstr = valObj+count;
	str = str.replace(eval('/'+RXstr+'/g'),valObj+seq);
	
	str = str.replace(/_listMenus./g,'//_listMenus.');
	
	return str;
}

_itemId = '';

// Color and size drop down relation 
//onRadioColorClick
function dropDownColorActions(idx)
{
	if($(idx))
	{
			img_value	= $(idx).value;
			
			img_value = img_value.split('|');
			img_ColorID	= img_value[0];
			img_price	= img_value[1];
		
			if(img_value!='')
			{
				relationId = $(idx).id.split('-')[1];
				
				if(img_value[2]!='' )
				 {
				  img_priceOnSale	= '| <span class="sale">'+''+img_value[2]+' '+translate.onSale+'</span>';
				 }
				 else
				 {
				 	img_priceOnSale	= '';
				 }
				
				if($("ItemPriceValueID"))
				{
					$("ItemPriceValueID").innerHTML =img_price +' '+img_priceOnSale;
				}	
				
				bypassImageZoomer = false;
				if(_itemId=='')
				{
					_itemId = img_value[3];
					bypassImageZoomer = true;
				}	
				
				getSizes(img_ColorID,_itemId);
			
			    if(!bypassImageZoomer)
			    {
					setImageZoomer();	
				}	
			}	
	
	}
	
	
}



function dropDownColorFromQuickView(idx)
{
	img_value	= $(idx).value;

	img_value = img_value.split('|');
	img_ColorID	= img_value[0];
	img_price	= img_value[1];
	
	if($(idx).value != '' && $(idx).value != '0')
	{
		relationId = $(idx).id.split('-')[1];
		
		
		if(img_value[2]!='' && img_value[2] != '0.00')
		 {
		  img_priceOnSale	= '| <span class="sale">$'+img_value[2]+' '+ $('SaleText').value  +'</span>';
		 }
		 else
		 {
		 	img_priceOnSale	= '';
		 }
		 
		 if($("newproduct").value == 'Y' && img_priceOnSale == '')
		 {
		 	isNew = '| NEW';
		 }
		 else
		 {
		 	isNew = '';
		 }
		
		
		if($("ItemPriceValueID"))
		{
			$("ItemPriceValueID").innerHTML = '$'+ img_price +' '+img_priceOnSale + ' ' + isNew;
		}
		
		_itemId = $('itemID').value;	
		
		getSizesQuickView(img_ColorID,_itemId);
		
	}
	else
	{

		$('colorId-0').value = '';
		
	}	
	
}


 function getSizesQuickView(colorId,itemId)
{
	DWREngine._execute(_cfCatLevelsLocation, null, 'getSizesByColorItem',itemId,colorId,updateSelectQuickView_result);
}


function updateSelectQuickView_result(result)
{
	isQuickView = "show";
	_resultKeys = new Array('SKU_ID','SIZE_DESC');	
	dropDownSetRelation(result);
	setColorIMageQuickView();
}

function setColorIMageQuickView(){	


 	$('productImageQV').src = '/_static/webUpload/731/'+img_value[5];

}


function showQuickView(o,direct)
{
	img = o.getElementsByTagName('IMG');
	divId = o.id.split('_')[1];
	imgExists = (img.length > 0)?true:false;
	
	divClassName = $('d_'+divId).className;
	
	setLeft = (_isFOX)?o.offsetLeft:getLeftPos(o);
	setTop = (_isFOX)?o.offsetTop:getTopPos(o);
	
	//setTop = o.offsetTop;
	if(direct.toUpperCase()=='SHOW')
	{
	
		if(imgExists){img[0].className = 'opaque';}
		
		IMG_WIDTH = img[0].width;
		IMG_HEIGHT = img[0].height;
		//170
		
		
		BTN_WIDTH = $('q_dummy').width;
		BTN_HEIGHT = $('q_dummy').height;
		
		
		
		adjustLeft = Math.ceil((IMG_WIDTH/2)-(BTN_WIDTH/2));
		adjustTop = Math.ceil((IMG_WIDTH/2));
		
		$('d_'+divId).className = divClassName.replace('displayNone','displayBlock');
	}
	else
	{
		if(imgExists){img[0].className = '';}
		$('d_'+divId).className = divClassName.replace('displayBlock','displayNone');
	}
}


  	
  	/*
  	
  	widthAdjust = (_isFOX)?1:-3;
  	leftAdjust = (_isFOX)?6:9;
  	
  	$(id).style.left = (setLeft-leftAdjust)+'px';
  	$(id).style.width = (e.offsetWidth-widthAdjust)+'px';
  	$(id).style.display = 'block';

*/
	
function _isInteger(val) {
			var digits="1234567890";
			for (var i=0; i < val.length; i++) {
				if (digits.indexOf(val.charAt(i))==-1) { return false; }
				}
			return true;
		}
	
	
	
function init()
{
	DWREngine._errorHandler =  errorHandler;
}

init();