var classifiedHolder=false;

var starSetup = Array();
var firstStarGetter = false;
var holdPaddingLeft;
var holdState; 
var noteJustSet = false;
var slides = 25;
var slideId;
var colorHolder;
var imgHolder;
var cityHolder=false; //needed for intro pages "Toate Articolele", "Toate anunturile"

var touchedMap = false;

var iconStates;

var _A_state=true, _C_state=false;

var activeTimeout = Array();
var activeTimeout2 = Array();

var aTIndex = 0;
var activeElem = 0;
var activeElem2 = 0;

var startDelay2 = 8600;

var prepAdvApply = Array();

function highlight(element, state)
{
	if (state)
		element.style.opacity = 0.9;
	else
		element.style.opacity = 0.35;
}

function addBonus(entityId)
{

}


function addMalus(entityId)
{

}


function postComment(entityType, entityId)
{
	if (document.getElementById("entity_type")!=null && document.getElementById("entity_id")!=null && document.getElementById("comment_text")!=null)
	{
		if (trim($("comment_text").value)!="" && !introMsg)
			$("commentForm").submit();
		else
			alert("Comentariul nu poate fi adaugat");
	}
}

function loadMainPhoto(styleImage, styleContainer, imageSource, visitor, crtAlbum, crtUser, flag)
{
	if (!flag)
	{
		clearInterval(APactInt);
		TimeToFade = 256.0;
	}

	introMsg=true;
	content = "<div id='mainPhoto' style='"+styleContainer+"'>";
		content += "<img border='1' style='"+styleImage+"' src='"+imageSource+"'>";
	content += "</div>";

	document.getElementById("galery_main").innerHTML = content;

	var attr= "getDetails="+imageSource;
		attr += "&visitor="+visitor;
		attr += "&_acrt="+crtAlbum;
		attr += "&_ucrt="+crtUser;

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
		var result = originalRequest.responseText.split("&|^");
		var title, description, note;
		title = result[0];
		addon = result[1];
		description = result[2];
		descaddon = result[3];
		note = result[4];
		comments = result[5];
		addcomment = result[6];

		document.getElementById("photo_title").innerHTML = title;
		document.getElementById("photo_description").innerHTML = description;
		document.getElementById("photo_note").innerHTML = note;
		document.getElementById("photo_comments").innerHTML = comments;
		document.getElementById("photo_add_comment").innerHTML = addcomment;
		
        }
}


function setCN(path, userId, note)
{
	
	var attr= "setComNote=1";
		attr += "&img="+path;
		attr += "&userId="+userId;
		attr += "&comments=some comment";
		attr += "&note="+note;
		

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
		var result = originalRequest.responseText;
		document.getElementById('photo_note').update(result);
        }
}


function slideLeft()
{
	slides--;
	if (slides==0)
	{
		clearInterval(slideId);
		slides = 25;
		return "";
	}
	
	elemValue = parseInt(document.getElementById("mainPhoto").style.paddingLeft) - 3; 
	document.getElementById("mainPhoto").style.paddingLeft = elemValue+"px";
}


function adjustPaddingLeft()
{
/*
	if (document.getElementById("rightDiv").style.display == 'block')
	{
		holdPaddingLeft = document.getElementById("mainPhoto").style.paddingLeft;
		holdPaddingLeft = parseInt(holdPaddingLeft);
		if (holdPaddingLeft < 100)
			return "";

		var newPaddingLeft;
		newPaddingLeft = holdPaddingLeft - 100;
		slideId = setInterval("slideLeft()", 2);
	}
	else
*/
	{
		document.getElementById("mainPhoto").style.paddingLeft = holdPaddingLeft+"px";
	}
}



var  TimeToFade = 256.0;
function fade(eid)
{
	var element = document.getElementById(eid);
	if(element == null)
		return;

	if(element.FadeState == null)
	{
		if(element.style.opacity == null
		|| element.style.opacity == ''
		|| element.style.opacity == '1')
		{
			element.FadeState = 2;
		}
		else
		{
			element.FadeState = -2;
		}
	}

	if(element.FadeState == 1 || element.FadeState == -1)
	{
		element.FadeState = element.FadeState == 1 ? -1 : 1;
		element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
	}
	else
	{
		element.FadeState = element.FadeState == 2 ? -1 : 1;
		element.FadeTimeLeft = TimeToFade;
		setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
	}  
}


