// © Mircea Mihail Marmureanu
// contact: wm_maw at evonet dot ro


//interval
var oInterval = "";
var oInterval2 = "";
var retry = 0;
var retryMax = 20;
function timer(functionName, functionTime){
	oInterval = setInterval(functionName,functionTime);
}

//file Upload management
function fileSelectionStatus(id){
	document.getElementById(id+'Status').style.visibility = "visible";
	file = document.getElementById(id).value.split("\\");
	document.getElementById(id+'Status').innerHTML = file[file.length-1];
}
function clearFileSelection(id){
	document.getElementById(id+'Status').style.visibility = "hidden";
	document.getElementById(id).focus();
}
//button management
function mouse_Over(id){
	document.getElementById(id).src = document.getElementById(id).src.replace("/up/","/over/");
}

function mouse_Out(id){
	document.getElementById(id).src = document.getElementById(id).src.replace("/over/","/up/");
}

function mouse_Down(id){
	document.getElementById(id).src = document.getElementById(id).src.replace("/down/","/over/");
}
//end of button management

//backround change functions
function overLink(id, img){
	document.remember = document.getElementById(id).style.backgroundImage;
	document.getElementById(id).style.backgroundImage = "url(" + img + ")";
}
function outLink(id){
	document.getElementById(id).style.backgroundImage = document.remember;
}
function changeImage(imageName){
	document.getElementById('imageSpace').innerHTML = '<img src="./resize.php?p=./img/escorte/'+imageName+'&w=427&h=640" />';
}
function veziProfil(number){
	display('contentSubMaster', './veziProfil.php', false, 'id_esc='+number, 'veziProfil', 'contentContainer', 'GET');
	timer('loadAmount('+number+')', 500);
	customSwitch('button01', false);
	customSwitch('button02', true);
}
function modificaProfil(number){
	display('contentSubMaster', './modificaProfil.php', false, 'id_esc='+number, 'modificaProfil', 'contentContainer', 'GET');
	timer('loadAmount('+number+')', 500);
	customSwitch('button01', false);
	customSwitch('button02', true);
}

function veziProfilBack(){
	MM_openBrWindow(historyManager.goback(2),'_self');
	customSwitch('button02', false);
	customSwitch('button01', true);
	siteAreas.init();
}
function loadAmount(number){
	//errorHandler('tryToLoad = '+retry);
	retry += 1;
	if(!blocker){
		display('amount', 'counter.php', false, 'id_esc='+number, '', 'normal', 'GET');
		clearInterval(oInterval);
		oInterval = "";
		retry = 0;
	}else if(retry >= 5){
		blocker = false;
		retry = 0;
		display('contentSubMaster', 'veziProfil.php', false, 'id_esc='+number, 'veziProfil', 'contentContainer', 'GET');
	}
}
function thumbnails(){
	//customSwitch('amount', false);
	//removeLink('amount');
	//display('contentSubMaster', './thumbnails.php', false, '', 'thumbnails', '', 'GET');
	//MM_openBrWindow(document.URL,'_self');
	MM_openBrWindow('./#~contentManagement:main!main!~contentSubMaster:thumbnails!thumbnails!','_self');
	siteAreas.init();
}
function contactAdmin(){
	customSwitch('amount', false);
	removeLink('amount');
	display('contentSubMaster', './contactAdmin.php', true, null, 'contactAdmin', '', 'POST');
}
function addEscort(){
	//customSwitch('amount', false);
	//removeLink('amount');
	//display('contentSubMaster', './add.php', true, '', 'add', '', 'GET');
	//MM_openBrWindow(document.URL,'_self');
	MM_openBrWindow('./#~contentManagement:main!main!~contentSubMaster:add!add!','_self');
	siteAreas.init();
}

function links(){
	//customSwitch('amount', false);
	//removeLink('amount');
	//display('contentSubMaster', './links.php', true, '', 'anouncement', '', 'GET');
	//MM_openBrWindow(document.URL,'_self');
	MM_openBrWindow('./#~contentManagement:main!main!~contentSubMaster:anouncement!links!','_self');
	siteAreas.init();
}

function nav(vars){
	display('contentManagement', './main.php', false, vars, 'main', '', 'GET');
	timer('loadBanner("'+vars+'")', 500);
}
function loadBanner(vars){
	//errorHandler('tryToLoad = '+retry);
	retry += 1;
	if(!blocker){
		display('bannersDiv', './banners.php', false, vars, '', 'footerContainer', 'GET');
		clearInterval(oInterval);
		oInterval = "";
		retry = 0;
	}else if(retry >= 5){
		blocker = false;
		retry = 0;
		display('contentManagement', './main.php', false, vars, 'main', '', 'GET');
	}
}
function sendMailDisplay(){
	customSwitch('sendEmailForm', true);
	customSwitch('descriereEscorta', false);
	
}
function sendMailHide(){
	customSwitch('sendEmailForm', false);
	customSwitch('descriereEscorta', true);
}
function sendMessage(){
	submitForm(true, 'sendEmailForm', './sendMail.php', true, '', 'POST', 'title', 'from', 'to', 'message', 'name');
}
function romana(){
	MM_openBrWindow('./#~contentManagement:main!main!lang=ro','_self');
	siteAreas.init();
}
function engleza(){
	MM_openBrWindow('./#~contentManagement:main!main!lang=eng','_self');
	siteAreas.init();
}
function goHome(){
	MM_openBrWindow('./#~contentManagement:main!main!','_self');
	siteAreas.init();
}

function sendAdd(){
	document.getElementById('form1').submit();
	customSwitch('loading', true);
	retry = 0;
	document.getElementById('adding').innerHTML ="<!-- -->";
	callServer();
	oInterval = setInterval('callServer()',5500);
	oInterval2 = setInterval('searchAnswer()',1200);
}
function callServer(){
	content = document.getElementById('adding').innerHTML;
	//alert("callServer return ->"+content);
	retry += 1;
	if((!blocker && retry <retryMax ) || (content == "" && retry <retryMax)){
	display('adding', './uploadstatus.php', false, '', '', '', null);
	}else if(retry >= retryMax){
		clearInterval(oInterval);
		oInterval="";
		clearInterval(oInterval2);
		oInterval2="";
		customSwitch('loading', false);
		errorHandler("Eroare necunoscuta!", 'errorDiv');
	}	
}
function searchAnswer(){
	content = document.getElementById('adding').innerHTML;
	//alert("searchAnswer return ->"+content);
	if(retry < retryMax && content != loading && content != ""){
		if(content == "inregOk"){
			clearInterval(oInterval);
			oInterval="";
			clearInterval(oInterval2);
			oInterval2="";
			MM_openBrWindow('./?area=ok','_self');
		}else if(content.indexOf("src=") == -1){
			clearInterval(oInterval);
			oInterval="";
			clearInterval(oInterval2);
			oInterval2="";
			customSwitch('loading', false);
			errorHandler(content, 'localErrorDiv');
			display('adding', './uploadstatus.php', false, '', '', '', null);
		}
	}
}