function OnDelete(strToDelete,idToDelete)
{	

	if(window.confirm("Are you sure you want to delete "+ strToDelete+" from the database?")== true)
	{
		// remove some items from url
		
		var str = document.location.href;
		str = RemoveURLParam(str,"delete=");
		str = RemoveURLParam(str,"id=");
		
		var pos = str.indexOf("?")
		var url = str;
		if (pos>=0)
		{
			url = url+"&delete=1&id="+idToDelete;
		}
		else
		{
			url = url+"?delete=1&id="+idToDelete;
		}
		window.location = url;
	}
}
function RemoveURLParam(strURL,strParam)
{
	var retstr="";
	urlparams = strURL.split('?');
	if(urlparams.length != 2)
		return strURL;	
	retstr = urlparams[0];
			
	params = urlparams[1].split('&');
	var bFirst = true;
	for(i=0;i<params.length;i++)
	{ 
		if(params[i].search(strParam) == -1)
		{
			// if not found insert in the returning string
			if(	bFirst)
				retstr +="?";
			bFirst = false;
			retstr += params[i]+"&";
		}
	}	
	return retstr;
}

function validateNumber(textArea) {
	if (textArea.value == null || textArea.value == "" || isNaN(textArea.value)) {
		return false;
	}
	return true;
}

function validateItems(array) {
	while(array.length > 0) {
		obj = array.pop();
		if (obj.value == null || obj.value == '') {
			return false;
		}
	}
	return true;
}

function validate(textArea, button) {
	if (textArea.value == null || textArea.value == "") {
		button.disabled = true;
		button.className = "disabled_buton";
	}
	else {
		button.disabled = false;
		button.className = "buton";
	}
}

function checkValues(array, item, button) {
	notEmpty = validateItems(array);
	aNumber = amountCheck(item);
	if (notEmpty && aNumber) {
		button.disabled = false;
		button.className = "buton";
	}
	else {
		button.disabled = true;
		button.className = "disabled_buton";
	}
}

function redirectUrl(url, ref) {
	if (url.indexOf("?") > 0)
		window.location = url + '&ref='+escape(ref);
	else
		window.location = url + '?ref='+escape(ref);
}

function amountCheck(amountField)
{
	if (isNaN(amountField.value))
	{
		return false;
	}
	strStrippedAmount = amountField.value;
	indexPoint = strStrippedAmount.indexOf(".");
	if (indexPoint == -1)
	{
		if(strStrippedAmount.length > 7)
		{
			return false;
		}
	}
	else
	{
		if(strStrippedAmount.substring(0, indexPoint).length > 7)
		{
			return false;
		}
		if(strStrippedAmount.substring(indexPoint+1, strStrippedAmount.length).length > 2)
		{
			return false;
		}
	}
	return true;
}


//Needed for color chooser

var SetBG = top.SetBG ;
var Tog = top.Tog ;