function  animateFade(lastTick, eid)
{  
	var curTick = new Date().getTime();
	var elapsedTicks = curTick - lastTick;

	var element = document.getElementById(eid);

	if(element.FadeTimeLeft <= elapsedTicks)
	{
		element.style.opacity = element.FadeState == 1 ? '1' : '0';
		element.style.filter = 'alpha(opacity = '
		+ (element.FadeState == 1 ? '100' : '0') + ')';
		element.FadeState = element.FadeState == 1 ? 2 : -2;
		return;
	}

	element.FadeTimeLeft -= elapsedTicks;
	var newOpVal = element.FadeTimeLeft/TimeToFade;
	if(element.FadeState == 1)
		newOpVal = 1 - newOpVal;

	element.style.opacity = newOpVal;
	element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';

	setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}



function changePage(newPage, username, owner, album, mainWidth, mainHeight)
{
	var attr= "newPage="+newPage;
		attr += "&username="+username;
		attr += "&album="+album;
		attr += "&mainWidth="+mainWidth;
		attr += "&mainHeight="+mainHeight;
		attr += "&owner="+owner;
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
          var result = originalRequest.responseText;
		  
          $("rightDiv").update(result);
        }
}



function showStar(position, state, oldNote)
{

if (noteJustSet) //if user clicked, override Server Side sent oldNote and use js session note
	oldNote = noteJustSet;

if (!firstStarGetter)
{
	firstStarGetter = true;
	if (!noteJustSet) //if not clicked yet, save default status of the star icons (as coming from the db)
	{
		for (i=1;i<=5;i++)
			starSetup[i] = document.getElementById("star"+i).innerHTML;
	}
	else //save clicked status
	{
		//update old note with session note
		for (i=1;i<=noteJustSet;i++)
			starSetup[i] = "<img border=0 src='/proj/STATIC_IMGS/stars/star_a.png'>";
		
		if (noteJustSet < 5)
			for(i=noteJustSet+1;i<=5;i++)
				starSetup[i] = "<img border=0 src='/proj/STATIC_IMGS/stars/star_g.png'>";

	}
}

var i = 1;
if (state)
{
	if (holdState)
		return;

	//set old Note first
	for (i=1;i<=oldNote;i++)
		document.getElementById("star"+i).innerHTML = starSetup[i];

	//set new elements up until position
	for (i=1;i<=position;i++)
		document.getElementById("star"+i).innerHTML = "<img border=0 src='/proj/STATIC_IMGS/stars/star_b.png'>";

}
else
{
	if (!holdState)
		return;

	for (i=1;i<=5;i++)
		document.getElementById("star"+i).innerHTML = starSetup[i];

	for (i=1;i<=oldNote;i++)
		document.getElementById("star"+i).innerHTML = "<img border=0 src='/proj/STATIC_IMGS/stars/star_a.png'>";
}


holdState = state;

}



function changeAlbumPage(owner, visitor, crtAlbumFp, page, albumTypes)
{
	var attr= "slideAlbums=true";
		attr += "&owner="+owner;
		attr += "&visitor="+visitor;
		attr += "&crtAlbumFp="+crtAlbumFp;
		attr += "&page="+page;
		attr += "&albumTypes="+albumTypes;
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
          var result = originalRequest.responseText;
          $("albums_div_container").update(result);
        }
}
		  
function colorize(obj, color)
{
	colorHolder = obj.style.backgroundColor;
	obj.style.backgroundColor = color;
}


function uncolorize(obj)
{
	obj.style.backgroundColor = colorHolder;

}

function colorize_img(obj, imgName)
{
	imgHolder = obj.style.backgroundImage;
	obj.style.background = "url("+imgName+")";
}


function uncolorize_img(obj)
{
	obj.style.backgroundImage = imgHolder;
}



