///////////////////////////////////////////////////////////////////////////////

var searchBoxInitialValue = '';
var loginIdTextInitialValue = '';

///////////////////////////////////////////////////////////////////////////////

function init() {
	self.setTimeout(checkPassword, 500);

	elem = document.getElementById('search-box-text');
	if(elem)
		searchBoxInitialValue = elem.value;

	elem = document.getElementById('member-login-input-id');
	if(elem)
		loginIdTextInitialValue = elem.value;

	elem = document.getElementById('member-login-input-password');
	if(elem && elem.addEventListener)
		elem.addEventListener("input", checkPassword, false);

    //update search valuator form, if case
    elem = document.getElementById('edit-judet');
    if(elem) {
        searchFormCountyChanged(elem);    
    }
        
	flash_eolas_fix();
	//changeImage("alegeri-2008", "");
	changeImage("parteneri-ivsc", "");
	changeImage("parteneri-tegova-3", "");
	changeImage("anunturi-angajare", "");
	changeImage("parteneri-rocert-2", "");
	scroll ();
}

///////////////////////////////////////////////////////////////////////////////

function clearSearchEdit(elem) {
	elem.value = "";
}

///////////////////////////////////////////////////////////////////////////////

function resetSearchEdit(elem) {
	value = elem.value.replace(/^\s*|\s*$/g,"");
	if(value == "")
		elem.value = searchBoxInitialValue;
}

///////////////////////////////////////////////////////////////////////////////

addLoadEvent(init);

///////////////////////////////////////////////////////////////////////////////

function flash_eolas_fix()
{
    //ediy v2
    n=navigator.userAgent;
    w=n.indexOf("MSIE");
    if((w>0)&&(parseInt(n.charAt(w+5))>5)){
        T=["object","embed","applet"];
        for(j=0;j<2;j++){
            E=document.getElementsByTagName(T[j]);
            for(i=0;i<E.length;i++){
                P=E[i].parentNode;
                H=P.innerHTML;
                P.removeChild(E[i]);
                P.innerHTML=H;
            }
        }
    }
}

///////////////////////////////////////////////////////////////////////////////

function changeImage(id, flag) {
    img = document.getElementById('id-' + id);
    source = 'img/' + id;
    if (flag != "")
        source += '.' + flag;
    source += '.jpg';
    img.src = source;
    
    return true;
}

///////////////////////////////////////////////////////////////////////////////

var coordinate = 1;

function scroll ()
{
    var step = 3;
    var width = 226;

    coordinate -= step;
    if (coordinate < -width)
        coordinate = width;

    if (coordinate > -step && coordinate < step) {
        coordinate = 0;
        self.setTimeout(scroll, 10*1000);
    }
    else
        self.setTimeout(scroll, 40);

    var scroll_container = document.getElementById('id-scroll-container');
    scroll_container.style.left = coordinate + 'px';
}

///////////////////////////////////////////////////////////////////////////////

function idNumberFocus(edit) {
	if(edit.value == loginIdTextInitialValue) {
		edit.value = '';
	}
}

///////////////////////////////////////////////////////////////////////////////

function idNumberBlur(edit) {
	if(edit.value.length == 0) {
		edit.value = loginIdTextInitialValue;
	}

	self.setTimeout(checkPassword, 500);
}

///////////////////////////////////////////////////////////////////////////////

function passwordFocus(edit) {
	edit.style.backgroundImage = 'none';
}

///////////////////////////////////////////////////////////////////////////////

function passwordBlur(edit) {
	if(edit.value.length == 0) {
		edit.style.backgroundImage = 'url(themes/anevar/imagini-anevar/cod-acces.gif)';
		edit.style.backgroundPosition = 'center left';
		edit.style.backgroundRepeat = 'no-repeat';
	}
}

///////////////////////////////////////////////////////////////////////////////

function checkPassword() {
	elem = document.getElementById('member-login-input-password');
	if(elem && elem.value.length > 0)
		elem.style.backgroundImage = 'none';
}

///////////////////////////////////////////////////////////////////////////////

function emptySelect(select) {
	var size = select.options.length;
	for(var i=0; i<size; i++) {
		select.options[0] = null;
	}
}

///////////////////////////////////////////////////////////////////////////////
  
function populateCitySelect(select, index) {
    var size = CountyCityPairs[index][1].length;
    for(var i=0; i<size; i++) {
        select.options[i] = new Option(CountyCityPairs[index][1][i], CountyCityPairs[index][1][i]);
    }
}

///////////////////////////////////////////////////////////////////////////////

function searchFormCountyChanged(elem) {

	var citySelect = document.getElementById('edit-localitate');
	var county = elem.value;
	var size = CountyCityPairs.length;
	for(var i=0; i<size; i++) {
		var crtCounty = CountyCityPairs[i][0];
		if(crtCounty == county) {
			emptySelect(citySelect);
			populateCitySelect(citySelect, i);
			break;
		}
	} 
}

///////////////////////////////////////////////////////////////////////////////

