/*
*/

function textCounter(field,countfield, maxlimit) 
{

	
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
	countfield.value = maxlimit - field.value.length;


}



function addNewVariation(item_id)
{
	var variations_object = document.getElementById(item_id + "#variations");
	
	if(variations_object.value != "")
	{
		variations_object.value += "|";
	}
	
	variations_object.value += ":,";
}

/*
*/
function addNewVariationOption(item_id, variation_nr)
{
	var variations_object = document.getElementById(item_id + "#variations");
	
	//split into the different variation names
	var variations = variations_object.value.split("|");
	
	//split into the different variation names and values
	for(var v = 0; v < variations.length; v++)
	{
		variations[v] = variations[v].split(":");
		
		//add new empty variation value
		if(v == variation_nr)
		{
			variations[v][1] += "/,";
		}
	}
	
	//reconstruct variations_object
	var tmp_variations = new Array(variations.length);
	
	//put the different variations into a string
	var new_variations = "";	
	
	//combine the different variation names and values
	for(var v = 0; v < variations.length; v++)
	{
		if(v > 0)
		{
			new_variations += "|";
		}
		
		new_variations += variations[v][0] + ":" + variations[v][1];
	}
	
	//put the result in the variations_object
	variations_object.value = new_variations;
}

/*
*/
function gotoURL(url)
{
	document.location.href = url;
}

/*
*/
function updateVariationOption(item_id, variation_nr, variation_option_nr)
{
	var variations_object = document.getElementById(item_id + "#variations");
	
	//split into the different variation names
	var variations = variations_object.value.split("|");
	
	//split into the different variation names and values
	for(var v = 0; v < variations.length; v++)
	{
		variations[v] = variations[v].split(":");
		
		//add new empty variation value
		if(v == variation_nr)
		{
			//set new name
			variations[v][0] = document.getElementById(variation_nr + "_name").value;
			
			if(variation_option_nr >= 0)
			{			
				//split into variation options
				variations[v][1] = variations[v][1].split("/");			
				
				//set new value
				variations[v][1][variation_option_nr] = document.getElementById(variation_nr + "_" + variation_option_nr + "_name").value + "," + document.getElementById(variation_nr + "_" + variation_option_nr + "_price").value;
				
				//combine variation options			
				var tmp_variationoptions = "";
				
				for(var vo = 0; vo < variations[v][1].length; vo++)
				{
					if(vo > 0)
					{
						tmp_variationoptions += "/";
					}
					
					tmp_variationoptions += variations[v][1][vo];
				}
				
				//store the changed made
				variations[v][1] = tmp_variationoptions;
			}
		}
	}
	
	//reconstruct variations_object
	var tmp_variations = new Array(variations.length);
	
	//put the different variations into a string
	var new_variations = "";	
	
	//combine the different variation names and values
	for(var v = 0; v < variations.length; v++)
	{
		if(v > 0)
		{
			new_variations += "|";
		}
		
		new_variations += variations[v][0] + ":" + variations[v][1];
	}
	
	//put the result in the variations_object
	variations_object.value = new_variations;
}

/*
*/
function removeVariation(item_id, variation_nr)
{
	var variations_object = document.getElementById(item_id + "#variations");
	
	//split into the different variation names
	var variations = variations_object.value.split("|");
	
	//reconstruct variations_object
	var tmp_variations = new Array(variations.length - 1);
	
	//put the different remaining variations into a string
	var new_variations = "";	
	
	var item_nr = 0;
	
	for(var v = 0; v < variations.length; v++)
	{		
		if(v != variation_nr)
		{
			if(item_nr > 0)
			{
				new_variations += "|";
			}		
			
			new_variations += variations[v];
			
			item_nr++;
		}
	}
	
	//put the result in the variations_object
	variations_object.value = new_variations;
}