function performSearch(searchPhrase)
{
	var attr= "gallerySearch=true";
		attr += "&gSQ="+searchPhrase;

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 	
		//split separator is intentionally different
		var result = originalRequest.responseText.split("&^|");
		var stats = result[0];
		var html_content = result[1];

		$("gal_search_results").update(html_content);
		$("gal_search_results").style.display = "block";
        }
}



function checkSearch(event, searchQuery)
{
	if (trim(searchQuery)=='')
		return;

	if (event.keyCode==13) 
	{
		performSearch(searchQuery);
	}
	else if (event.keyCode==27)
	{
		document.getElementById("gal_search").value = "";
	}
}


function switchSearchPhoto()
{
	obj = $("gal_search_results").style.display;
	if (obj == 'none')
	{
		$("albums_div").style.display = 'block';
		$("photo_switcher").update("<img border=0 src='/proj/STATIC_IMGS/fold.png'>");
	}
	else
	{
		$("albums_div").style.display = 'none';
		$("photo_switcher").update("<img border=0 src='/proj/STATIC_IMGS/unfold.png'>");
	}

}

function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) 
{
	return stringToTrim.replace(/\s+$/,"");
}

function switchGalMap()
{
	$("gal_map_holder").style.display = ($("gal_map_holder").style.display == 'none') ? 'block' : 'none';

	if ($("gal_map_holder").style.display == 'block')
	{
		//hide albums div
		$("albums_div").style.display = "none";
		$("gal_show_on_btn").innerHTML = _LBL_showOnSel;
		
		initialize();
		touchedMap = !touchedMap;
		if (touchedMap)
			$("showMapOption").style.marginTop = _MSG_showGmap2;
		else
			$("showMapOption").style.marginTop = _MSG_showGmap1;
	}
	else
	{
		//show albums div
		$("albums_div").style.display = "block";
		$("gal_show_on_btn").innerHTML = _LBL_showOnMap;

		touchedMap = !touchedMap;
		$("map_canvas").style.height = '350px';
		$("showMapOption").style.marginTop = _MSG_unshowGmap;
	}

	var attr= "gallerySaveState=true";
		attr += "&newState="+$("gal_map_holder").style.display;

	//send the map show state
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 	
		;//nothing to do
        }
}


function __setNote(entityType, entityId, note, output)
{
	noteJustSet = note;
	firstStarGetter = false;
	

	var attr= "setNote=true";
		attr += "&artId="+entityId;
		attr += "&entityType="+entityType;
		attr += "&newNote="+note;
		attr += "&output="+output;
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.ratings.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 	
		;//nothing to do
		$("yourNote").innerHTML = originalRequest.responseText;
        }

}


function setBM(entityType, entityId, bm, parentId, lineType)
{
	$("bm_mod_"+entityId).update("<div style='margin-top: 22px'><img src='/STATIC_IMGS/ajxl/bm_"+lineType+".gif></div>");
		
	var attr= "addBonusMalus=true";
		attr += "&commentId="+entityId;
		attr += "&parentId="+parentId;
		attr += "&entityType="+entityType;
		attr += "&bm="+bm;
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.comments.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 	
		$("bm_mod_"+entityId).update(originalRequest.responseText);
        }
}


function _updCities(countryId, forceName)
{
	document.getElementById("dep_sel_city").innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='/STATIC_IMGS/ajxl/plswait.gif'>";
	var attr= "selCountry="+countryId;
	if (forceName != undefined)
		attr += "&name="+forceName;
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.classifieds.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
		var results = originalRequest.responseText;
		document.getElementById("dep_sel_city").innerHTML = results;
        }
}

function crAlbumCityUpd(cityLabel, type)
{
	if (type == 1)
	{
		var replaceWhat = "..., ...";
		var countryLabel = document.getElementById("galCrCountryId").options[document.getElementById("galCrCountryId").selectedIndex].innerHTML;
		cityLabel = cityLabel +', '+countryLabel;
	}
	else
		var replaceWhat = "...";

	if (justChanged)
		replaceWhat = justChanged;

	if (document.getElementById("album_title") != null)
		document.getElementById("album_title").value = document.getElementById("album_title").value.replace(replaceWhat,cityLabel);

	if (document.getElementById("album_description")!= null)
		document.getElementById("album_description").value = document.getElementById("album_description").value.replace(replaceWhat,cityLabel);

	justChanged = cityLabel;
}