var colordelim = "000000|BEBEBE|696969|D3D3D3|778899|708090|F0F8FF|8A2BE2|5F9EA0|6495ED|483D8B|00CED1|00BFFF|1E90FF|ADD8E6|E0FFFF|87CEFA|8470FF|B0C4DE|66CDAA|0000CD|7B68EE|48D1CC|191970|000080|AFEEEE|B0E0E6|4169E1|87CEEB|6A5ACD|4682B4|7FFFD4|F0FFFF|0000FF|00FFFF|000080|40E0D0|2F4F4F|BC8F8F|8B4513|F4A460|F5F5DC|A52A2A|DEB887|D2691E|CD853F|D2B48C|006400|BDB76B|556B2F|8FBC8F|228B22|ADFF2F|7CFC00|20B2AA|32CD32|3CB371|00FA9A|F5FFFA|6B8E23|98FB98|2E8B57|00FF7F|9ACD32|7FFF00|00FF00|F0E68C|FF8C00|E9967A|F08080|FFA07A|FFDAB9|FFE4C4|FF7F50|F0FFF0|FFA500|FA8072|A0522D|FF1493|FF69B4|CD5C5C|FFB6C1|C71585|FFE4E1|FF4500|DB7093|D02090|B22222|FFC0CB|FF0000|FF6347|9932CC|9400D3|FFF0F5|BA55D3|9370DB|E6E6FA|FF00FF|B03060|DA70D6|DDA0DD|A020F0|D8BFD8|EE82EE|FAEBD7|FFFAF0|F8F8FF|FFDEAD|FDF5E6|F5F5F5|DCDCDC|FFFFF0|FAF0E6|FFF5EE|FFFAFA|F5DEB3|FFFFFF|FFEBCD|B8860B|FFFACD|EEDD82|FAFAD2|FFFFE0|EEE8AA|FFEFD5|FFF8DC|FFD700|DAA520|FFE4B5|FFFF00";
var colorNameDelim = "Black|Grey|DimGrey|LightGray|LightSlateGrey|SlateGray|AliceBlue|BlueViolet|CadetBlue|CornflowerBlue|DarkSlateBlue|DarkTurquoise|DeepSkyBlue|DodgerBlue|LightBlue|LightCyan|LightSkyBlue|LightSlateBlue|LightSteelBlue|MediumAquamarine|MediumBlue|MediumSlateBlue|MediumTurquoise|MidnightBlue|NavyBlue|PaleTurquoise|PowderBlue|RoyalBlue|SkyBlue|SlateBlue|SteelBlue|Aquamarine|Azure|Blue|Cyan|Navy|Turquoise|DarkSlateGray|RosyBrown|SaddleBrown|SandyBrown|Beige|Brown|Burlywood|Chocolate|Peru|Tan|DarkGreen|DarkKhaki|DarkOliveGreen|DarkSeaGreen|ForestGreen|GreenYellow|LawnGreen|LightSeaGreen|LimeGreen|MediumSeaGreen|MediumSpringGreen|MintCream|OliveDrab|PaleGreen|SeaGreen|SpringGreen|YellowGreen|Chartreuse|Green|Khaki|DarkOrange|DarkSalmon|LightCoral|LightSalmon|PeachPuff|Bisque|Coral|Honeydew|Orange|Salmon|Sienna|DeepPink|HotPink|IndianRed|LightPink|MediumVioletRed|MistyRose|OrangeRed|PaleVioletRed|VioletRed|Firebrick|Pink|Red|Tomato|DarkOrchid|DarkViolet|LavenderBlush|MediumOrchid|MediumPurple|Lavender|Magenta|Maroon|Orchid|Plum|Purple|Thistle|Violet|AntiqueWhite|FloralWhite|GhostWhite|NavajoWhite|OldLace|WhiteSmoke|Gainsboro|Ivory|Linen|Seashell|Snow|Wheat|White|BlanchedAlmond|DarkGoldenrod|LemonChiffon|LightGoldenrod|LightGoldenrodYellow|LightYellow|PaleGoldenrod|PapayaWhip|Cornsilk|Gold|Goldenrod|Moccasin|Yellow";

var colors = colordelim.split( "|" ) ;
var names = colorNameDelim.split( "|" );

function WriteColorTable( document, ncols ) {
	alert("OK");
	document.writeln( "<TABLE border=8>" ) ;

	for( var i = 0 ; i < colors.length ; i++ ) {
	if( (i % ncols) == 0 ) {
		document.write( "\n<TR>" ) ;
	}
	var rgb = colors[i].split( "" ) ;
	var name = names[i];
	var bgcol = "#"+rgb[0]+rgb[1]+rgb[2]+rgb[3]+rgb[4]+rgb[5] ;
		document.write( '<TD width="2" height="10" bgcolor="' + bgcol + '\" onclick="selectColor(\''+name+'\', \''+bgcol+'\')" onMouseOver="SetBG(\''+name+'\', \'' + bgcol + '\');"></td>');
	}
	document.writeln( "</TABLE>" ) ;
}


var cartId = "";
function showCart(url) {
	window.location = url+"?cartid="+cartId;
}
function getCartId() {
	urlParams = window.location.toString().split('?')[1];
	if(urlParams != null) {
		params = urlParams.split('&');
		for(i=0; i < params.length; i++) {
			if (params[i].toLowerCase().indexOf('cartid') == 0) {
				cartId = params[i].split('=')[1].replace('#', '');
			}
		}
	}
}

function confirmDelete(isItemNotProduct)
{
	if(isItemNotProduct)
	{
		if(confirm('Are you sure you want to delete the selected item?'))
			return true;
		else 
			return false;
	}
	else
	{
		if(confirm('Are you sure you want to delete the selected product and all its variations?'))
			return true;
		else 
			return false;
	}
}
