function preloadImages(imgArray){
	var images = new Array();
	for(i=0;i<imgArray.length;i++)
	{
		t = new Image(); 
		t.src = '<?=base_url?>'+imgArray[i];
		images.push(t);
	}
}

function getElById(elName)
{
	el = document.getElementById(elName);
	if(typeof(el) == 'undefined' || el == null) return false;
	return el;
}

function getElementHeight(Elem) {
	if (elem && elem.clip && elem.clip.height) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else 
	{
		if(document.getElementById) 
		{
			var elem = document.getElementById(Elem);
		} 
		else if (document.all)
		{
			var elem = document.all[Elem];
		}
		if (elem)
		{
			if(elem.style && elem.style.pixelHeight) 
			{
				yPos = elem.style.pixelHeight;
			} 
			else 
			{
				yPos = elem.offsetHeight;
			}
		}
		else return false;
		return yPos;
	}
}

function getElementWidth(Elem) {
	if (elem && elem.clip && elem.clip.width) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else 
	{
		if(document.getElementById) 
		{
			var elem = document.getElementById(Elem);
		} 
		else if (document.all)
		{
			var elem = document.all[Elem];
		}
		if (elem)
		{
			if(elem.style && elem.style.pixelWidth) 
			{
				xPos = elem.style.pixelWidth;
			} 
			else 
			{
				xPos = elem.offsetWidth;
			}
		}
		else return false;
		return xPos;
	}
}

function bigPicture(image, base_url)
{
	if(typeof(image) == 'undefined')
	{
		img = document.getElementById('imagine_produs');
		if(typeof(img) == 'undefined') return;
		image = img.src;
	}
	if(typeof(base_url) == 'undefined') base_url = '';
	window.open(base_url + 'imgpreview.php?src='+escape(image),'_bigPicture','top=0, left=0, scrollbars=1, status=0, width=100, height=100, resizable=0'); 
}

function getScreenResolution()
{
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
	 screenW = screen.width;
	 screenH = screen.height;
	}
	else if (navigator.appName == "Netscape" 
			&& parseInt(navigator.appVersion)==3
			&& navigator.javaEnabled()
		 ) 
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenW = jScreenSize.width;
	 screenH = jScreenSize.height;
	}
	return new Array(screenW, screenH);
}


function resizeWindow(w,h) {
 //trebuie recalculat in fct de marime sa faca sau nu bara orizontala 
 w+=16;
 h+=3;
 
 resolution = getScreenResolution();
 if(w > resolution[0]) w = resolution[0];
 if(h > resolution[1]) h = resolution[1] - 50;
 
 if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
		top.outerWidth=w;
		top.outerHeight=h;
	 }
	 else top.resizeTo(w,h);
 }
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {width: myWidth, height: myHeight}
}

function resizeElHeightByWindowSize(element, difference){
	w = getWindowSize();
	height = (w.height - difference);
	//if(getElementHeight(element) <= height)
	document.getElementById(element).style.height = height+'px';
}

function resizeAll(){
	resizeElHeightByWindowSize('pageContent', 286);
	//alert(getElementHeight('pageContent'));
	//document.getElementById('pagePlanta').style.height = (getElementHeight('pageContent')-304)+'px';
}

function getImageFromSrc(src){
	var regexp = /^(.*\/)?([^\/]+)$/;
	if(!regexp.exec(src)) return alert("Nume fisier trimis invalid: "+src);
	return RegExp.$2;
}

function rotateImg(elId, timeout, imgArray, counter){
	if(imgArray.length < 2) return;
	document.getElementById(elId).src = boxEvenimente[imgArray[counter]];
	imgArrayStr = 'new Array(';
	for(var i = 0; i < imgArray.length; i++) imgArrayStr += (i!=0?', ':'')+"'"+imgArray[i]+"'";
	imgArrayStr += ')';
	setTimeout("rotateImg('"+elId+"', "+timeout+", "+imgArrayStr+", "+((counter + 1) % imgArray.length)+");", timeout);
}

/*jquery cookie*/
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};
/*end jquery cookie*/

function mb_grid_list(grid){
	$('#produse_list').removeClass().addClass(grid?"pr_grid":"pr_list");
	$.cookie("mb_grid", grid?1:0, {expires:365});
}
