/*
    CMS Backend - Interfata de administrare a CMS-urilor dezvoltate de Felix Manea
    Copyright (C) 2007-2008 Felix Manea (felix.manea@gmail.com)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/
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;
}
