deleteAddress = function(message,adrId)
{
	if(confirm(message))
		YAHOO.tapeshop.common.AJAXNavigator.load('tapeForm','editAddress/deleteAddress/'+adrId+'', 'editAddress');
}

deleteCompany = function(message,compId)
{
	if(confirm(message))
		YAHOO.tapeshop.common.AJAXNavigator.load('tapeForm','editCompany/deleteCompany/'+compId+'', 'editCompany');

}

selectListElement = function(selectedElem)
{
	var fieldsetElems = document.getElementsByTagName('fieldset');
	for(i=0;i<fieldsetElems.length;i++)	{
			fieldsetElems[i].className='listElement';
		}
	selectedElem.className='selected';
}

updateCart = function(url, params, message)
{
	var quantities = document.getElementsByTagName('input');
	var found = false;
	for (i=0;i<quantities.length;i++)
	{
		if (quantities[i].name.indexOf("quantity_")!=-1)
		{
			var quantity = quantities[i].value;
			if (!validateInteger(quantity)) 
			{
				found = true;
				break;
			}
			if (parseInt(quantity)<0)
			{
				found = true;
				break;
			}
			
		}
	}
	if (!found) YAHOO.tapeshop.common.AJAXNavigator.navigate(url, params);
	else alert(message);
}

updateOrderCart = function(url,message,placeHolder)
{
	var quantities = document.getElementsByTagName('input');
	var found = false;
	for (i=0;i<quantities.length;i++)
	{
		if (quantities[i].name.indexOf("quantity_")!=-1)
		{
			var quantity = quantities[i].value;
			if (!validateInteger(quantity)) 
			{
				found = true;
				break;
			}
			if (parseInt(quantity)<0)
			{
				found = true;
				break;
			}
			
		}
	}
	if (!found) YAHOO.tapeshop.common.AJAXNavigator.load('tapeForm',url, placeHolder);
	else alert(message);
}

submitAction = function(viewData, loadData)
{
	if (loadData == null || loadData.length != 3) return;
	var canLoad = true;
	if (viewData.length != 0) 
	{
		var aMessages = validateView(viewData);
		if (aMessages.length > 0)
		{
			popupMessages(aMessages);
				canLoad = false;
		}
	}
	if (canLoad) YAHOO.tapeshop.common.AJAXNavigator.load(loadData[0],loadData[1],loadData[2]);
		
} 

validateView  = function(viewData)
{
	//var viewElems = viewData
	if (viewData.length % 2 != 0) 
	{
		alert("Numar incorect de paramatrii!");
		return;	
	}
	aMessages = new Array();
	var elem = null;
	var count  = 0;
	for(i=0;i<viewData.length;i=i+2)
	{
		elem = document.getElementsByName(viewData[i]);		
		if (elem.length>0 && !validatePositiveInteger(elem[0].value))
		{
			aMessages[count] = viewData[i+1];
			count++;	
		}
	}
	
	return aMessages;
}


popupMessages = function(aMessages)
{
	if (aMessages.length == 0) return;
	var toDisplay='';
	for(i=0;i<aMessages.length;i++)
		toDisplay+=aMessages[i]+"\n";
	alert(toDisplay);
}

expandElements = function (nrcrt, linkElemName, detailsElemName)
{
	var linkElems = document.getElementsByName(linkElemName);
	for(i=0;i<linkElems.length;i++)
	{
		YAHOO.util.Dom.addClass(linkElems[i], 'hidden');
	}
	var detailsElems = document.getElementsByName(detailsElemName);
	for(i=0;i<detailsElems.length;i++)
	{
		YAHOO.util.Dom.addClass(detailsElems[i], 'hidden');
	}
	if (nrcrt!=-1)
	{
		YAHOO.util.Dom.removeClass(document.getElementById(linkElemName+"_"+nrcrt), 'hidden');
		YAHOO.util.Dom.removeClass(document.getElementById(detailsElemName+"_"+nrcrt), 'hidden');
	}
	
	
}

searchProduct = function(str, path) {
    str = str.replace(/[\s]/g, "_");
	if ( document.getElementById("simpleSearchCriteria").value != "" )
	{
		setPath(path);
		var url = 'product/search/criteria/' + escape( str );
		YAHOO.tapeshop.common.AJAXNavigator.navigate( url, url );
		document.getElementById("simpleSearchCriteria").value = "";
	}
	else
	{
		alert( 'Trebuie completat campul de cautare!' );
	}
}

keyupSearch = function( e )
{
	if ( !e )
	{
		var e = window.event;
	}
	
	if ( e.keyCode )
	{
		code = e.keyCode;
	}
	else if ( e.which )
	{
		code = e.which;
	}
	
	if ( code == 13 )
	{
		document.getElementById('simpleSearchButton').click();
	}
}

setPath = function(pieces) {
	var container = document.getElementById('historyPieces');
	var separator = "&nbsp;&raquo;&nbsp;";
	var path = "";
	for (var i=0; i<pieces.length; i++) {
//		path += separator + pieces[i];
	}
	container.innerHTML = path;
}

