/* Hack remove value inpu of Vm */
window.addEvent('domready', function(){
	var vm_inputs = getElementsByClass ("addtocart_button", null, "INPUT");	
	var vm_inputs1 = getElementsByClass ("addtocart_button_module", null, "INPUT");	
	if ((!vm_inputs || !vm_inputs.length) && (!vm_inputs1 || !vm_inputs1.length)) return;
	for (var i=0; i<vm_inputs.length; i++)
	{
		var vm_input = vm_inputs[i];
		vm_input.value = "";
	}
	
	if (!vm_inputs1 || !vm_inputs1.length) return;
	for (var i=0; i<vm_inputs1.length; i++)
	{
		var vm_input1 = vm_inputs1[i];
		vm_input1.value = "";
	}
									 
});

function switchFontSize (ckname,val){
	var bd = $E('BODY');
	switch (val) {
		case 'inc':
			if (CurrentFontSize+1 < 7) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize++;
				bd.addClass('fs'+CurrentFontSize);
			}		
		break;
		case 'dec':
			if (CurrentFontSize-1 > 0) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize--;
				bd.addClass('fs'+CurrentFontSize);
			}		
		break;
		default:
			bd.removeClass('fs'+CurrentFontSize);
			CurrentFontSize = val;
			bd.addClass('fs'+CurrentFontSize);		
	}
	Cookie.set(ckname, CurrentFontSize,{duration:365});
}

function switchTool (ckname, val) {
	createCookie(ckname, val, 365);
	window.location.reload();
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

function changeToolHilite(oldtool, newtool) {
	if (oldtool != newtool) {
		if (oldtool) {
			oldtool.src = oldtool.src.replace(/-hilite/,'');
		}
		newtool.src = newtool.src.replace(/.gif$/,'-hilite.gif');
	}
}

//addEvent - attach a function to an event
function jaAddEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

function getElem (id) {
	var obj = document.getElementById (id);
	if (!obj) return null;
	var divs = obj.getElementsByTagName ('div');
	if (divs && divs.length >= 1) return divs[divs.length - 1];
	return null;
}

function getFirstDiv (id) {
	var obj = document.getElementById (id);
	if (!obj) return null;
	var divs = obj.getElementsByTagName ('div');
	if (divs && divs.length >= 1) return divs[0];
	return obj;
}

function instr(str, item){
	var arr = str.split(" ");
	for (var i = 0; i < arr.length; i++){
		if (arr[i] == item) return true;
	}
	return false;
}

function equalHeightInit (){

	//Content and wrap col
	var ja_content = document.getElementById ('ja-container');
	var ja_colwrap = document.getElementById ('ja-colwrap');
	if (ja_content && ja_colwrap) {
		if (ja_content.scrollHeight > ja_colwrap.scrollHeight) 
		{
			var ja_inners = getElementsByClass ("innerpad", ja_colwrap, "DIV");	
			if (ja_inners && ja_inners.length)
			{
				ja_inners[0].style.height = ja_content.scrollHeight + 'px';
			}
		}else{
			document.getElementById ('ja-content').style.height = ja_content.scrollHeight + 'px';
		}
	}

	//Bottom spotlight 1
	var ja_botsl = document.getElementById ('ja-botsl1');
	if (ja_botsl)
	{
		var botsl = getElementsByClass ("ja-box.*", ja_botsl, "DIV");	
		if (botsl && botsl.length)
		{
			var maxh = 0
			for (var i=0; i<botsl.length ; ++i)
			{
				maxh = (botsl[i].scrollHeight > maxh)? botsl[i].scrollHeight:maxh;
			}
			for (var i=0; i<botsl.length ; ++i)
			{
				if (botsl[i].scrollHeight < maxh)
				{
					var ja_inners = getElementsByClass ("moduletable.*", botsl[i], "DIV");	
					if (ja_inners && ja_inners.length)
					{
						ja_inners[0].style.height = maxh - 30 + 'px';
					}
				}				
			}
		}
	}

	//Bottom spotlight 2
	var ja_botsl = document.getElementById ('ja-botsl2');
	if (ja_botsl)
	{
		var botsl = getElementsByClass ("ja-box.*", ja_botsl, "DIV");	
		if (botsl && botsl.length)
		{
			var maxh = 0
			for (var i=0; i<botsl.length ; ++i)
			{
				maxh = (botsl[i].scrollHeight > maxh)? botsl[i].scrollHeight:maxh;
			}
			for (var i=0; i<botsl.length ; ++i)
			{
				if (botsl[i].scrollHeight < maxh)
				{
					var ja_inners = getElementsByClass ("moduletable.*", botsl[i], "DIV");	
					if (ja_inners && ja_inners.length)
					{
						ja_inners[0].style.height = maxh - 30 + 'px';
					}
				}				
			}
		}
	}

}

jaAddEvent (window, 'load', equalHeightInit);

function preloadImages () {
	var imgs = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var imgsrc = arguments[i];
		imgs[i] = new Image();
		imgs[i].src = imgsrc;
	}
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	var j = 0;
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (var i = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	//alert(searchClass + j);
	return classElements;
}


function fixIE() {
	var objs = getElementsByClass ("createdate", null, "TD");
	if (objs) {
		for (var i=0; i<objs.length; i++){
			objs[i].innerHTML = "<span>" + objs[i].innerHTML + "</span>";
		}
	}

	var obj = $E('h1.logo a');
	obj.onmouseover = function () {
		this.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=templates/ja_genista/images/logo2.png, sizingMethod='crop')");
	}
	obj.onmouseout = function () {
		this.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=templates/ja_genista/images/logo1.png, sizingMethod='crop')");
	}
	
	var objs = getElementsByClass('.*-transbg');
	if (objs) {
		for(var i=0; i<objs.length;i++){
			makeTransBg(objs[i]);
		}
	}
}