function qLPos(e)
{
	//var coords = getMouseXY(e);
//	var coordSet = coords.split("||")
///	var coordX = coordSet[0]-400;
//	var coordY = coordSet[1];

//	$("qLAbs").style.marginTop = coordY+"px";
//	$("qLAbs").style.marginLeft = coordX+"px";
}

function qLShow()
{
	$("qLAbs").style.display = 'block';
}

function qLHide()
{
	$("qLAbs").style.display = 'none';
}


function changeLegend(pushed, colors, borders)
{
	if (borders == undefined)
		borders = false;

	if (colors == undefined)
		colors = 'transparent';

	//current object state is set by default to TRUE TRUE
	//switch the state of pushedObj
	if (pushed == '1')
		_A_state = _A_state ? false : true;
	
	if (pushed == '2')
		_C_state = _C_state ? false : true;

	if (!_A_state && !_C_state)
	{
			_A_state = true;
	}



	//set coordinates
	if (_A_state && _C_state)
		$("gmap_coords").value = $("ds_all").value;
	else
		if (_A_state && !_C_state)
			$("gmap_coords").value = $("ds_group1").value;
	else 
		if (_C_state && !_A_state)
			$("gmap_coords").value = $("ds_group2").value;
			
		
	initialize();


	//based on new state, change colors
	if (!_A_state)
	{
		$("GR1_only").style.backgroundColor = 'transparent';

		if (borders)
			$("GR1_only").style.border = '1px dashed #CDCDCD';
	}
	else
	{
		$("GR1_only").style.backgroundColor = colors;
		if (borders)
			$("GR1_only").style.border = '1px solid #CDCDCD';
	}


	if (!_C_state)
	{
		$("GR2_only").style.backgroundColor = 'transparent';
		if (borders)
			$("GR2_only").style.border = '1px dashed #CDCDCD';
	}
	else
	{
		$("GR2_only").style.backgroundColor = colors;
		if (borders)
			$("GR2_only").style.border = '1px solid #CDCDCD';
	}
}


function loadMapElements(pushed, objToLoad)
{
	if (pushed == "1")
	{
		$("GR1_in").style.marginTop = "0px";
		$("GR2_in").style.marginTop = "-50px";
		_A_state = true;
		_C_state = false;
	}

	if (pushed == "2")
	{
		$("GR1_in").style.marginTop = "-50px";
		$("GR2_in").style.marginTop = "0px";
		_A_state = false;
		_C_state = true;
	}

	$("gmap_coords").value = $(objToLoad).value;
	initialize();
}


function pushExtVisit(extURL)
{
	var attr= "pushExtVisit=true";
		attr += "&extURL="+extURL;
		attr += "&intURL="+document.location.href;
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.push.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
        }
}

var activeImgStuff;
function imgHighlight(objId, state, fp)
{
	if (activeSF == 1) 
		return false;
	var obj = document.getElementById(objId);
	if (state)
	{
		activeImgStuff = imgStuff[fp];
		smSFade("hjx_desc");
		unLightOthers(objId);
		obj.style.border = "3px solid #EF7305";
		setTimeout('putStuff()', 500);
		
	}
	else
	{
		//obj.style.borderTop = "3px solid #D5E0EA";
	//	obj.style.borderRight = "3px solid #D5E0EA";
	//	obj.style.borderLeft = "3px solid #D5E0EA";
	//	obj.style.borderBottom = "3px solid #D5E0EA";
		//$("hjx_desc").update("");
	}
}


function imgHighlightS(objId)
{
	var obj = document.getElementById("gPrvS_"+objId);
	obj.style.border = "2px solid #EF7305";
	unLightOthersS(objId);
}

function unLightOthersS(objId)
{
	var i=0;
	var selObj;
	for(i=0;i<50;i++)
	{
		if (objId != i)
		{
			selObj = document.getElementById("gPrvS_"+i);
			if (selObj!=null)
			{
				selObj.style.border = "2px solid #D5E0EA";
			}
		}
	}

}

