// Javascript Library


function popupWindow(url,resizable){
	if (resizable == 1)
	window.open(url,'Tokashsilver','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=400,top=150,left=150'); else
	window.open(url,'Tokashsilver','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=400,top=150,left=150');
}

function popupAdminPanel(url,resizable){
	if (resizable == 1)
	window.open(url,'Tokashsilver','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=700,top=10,left=10'); else
	window.open(url,'Tokashsilver','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=no,resizable=no,width=500,height=500,top=150,left=150');
}

function round(number,X) {
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function FormatMoney(value,prefix,front) {
   
   if(front == true) {
	   result=prefix+' '+Math.floor(value)+".";

	   var cents=100*(value-Math.floor(value))+0.5;
	   result += Math.floor(cents/10);
	   result += Math.floor(cents%10);
   } else {
	   
	    result=Math.floor(value)+".";

	   var cents=100*(value-Math.floor(value))+0.5;
	   result += Math.floor(cents/10);
	   result += Math.floor(cents%10);
	   result += ' '+prefix;
	   
   }
   return result;
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function MM_goToURL() { //v3.0
	var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
	expire = new Date((new Date()).getTime() + hours * 3600000);
	expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function SetHighlighted(object) {
	object.style.color = '#333333';
	object.style.background = '#FF9900';
	object.style.border = 0;
}

function UnSetSetHighlighted(object) {
	object.style.color = '#666666';
	object.style.background = '#FFFFFF';
	object.style.border = 0;
}

function DisableElement(element) {
	if (element == null) return;
	element.disabled = true;
}

/////////// MENU //////////////////

function iOver(sender)
{
	if (!sender) return;
	//sender.originalClassName = sender.className;
	//sender.className = "MenuItemHover";
}	

function iOut(sender)
{
	if (!sender) return;
	//insideMenu = false;
	//sender.className = sender.originalClassName;
}	

function subOver(sender)
{
	if (!sender) return;
	insideMenu = true;

	var e;

	if (currentPopOut != "none")
	{
		changeDisplay(document.getElementById(currentPopOut), "none");
		currentPopOut = "none";
	}
	if (currentMenu != "none")
	{
		var e = document.getElementById(currentMenu);
		e.className = e.originalClassName;
		currentMenu = "none";
	}
		
	sender.originalClassName = sender.className;
	
	if (sender.className == "SubMenuItemCurrent") {
		sender.className = "SubMenuItemCurrentHover";
	}
	else {
		sender.className = "SubMenuItemHover";
	}
	var poperid = sender.id;
	currentMenu = poperid;
	poperid = poperid.replace(/poper/, "popup");
	currentPopOut = poperid;
	
	changeDisplay(document.getElementById(poperid), "");			
}

function subOut(sender)
{
	if (!sender) return;
	insideMenu = false;
}

function subOver2(sender)
{
	if (!sender) return;
	sender.originalClassName = sender.className;

	if (sender.className == "SubMenuItemCurrent") {
		sender.className = "SubMenuItemCurrentHover";
	}
	else {
		sender.className = "SubMenuItemHover";
	}
}	

function subOut2(sender)
{
	if (!sender) return;
	insideMenu = false;
	sender.className = sender.originalClassName;
}	


function changeDisplay(e, display)
{
	if (e.style != null) {
		e.style.display = display;
	}
	else {
		if (e.display != display) {
			e.display = display;
		}
	}	
}

function mOver(sender)
{

	insideMenu = true;

	var e;

	if (currentPopOut != "none")
	{
		changeDisplay(document.getElementById(currentPopOut), "none");
		currentPopOut = "none";
	}
	if (currentMenu != "none")
	{
		var e = document.getElementById(currentMenu);
		currentMenu = "none";
	}

		
	var poperid = sender.id;
	currentMenu = poperid;
	poperid = poperid.replace(/poper/, "popup");
	currentPopOut = poperid;
	
	changeDisplay(document.getElementById(poperid), "");			
}

function mOut(sender)
{
	insideMenu = false;
}
	
function mPopupOver(sender)
{
	if (!sender) return;
	insideMenu = true;
}
	
function mPopupOut(sender)
{
	if (!sender) return;
	insideMenu = false;
}
	
function sOver(sender, s)
{
	
	if (!sender) return;
//		insideMenu = true;
	sender.className = (s == "last" ? "PopupMenuItemHover2" : "PopupMenuItemHover");
}

function sOut(sender, s)
{
	if (!sender) return;
	insideMenu = false;
	sender.className = (s == "last" ? "PopupMenuItem2" : "PopupMenuItem");
}



var currentPopOut, currentMenu, HTMLStr;

currentPopOut = "none";
currentMenu = "none";
oldClassName = "";

insideMenu = false;
			
document.onmouseover = document_onmouseover;
			
function document_onmouseover()
{
	if (! insideMenu) {
		if (currentPopOut != "none")
		{
			changeDisplay(document.getElementById(currentPopOut), "none");
			currentPopOut = "none";	
		}
		if (currentMenu != "none")
		{
			var e = document.getElementById(currentMenu);
			//e.className = e.originalClassName;
			currentMenu = "none";
		}
	}
}	

function setCurrentItem2(ssid2)	// Level 2 items only
{
	var e = document.getElementById("sub" + ssid2);
	
	if (e == null) {
		e = document.getElementById("poper" + ssid2);
	}
	if (e == null) {
		return;
	}
	e.className = "SubMenuItemCurrent";
	e.originalClassName = "SubMenuItemCurrent";

	var i = document.getElementById("imgPointer");

	if (i != null) {
		var f = e.firstChild;
		e.insertBefore(i, f);
		i.style.display = "";
	}
}	

// Automatically generated items only.
function setCurrentItemTopic(id)
{
	var e = document.getElementById("mm_tpid" + id);

	if (e == null) {
		return;
	}
	e.className = "MenuItemHighlight";
	e.originalClassName = "MenuItemHighlight";
}	

// Automatically generated items only.
function setCurrentItemAuto(id, pref)
{
	var e = document.getElementById("mm_" + pref + id);

	if (e == null) {
		return;
	}
	e.className = "MenuItemHighlight";
	e.originalClassName = "MenuItemHighlight";
}	

/////////////// END MENU //////////////////////

function SelectItem(select_box,item_) {
	var whichitem = 0;
	if (document.getElementById(select_box) == null) return;
	while (whichitem < document.getElementById(select_box).length) {
		if (document.getElementById(select_box).options[whichitem].text == item_) {
			document.getElementById(select_box).selectedIndex = whichitem; 
			break;
		}
		whichitem++;
	}
}
function SelectItemByValue(select_box,item_) {
	var whichitem = 0;
	if (document.getElementById(select_box) == null) return;
	while (whichitem < document.getElementById(select_box).length) {
		if (document.getElementById(select_box).options[whichitem].value == item_) {
			document.getElementById(select_box).selectedIndex = whichitem; 
			break;
		}
		whichitem++;
	}
}
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}

function $e(obj)
{
	return document.getElementById(obj);
}

 function urlencode_string( str ) {
						// http://kevin.vanzonneveld.net
						// +   original by: Philip Peterson
						// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
						// +      input by: AJ
						// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
						// %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
						// *     example 1: urlencode('Kevin van Zonneveld!');
						// *     returns 1: 'Kevin+van+Zonneveld%21'
						// *     example 2: urlencode('http://kevin.vanzonneveld.net/');
						// *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
						// *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
						// *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
											 
						var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
						var ret = str.toString();
						
						var replacer = function(search, replace, str) {
							var tmp_arr = [];
							tmp_arr = str.split(search);
							return tmp_arr.join(replace);
						};
						
						// The histogram is identical to the one in urldecode.
						histogram['!']   = '%21';
						histogram['%20'] = '+';
						
						// Begin with encodeURIComponent, which most resembles PHP's encoding functions
						ret = encodeURIComponent(ret);
						
						for (search in histogram) {
							replace = histogram[search];
							ret = replacer(search, replace, ret) // Custom replace. No regexing
						}
						
						// Uppercase for full PHP compatibility
						return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
							return "%"+m2.toUpperCase();
						});
						
						return ret;
					}

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};


$().ready(function()
{
	//START LightBox
	$('#gallery a').lightBox();
	
	//START LEFTMENU
	$(".mleft").mouseover(function()
	{
		//HIDE ALL OTHER MENUS
		
		
		//var menuId   = $(this).attr("id");
		//var menuName = "#"+menuId.replace("poper", "popup");	
		//	openMenu[menuId] = 0;
		$(this).find('.PopupMenu').css('display', 'block');
		$(this).click(function() {
			$(this).find('.PopupMenu').css('display', 'none');
		});
		$(this).bind("mouseleave",function() {
				
				$(this).trigger('click');
		});

	});
	
	//RESIZE CATALOG PRODUCTS
	$(".hcat").each(function() 
	{
		var parentHeight = $(this).parents(".products").height();
		//alert(parentHeight);
		
		$(this).height(parentHeight);
		
	});
});
					

