function getObj(name) {
	if (document.getElementById) {
		if(document.getElementById(name)) {
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
		}
	}
	else if (document.all) {
		if(document.all[name]) {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		}
	}
	else if (document.layers) {
		if (document.layers[name]) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		}
	}
}

function columnMatch(column_1, column_2) {
	oCol_1 = new getObj(column_1);
	oCol_2 = new getObj(column_2);
	
	if( !oCol_1 || !oCol_2 ) { return; }
	if( !oCol_1.obj || !oCol_2.obj ) { return; }
	
	iHeight_1 = oCol_1.obj.offsetHeight;
	iHeight_2 = oCol_2.obj.offsetHeight;

	iNewHeight = Math.max(iHeight_1, iHeight_2);
	oCol_1.obj.style.height = iNewHeight + 'px';
	oCol_2.obj.style.height = (iNewHeight - 18) + 'px';
}

function columnMatch2(column_1, column_2, column_3) {
	oCol_1 = new getObj(column_1);
	oCol_2 = new getObj(column_2);
	oCol_3 = new getObj(column_3);
	
	if( !oCol_1 || !oCol_2 ) { return; }
	if( !oCol_1.obj || !oCol_2.obj ) { return; }
	if( !oCol_2 || !oCol_3 ) { return; }
	if( !oCol_2.obj || !oCol_3.obj ) { return; }
	
	iHeight_1 = oCol_1.obj.offsetHeight;
	iHeight_2 = oCol_2.obj.offsetHeight;
	iHeight_3 = oCol_3.obj.offsetHeight;

	iNewHeight = Math.max(iHeight_1, iHeight_2, iHeight_3);
	oCol_1.obj.style.height = iNewHeight + 'px';
	oCol_2.obj.style.height = iNewHeight + 'px';
	oCol_3.obj.style.height = iNewHeight + 'px';
}

function resetFieldClick(fieldId,defaultVal)
{
	var field = document.getElementById(fieldId);
	if (field.value == defaultVal)
	{
		field.value = '';
	}
}

function resetFieldBlur(fieldId,defaultVal)
{
	var field = document.getElementById(fieldId);
	if (field.value == '')
	{
		field.value = defaultVal;
	}
}

function closeMenu() {
	for(i=1;i<6;i++) {
		if(getObj('menu' + i).style.display='block') {
			getObj('menu' + i).style.display='none';
		}
	}
}

function expand(containerId) {
	if ( !containerId ) return;
	oContainer = new getObj(containerId);
	if ( !oContainer ) return;
	sDisplay = oContainer.obj.style.display;
	if ( sDisplay != 'block' ) { 
		oContainer.obj.style.display = 'block';
	}
	else if ( sDisplay = 'block' ) {
		oContainer.obj.style.display = 'none';
	}
}

function stripPath(loc)
{
	return loc.replace(/^(((.+)\/)+)?(([\w\-_]+\.)+\w{3})$/, '$4');
}

// Change the picture
function chgPic(newSrc)
{
	document.getElementById('bigPic').src=baseHref+'custom_images/galerie/full/'+stripPath(newSrc);
}

function pop(src)
{
	window.open(baseHref+'custom_images/galerie/pop/'+stripPath(src),'popup' ,'resizable=1, status=0, toolbar=0, location=0, menubar=0, width=750, height=750');
}

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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function reloadWindow()
{
	window.location=window.location;
	
	return;
}

/* GALERIE FOTO */
function changePic(newSrc,newName)
{
	document.getElementById('bigPic').src=baseHref+'custom_images/galerie/full/'+stripPath(newSrc);
	document.getElementById('bigPicName').innerHTML=newName;
}

function move_Left()
{
	var x=document.getElementById('gallery_pics');
	if (parseInt(x.style.marginLeft) < 0)
	{
		y=parseInt(document.getElementById('gallery_pics').style.marginLeft);
		x.style.marginLeft = y + 80 + 'px';
		setCookie(x.style.marginLeft); // update cookie with the position of the slider when moving to left
	}
	setDefaultPosition();
}

function move_Right()
{
	var x=document.getElementById('gallery_pics');
	var linksNumber = x.getElementsByTagName("a").length;
//	alert(linksNumber*83);
	if (Math.abs(parseInt(x.style.marginLeft)) < ((linksNumber*80)-315))
	{
		y=parseInt(document.getElementById('gallery_pics').style.marginLeft);
		x.style.marginLeft = y - 80 + 'px';
		setCookie(x.style.marginLeft); // update cookie with the position of the slider when moving to right
	}
	setDefaultPosition();
}
	
function setCookie(value) 
{ // sets the cookie named starfoods_istoric to a value
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000 * 24 * 999 ); // set expire time after 999 days (never)
	document.cookie = 'uniter_photo_gallery' + "=" + escape(value) + ";expires=" + expire.toGMTString(); // set the cookie
}
	
function getCookie() 
{ // returns the value of a cookie (starfoods_istoric in this case)
	var c_name = 'uniter_photo_gallery'; // the cookie we use to work on
	
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length+1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}
	
function setDefaultPosition() 
{ // sets the position of the slider to the position kept in the cookie
	var x = document.getElementById('gallery_pics');
	x.style.marginLeft = parseInt(getCookie()) + 'px';
}
/* END GALERIE FOTO */