function putStuff()
{
	$("hjx_desc").update(activeImgStuff);
	smSFade("hjx_desc");
}


function unLightOthers(selId)
{
	var i=0;
	var selObj;
	for(i=0;i<10;i++)
	{
		if (selId != i)
		{
			selObj = document.getElementById("gPrv_"+i);
			if (selObj!=null)
			{
				selObj.style.border = "3px solid #D5E0EA";
			}
		}
	}
}



// ******************************Effect on home - left element***********************************************
function hmC()
{
	activeTimeout[aTIndex++] = setTimeout('fadeAndLoad(1)',startDelay);
}

//fade and load
function fadeAndLoad(elem)
{
	smToggle('hm_chg', 1000, elem);
}


//change to another element
var oldInner = '';
var oldInner2 = '';

var newInner = '';
var newInner2 = '';
var elem1 = '';
var elem2 = '';
var elem3 = '';
function hmLoad(elem)
{
	if (elem > 4)
		elem = 1;

	if (elem < 1)
		elem = 4;

	if (elem == undefined)
		elem = 1;

	activeElem = elem;

	if (elem == 1)
	{
		oldInner = $('hm_chg').innerHTML;
		if (elem1 != '')
		{
			$('hm_chg').innerHTML = elem1;
			smToggle('hm_chg', 1000, -1);
			activeTimeout[aTIndex++] = setTimeout('fadeAndLoad(2)',startDelay-1000);
			return;
		}
	}

	if (elem == 2)
	{
		if (elem2 != '')
		{
			$('hm_chg').innerHTML = elem2;
			smToggle('hm_chg', 1000, -1);
			activeTimeout[aTIndex++] = setTimeout('fadeAndLoad(3)',startDelay-1000);
			return;
		}
	}

	if (elem == 3)
	{
		if (elem3 != '')
		{
			$('hm_chg').innerHTML = elem3;
			smToggle('hm_chg', 1000, -1);
			activeTimeout[aTIndex++] = setTimeout('fadeAndLoad(4)',startDelay-1000);
			return;
		}
	}


	if (elem == 4)
	{
		$('hm_chg').innerHTML = oldInner;
		smToggle('hm_chg', 1000, -1);
		hmC();
		return;
	}


	var attr= "fetchNew"+elem+"=true";
		attr += "&fetcherType="+pageType;
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.fetcher.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
		$('hm_chg').innerHTML = originalRequest.responseText;
		smToggle('hm_chg', 1000, -1);
		if (elem == 1)
		{
			elem1 = $('hm_chg').innerHTML;
			activeTimeout[aTIndex++] = setTimeout('fadeAndLoad(2)',startDelay-2000);
		}

		if (elem == 2)
		{
			elem2 = $('hm_chg').innerHTML;
			activeTimeout[aTIndex++] = setTimeout('fadeAndLoad(3)',startDelay-2000);
		}

		if (elem == 3)
		{
			elem3 = $('hm_chg').innerHTML;
			activeTimeout[aTIndex++] = setTimeout('fadeAndLoad(4)',startDelay-2000);
		}
        }
}


// ***************************Effect on home - right element **************************************************
function mmC()
{
	activeTimeout2[aTIndex++] = setTimeout('fadeAndLoad2(1)',startDelay2);
}

//fade and load
function fadeAndLoad2(elem)
{
	//smToggle2('map_holder', 1000, elem);
	hmLoad2(elem);
}

var elemS1 ='';
function hmLoad2(elem)
{
	if (elem == 1)
	{
		$("map_canvas").toggle();
		$("hic_cid").style.height = "366px";
		if (_BR == 'Microsoft Internet Explorer')
		{
		//	$("hic_cid").style.marginLeft = "-300px";
		}

		//take a shortcut if already did this
		if (elemS1 != '')
		{
			$("hic_cid").toggle();
			setTimeout('fadeAndLoad2(1)',startDelay2);
			return false;
		}
	}
	else
	{
		$("hic_cid").toggle();
		smSFade("map_canvas");
		setTimeout('fadeAndLoad2(1)',startDelay2);
		return false;
	}

	var attr= "imgFetcher=true";
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.fetcher.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
		$('hic_cid').innerHTML = originalRequest.responseText;
		if (elem == 1)
		{
			elemS1 = $('map_holder').innerHTML;
			activeTimeout2[aTIndex++] = setTimeout('fadeAndLoad2(2)',startDelay2);
		}

        }
}