/*
*/
function removeVariationOption(item_id, variation_nr, variation_option_nr)
{
	var variations_object = document.getElementById(item_id + "#variations");
	
	//split into the different variation names
	var variations = variations_object.value.split("|");
	
	//reconstruct variations_object
	var tmp_variations = new Array(variations.length - 1);
	
	//put the different remaining variations into a string
	var new_variations = "";	
	
	for(var v = 0; v < variations.length; v++)
	{		
		if(v > 0)
		{
			new_variations += "|";
		}	

		if(v != variation_nr)
		{
		
			new_variations += variations[v];
		}
		else
		{
			var tmp_options       = variations[v].split(":");			
			
			if(tmp_options.length > 1)
			{
				var tmp_options_array = tmp_options[1].split("/");
				
				new_variations += tmp_options[0] + ":";
				
				var item_nr = 0;
				
				for(var o = 0; o < tmp_options_array.length; o++)
				{					
					if(o != variation_option_nr)
					{
						if(item_nr > 0)
						{
							new_variations += "/";
						}
						
						new_variations += tmp_options_array[o];
						
						item_nr++;
					}
				}
			}
		}
	}
	
	//put the result in the variations_object
	variations_object.value = new_variations;
}

/*
*/
function submitForm(object_value, action_value, item_id)
{
	document.getElementById('object').value  = object_value;
	document.getElementById('action').value  = action_value;
	document.getElementById('item_id').value = item_id;

	document.getElementById('global_form').submit();
}

/*
*/
function submitCMSForm(object_value, action_value, item_id)
{
	document.getElementById('object').value  = object_value;
	document.getElementById('action').value  = action_value;
	document.getElementById('item_id').value = item_id;

	document.getElementById('edit').submit();
}

/*
	POP-UP
*/

function popUp(title, sUrl,  nWidth, nHeight)
//function popUp(title, sUrl, nWidth=850, nHeight=1100)
{
	nWidth= nWidth===undefined ? 1100 : nWidth;
	nHeight= nHeight===undefined ? 850 : nHeight;
	window.open(sUrl, "", "height="+nHeight+"px, left=" + ((screen.width  - nWidth) / 2) + "px, location=false, overflow=visible, resizable=no scrollbars=yes, status=no, toolbar=no, top=" + ((screen.height - nHeight) / 2) + "px, width="+nWidth+"px;");
}

/*
	POP-UP LAYER
*/

/*
*/
function hidePopupLayer()
{
	document.getElementById("popup_layer").style.visibility = "hidden";
}

/*
*/
function showPopupLayer(title, url)
{
	document.getElementById("popup_layer").style.left       = ((screen.width  - 500) / 2) + "px";
	document.getElementById("popup_layer").style.top        = ((screen.height - 400) / 2) - 100 + "px";

	document.getElementById("popup_layer").style.visibility = "visible";
	document.getElementById("popup_layer_title").innerHTML  = title;
	document.getElementById("popup_layer_iframe").src       = url;
}

/*
	SHOPPING CARD
*/

/*
*/
function deleteArticleFromShoppingCard(a_id)
{
	document.getElementById("object").value  = "shoppingcard";
	document.getElementById("action").value  = "delete";
	document.getElementById("item_id").value = a_id;
	document.getElementById("global_form").submit();
}

/*
*/
function updateShoppingCard()
{
	document.getElementById("object").value  = "shoppingcard";
	document.getElementById("action").value  = "update";
	document.getElementById("global_form").submit();	
}
function checkUserDet()
{
	document.getElementById("object").value  = "shoppingcard";
	document.getElementById("action").value  = "check";
	document.getElementById("global_form").submit();	
}
function undoUserDet()
{
	document.getElementById("object").value  = "shoppingcard";
	document.getElementById("action").value  = "check";
	document.getElementById("firstname").value  = ""; 
	document.getElementById("middlename").value  = ""; 
	document.getElementById("lastname").value  = ""; 
	document.getElementById("street").value  = ""; 
	document.getElementById("housenumber").value  = ""; 
	document.getElementById("postal").value  = ""; 
	document.getElementById("city").value  = ""; 
	document.getElementById("telephone").value  = ""; 
	document.getElementById("email").value  = ""; 
	document.getElementById("accountnumber").value  = ""; 
	
	<!--document.getElementById("global_form").submit();		-->
}
/*
	popup
*/
function customPopup(URL, width, height){
	newWindow = window.open(URL, 'popup', 'toolbar=no,location=no, left=40, scrollbars=yes,width= '+ width + ',height='+ height +'')
}
function popUpIMG(name, width, height,test) {

	newWindow = window.open('../templates/show_picture.php?name=' + name, test, "toolbar=no,location=no left=" + ((screen.width  - 500) / 2) + "px height=100 ,scrollbars=no,width="+ width +',height='+ height);
}

		function customPopUp2(url, width, height)
		{
			window.open(url, "", "height=" + height + "px,left=0px,top=0px,width=" + width + "px,resizable=1;");
		}