ratingRevertTimeoutId = null;

changeRating = function( rating )
{
	if ( ratingRevertTimeoutId )
	{
		clearTimeout( ratingRevertTimeoutId );
	}
	
	for ( var i = 0; i < 5; i++ )
	{
		var img = document.getElementById( 'rating[' + i + ']' );
		// remember initial src
		if ( !img.oldsrc )
		{
			img.oldsrc = img.src;
		}

		if ( i <= rating )
		{
			img.src = "/resources/images/rate_on.gif";
		}
		else
		{
			img.src = "/resources/images/rate_off.gif";
		}
	}
}

revertRating = function()
{
	ratingRevertTimeoutId = setTimeout( "for ( var i = 0; i < 5; i++ ) { var img = document.getElementById( 'rating[' + i + ']' ); if ( img.oldsrc ) { img.src = img.oldsrc; } }", 500 );
}


sendOrder = function ( elem )
{
	var aPayMode = document.getElementsByName('payMode');
	var vPayMode = '';
	
	for (i=0; i<aPayMode.length; i++)
	{
		if (aPayMode[i].checked)
		{
			vPayMode = aPayMode[i].value;
			break;
		}
	}
	
	// for 'Card online', check if Transportation is payable
	if (vPayMode == 3)
	{
		
		showWarningPanel();
	}
	else
	{
		YAHOO.tapeshop.common.AJAXNavigator.navigate( 'order','order/sendOrder' );
	}

/*	if (elem.disabled == false)
	{
		YAHOO.tapeshop.common.AJAXNavigator.navigate( 'order','order/sendOrder' );
	}
	elem.disabled=true; */
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {

    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
	
  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  document.cookie = cookie_string;
}

function delete_cookie ( cookie_name )
{

  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}


/**
* Method called when a product is added to the cart
* @param productId 	- the id of the product that will le added to cart
* @param productQty - the quantity 
*/
/*addProduct = function ( productId, productQty )
{
	var products			= get_cookie('products');
	var products_new		= '';
	if (products == null)
	{
		products_new		= productId+'_'+productQty;
	}
	else
	{	
			var aProducts = new Array();
			aProducts	  = products.split(',');
			var aPrdElem  = null;
			var found	  = false; 
		
			for (var i=0; i< aProducts.length ; i++)
			{
				aPrdElem = new Array();
				aPrdElem = aProducts[i].split('_');
				if ( aPrdElem.length == 2)
				{
					if ( aPrdElem[0] == productId )
					{
						var qty		 =  parseInt(aPrdElem[1]) + productQty;
						aProducts[i] =  aPrdElem[0]+'_'+qty;//( + productQty);
						found		 = true;
					}
				}
				products_new = products_new + aProducts[i];
				if (i<aProducts.length-1)
					products_new	= products_new+',';
					
			}
			if ( found == false)
			{
				products 		= products + ','+productId+'_'+productQty;
				products_new 	= products_new + ','+productId+'_'+productQty;
			}
	}
	set_cookie ('products',products_new,'2010');
	YAHOO.tapeshop.common.AJAXNavigator.load(null,'cart/add/'+productId,'cartDiv');
}
*/

/**
* Method called to change the title and the meta tag data from the html page
* @param title 			- the new title that will be set to the page
* @param description	- the description's meta tag new value
* @param keywords		- the keywords's meta tag new value
*/
changeMetaInformation = function ( title, description, keywords )
{
	var titleElems=document.getElementsByTagName("title");
  	if ( titleElems.length > 0)
  	{
  		if ( titleElems[0])
  		{
  			titleElems[0].text 		= title;
  			titleElems[0].nodeValue = title;
  		//	titleElems[0].innerText	= title;
  		}
  	}
  	
	document.title	= title;

	if (document.getElementsByName)
	 {
  	 	 var metaArray = document.getElementsByName('description');
 		 for (var i=0; i<metaArray.length; i++) {
   				metaArray[i].content=description;
 		 }

  		var metaArray = document.getElementsByName('keywords');
  		for (var i=0; i<metaArray.length; i++) {
  			metaArray[i].content=keywords;	
   		} 
	}
}

/**
*	Method called to change the page footer text when a category/subcategory/home page is selected
*/
changeCompanyFooter	= function ( categoryName, message1, message2 )
{
	var companyDiv			= document.getElementById('companyFooterDiv');
	if ( companyDiv != 'undefined' && companyDiv != null)
	{
		companyDiv.innerHTML	= message1+'&nbsp;-&nbsp;<strong>'+message2+'&nbsp;'+categoryName+'</strong>';
	}
}


/**
 * Method called for displaying a popup message about product's transportation
 */
showTranspMessage = function ( message )
{
	document.getElementById('messageBodyDiv').innerHTML = message;
	showMessagePanel();
}

/**
 * Method called to notify the user about an online payment
 */