//change album sort
function sortAlbums(sortType)
{
	$("_albHldr").innerHTML = "<div style='float:left; width: 100px; margin-left: 450px; margin-top: 110px'><img src='/STATIC_IMGS/ajxloader2.gif'></div>";
	//show the ajax holder
	var attr= "sortType="+sortType;
		attr += "&albSort=true";
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        { 
		var response = originalRequest.responseText.split("^|&");
		sortClearAll();
		firstActive = sortType;
		$("_albHldr").innerHTML = response[0];
		$("ss_pagination").innerHTML = response[1];
		$("opt"+sortType).style.marginTop = "-34px";
        }
}

var oldFloater = '';
var newFloater = '';
function loadLogin()
{
	if (!oldFloater)
		oldFloater = $("qLAbs").innerHTML;

	if (document.getElementById("qLogId") == null)
		return;

	$("qLAbs").innerHTML = $("qLogId").innerHTML;

}

function loadLinks()
{
	$("qLAbs").innerHTML = oldFloater;
}

function loadTag(phr)
{
	hsrcState = true;
	$("search_box").value = phr;
	clVal($("search_box").value);
}

function clearAllTimeouts()
{
	var lgth = activeTimeout.length;
	for(i=0;i<=lgth;i++)
		clearTimeout(activeTimeout[i]);
}

function pause()
{
	clearAllTimeouts(activeTimeout);
}

function ffwd()
{
	clearAllTimeouts();
	fadeAndLoad(activeElem+1)
}


function rew()
{
	clearAllTimeouts();
	fadeAndLoad(activeElem-1);
}


function loadSpPhoto(photoPath, albumURL)
{
	var attr= "specificPhoto="+photoPath;
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });
        function showResponse(originalRequest)
        { 
		document.location.href = albumURL;
		return;
	}
}


function checkPic()
{
	var j=0;
	var secondDiez=0;
	var first=0;
	var nowURL = document.location.href;
	var actualPhoto = '';
	//if url has this string
	first = strpos(nowURL, "#/GALLERY_IMGS/");
	if (first)
	{
		secondDiez = strpos(nowURL, "#", first+1);
		if (secondDiez)
			actualPhoto = nowURL.substring(first+1, secondDiez);
		else
			actualPhoto = nowURL.substring(first+1);


		//check the arr table for the photo and callback the stored function
		for(j=0;j<=30;j++)
			if (arr[j]!=undefined)
			{
				if (strpos(arr[j], actualPhoto))
				{
					eval(arr[j]);
					return true;
				}
			}
	}
}


var firstActive = 4;
var activeSortOption;
function sortMouseOver(id)
{
	activeSortOption = id;
	$("opt"+id).style.marginTop = "-34px";
}

function sortMouseOut(id)
{
	if (id == firstActive)
		return false;

	$("opt"+id).style.marginTop = "0px";
}


function sortClearAll()
{
	$("opt1").style.marginTop = "0px";
	$("opt2").style.marginTop = "0px";
	$("opt3").style.marginTop = "0px";
	$("opt4").style.marginTop = "0px";
	$("opt5").style.marginTop = "0px";
}

var lastElement='';
function highlightEdit(field)
{
	field.style.fontStyle = "normal";
	field.style.color = "#000000";
	lastElement = field.value;
}


function unHighlightEdit(field)
{
	if (!trim(field.value))
	{
		field.style.fontStyle = "italic";
		field.style.color = "grey";
		field.value = lastElement;
	}
}


function saveArtData(footprint)
{
	var msg='';
	var mandatory = 0;

	if (trim($("pers_addr").value)=='' || $("pers_addr").value=='Click aici pentru a configura adresa completa')
	{
		msg += "- Nu ati configurat adresa [OBLIGATORIU]\n";
		mandatory++;
	}

	if (trim($("pers_eml").value)=='' || $("pers_eml").value=='adresa_email@yahoo.com')
	{
		msg += "- Nu ati configurat o adresa de email [OBLIGATORIU]\n";
		mandatory++;
	}

	if (trim($("pers_phone1").value)=='' || $("pers_phone1").value=='0040-256-0123456')
		msg += "- Nu ati configurat primul nr de telefon\n";

	if (trim($("pers_phone2").value)=='' || $("pers_phone2").value=='0040-744-0123456')
		msg += "- Nu ati configurat al doilea nr de telefon";


	if (msg)
		alert(msg);

	if (mandatory)
		return false;


	var attr= "fp="+footprint;
		attr+= "&pers_phone1="+$("pers_phone1").value;
		attr+= "&pers_phone2="+$("pers_phone2").value;
		attr+= "&pers_addr="+$("pers_addr").value;
		attr+= "&pers_eml="+$("pers_eml").value;

	if (document.getElementById("pers_web")!=null)
		attr+= "&pers_web="+$("pers_web").value;

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.forum.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });
        function showResponse(originalRequest)
        { 
		$("f_co_ti_status").update("&middot; Date de contact <span style='color: white'>[OK]</span>");
	}
}


function sendGoogleCoords(footprint)
{
	var attr= "gfp="+footprint;
	attr+= "&setCity="+$("class_sel_city").value;

	var myAjax = new Ajax.Request(
		    '/proj/PHP/ajax/dispatch.forum.php',
		    {
			method: 'post',
			parameters: attr,
			asynchronous: true,
			onComplete: showResponse,
			contentType:'application/x-www-form-urlencoded',
			encoding: 'UTF-8'
		    });
	function showResponse(originalRequest)
	{ 
		$("gmap_coords_all").innerHTML = originalRequest.responseText+"|_PH";
	}
}

function switchMapType()
{
	prepMap("byUser","",1);
}

function changeArt()
{
	smSFade("news_mod_avg");
	smToggle3("news_mod_id"); //this will launch changeArtDelayed after fading
}

function changeArtDelayed()
{
	var attr= "newArtFetcher=true";

	var myAjax = new Ajax.Request(
		    '/proj/PHP/ajax/dispatch.fetcher.php',
		    {
			method: 'post',
			parameters: attr,
			asynchronous: true,
			onComplete: showResponse,
			contentType:'application/x-www-form-urlencoded',
			encoding: 'UTF-8'
		    });
	function showResponse(originalRequest)
	{ 
		var response = originalRequest.responseText.split("^|&");
		$("news_mod_id").innerHTML = response[0];
		$("news_mod_avg").innerHTML = response[1];
		smSFade("news_mod_id");
		smSFade("news_mod_avg");
	}
}

function goToPage(pageToLoad)
{
	$("_albHldr").innerHTML = "<div style='float:left; width: 100px; margin-left: 450px; margin-top: 110px'><img src='/STATIC_IMGS/ajxloader2.gif'></div>";
	var attr= "pageChanger="+pageToLoad;

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.gallery.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });
	function showResponse(originalRequest)
	{ 
		var response = originalRequest.responseText.split("^|&");
		$("_albHldr").innerHTML = response[0];
		$("ss_pagination").innerHTML = response[1];
	}
}


function flipLoginP1(obj, size)
{
	obj.style.marginTop = size+"px";
}


function logout()
{
	if (confirm("Click pe OK pentru a va deconecta"))
		document.location.href='/logout.htm';
}

function sendToFriend(url)
{
	if (!oldFloater)
		oldFloater = $("qLAbs").innerHTML;

	if (document.getElementById("qSendId") == null)
		return;

	$("qLAbs").innerHTML = $("qSendId").innerHTML;
}


function validateCaptcha(cpc, tit)
{
	if (trim($("your_list").value) == '')
	{
		alert("Nu ati selectat nici o adresa de email");
		return;
	}

	if (trim($("your_email").value) == '')
	{
		alert("Va rugam sa va introduceti adresa de email");
		$("your_email").focus();
		return;
	}

	var attr= "cpc="+cpc;
		attr += "&tit="+tit;

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.misc.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });
	function showResponse(originalRequest)
	{ 
		var response = originalRequest.responseText;
		if (response == 1)
			$("fsend_form").submit();
		else
			alert(response);
	}
}

function searchOrFilter()
{
	var page='';
	if (document.getElementById("suggestInput")!=null)
		page = 'gal';
	else
		if (document.getElementById("search_box")!=null)
			page = 'home';
		else
			return false;
		
	if (page == 'home')
	{
			$("srcFrm").submit();
		//document.location.href = "/cauta.htm?f="+page+"&q="+document.getElementById("search_box").value;
	}
	else
		if (page == 'gal')
			galSorter(document.getElementById("suggestInput").value);

}


function prepHotLocations(regionId)
{
	var attr= "chgLocations=true";
		attr += "&rId="+regionId;

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.home.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });
	function showResponse(originalRequest)
	{ 
		var response = originalRequest.responseText;
		$("id_hotloc").update(response);
	}
}


function region2Map(regionId)
{
	prepMap('region', 1, "", "", regionId);
	prepHotLocations(regionId);
}

function urlencode(str) 
{
    return escape(str.replace(/%/g, '%25').replace(/\+/g, '%2B')).replace(/%25/g, '%');
}

function hotGoTo()
{
	var countryName = "romania";
	var cityName = $("citysel").value;
	var startDate = $("pr_st_date").value;
	var noNights = $("selNights").value;
	var persons = $("selPersons").value;


	if (!countryName || !cityName || cityName == -1)
	{
		alert('Trebuie sa alegeti o regiune sau un oras');
		return false;
	}

	if (!startDate || !noNights)
		if (!confirm("Nu ati selectat Data sosirii si Numarul de nopti.\n           Doriti totusi sa lansati cautarea?"))
			return false;

	$("hot_form").action = '/cazare/'+countryName+'/'+cityName+'/';
	//document.location.href='/cazare/'+countryName+'/'+cityName+'/?st='+startDate+'&ni='+noNights;
	$("ni").value = noNights;
	$("st").value = startDate;
	$("pe").value = persons;
	$("hot_form").submit();
}


var existingValues = Array();
function advToggle(id)
{
	if ($(id).style.height == '100%')
	{
		$(id).style.height = "128px";
		$("a_"+id).innerHTML = existingValues[id];
	}
	else
	{
		$(id).style.height = "100%";
		existingValues[id] = $("a_"+id).innerHTML;
		$("a_"+id).innerHTML = "Micsoreaza";
	}

}


function advApply(fi)
{
	var id = $(fi).id;
	var partString = "";
	var attr= "advFilter=true";
		attr += "&optN="+$(fi).id;
		attr += "&optV="+$(fi).checked;

	if ($(fi).id.substring(0, 6) == 'cb_pr_') //price sliders
	{
		partString = $(fi).id.substring(6); //not required
		attr += "&amFrom_"+partString+"="+$("amount_from_"+partString).value;
		attr += "&amTo_"+partString+"="+$("amount_to_"+partString).value;
	}

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.hotel.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });
	function showResponse(originalRequest)
	{ 
		var response = originalRequest.responseText;
		$("adv_filter_div").update(response);
		prepMap("country");
	}
}

function resetAdvFilters()
{
	var attr= "advResetFilter=true";
	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.hotel.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });
	function showResponse(originalRequest)
	{ 
		var response = originalRequest.responseText;
		$("adv_filter_div").update(response);
		prepMap("country");
	}
}

var showSpam=false;
function showSpamPhotos()
{
	if (showSpam)
		return false;

	smExpand("divShowSpam");
	showSpam = true;
}


function __chgCurrency(nc)
{
	if (nc < -1)
	{
		alert("Va rugam alegeti o moneda sau valuta din lista");
		return false;
	}

	var attr= "setNavCurrency=true";
		attr += "&nc="+nc;

	var myAjax = new Ajax.Request(
                    '/proj/PHP/ajax/dispatch.hotel.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });
	function showResponse(originalRequest)
	{ 
		var response = originalRequest.responseText;
		document.location.href = document.location.href;
	}
}

