var xmlHttp


// AJAX loader functions:
function getHeight() {
  var myHeight = 0;
  if( typeof( window.top.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.top.innerHeight;
  } else if( window.top.document.documentElement && window.top.document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = window.top.document.documentElement.clientHeight;
  } else if( window.top.body && window.top.body.clientHeight ) {
    //IE 4 compatible
    myHeight = window.top.document.body.clientHeight;
  }
  
  myHeight=myHeight+getScrollY();
  return myHeight;
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.top.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.top.pageYOffset;
  } else if( window.top.document.body && window.top.document.body.scrollTop ) {
    //DOM compliant
    scrOfY = window.top.document.body.scrollTop;
  } else if( window.top.document.documentElement && window.top.document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = window.top.document.documentElement.scrollTop;
  }
  return scrOfY;
}




function showajaxloader()
{
	elaloader=locate_el('ajaxloader', window.parent.document);
	elaloader.style.visibility='visible';
	elaloader.style.height=getHeight().toString()+'px';
	elajaxloadertable=locate_el('ajaxloadertable', window.parent.document);
	elajaxloadertable.style.height=getHeight().toString()+'px';
	return 1;
}


function hideajaxloader()
{
	elaloader=locate_el('ajaxloader', window.parent.document);
	elaloader.style.visibility='hidden';
	return 1;
}


function showallbookmarks()
{
	elallbookmarks=locate_el('allbookmarks');
	if(elallbookmarks.style.visibility=="visible")
		{
			elallbookmarks.style.visibility="hidden";
		}
	else
		{
			elallbookmarks.style.visibility="visible";
		}
}



// AJAX main function
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



// AJAX function used
// Account creation
function create_account()
{
	
	
	

	elusername=locate_el('username');
	elpassword=locate_el('password');
	elpassword2=locate_el('password2');
	elemail=locate_el('email');
	
	elcode=locate_el('code');
	elagree=locate_el('agree');
	
	elnumefirma=locate_el('numefirma');
	elcountry=locate_el('country');
	elregion=locate_el('region');
	elcity=locate_el('city');
	eladdress=locate_el('address');
	elzip=locate_el('zip');
	elphone=locate_el('phone');
	elfax=locate_el('fax');
	elmap=locate_el('map');
	elweb=locate_el('web');
	elperson=locate_el('person');
	elposition=locate_el('position');
	
	elshortdesc=locate_el('shortdesc');
	elkeywords=locate_el('keywords');
	
	PrepareSave();
	eldescription=locate_el('DataTextarea');
	
	elmanufacturer=locate_el('manufacturer');
	elsupplier=locate_el('supplier');
	elseller=locate_el('seller');
	elbuyer=locate_el('buyer');
	elimporter=locate_el('importer');
	elexporter=locate_el('exporter');
	elserviceprovider=locate_el('serviceprovider');
	elagent=locate_el('agent');
	
	elyear=locate_el('year');
	elnoe=locate_el('noe');
	elsales=locate_el('sales');
	
	
	elcategory=locate_el('category');
	elsubcategory=locate_el('subcategory');
	elsubsubcategory=locate_el('subsubcategory');
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var urltosend="./actions/createaccount.php";
	var url="";
	url=url+"username="+encodeURIComponent(elusername.value);
	url=url+"&password="+encodeURIComponent(elpassword.value);
	url=url+"&password2="+encodeURIComponent(elpassword2.value);
	url=url+"&email="+encodeURIComponent(elemail.value);
	
	url=url+"&numefirma="+encodeURIComponent(elnumefirma.value);
	url=url+"&country="+elcountry.options[elcountry.selectedIndex].value;
	url=url+"&region="+encodeURIComponent(elregion.value);
	url=url+"&city="+encodeURIComponent(elcity.value);
	url=url+"&address="+encodeURIComponent(eladdress.value);
	url=url+"&zip="+encodeURIComponent(elzip.value);
	url=url+"&phone="+encodeURIComponent(elphone.value);
	url=url+"&fax="+encodeURIComponent(elfax.value);
	url=url+"&map="+encodeURIComponent(elmap.value);
	url=url+"&web="+encodeURIComponent(elweb.value);
	url=url+"&person="+encodeURIComponent(elperson.value);
	url=url+"&position="+encodeURIComponent(elposition.value);
	
	
	url=url+"&shortdesc="+encodeURIComponent(elshortdesc.value);
	url=url+"&keywords="+encodeURIComponent(elkeywords.value);
	url=url+"&description="+encodeURIComponent(eldescription.value);
	
	if(elmanufacturer.checked)		{ url=url+"&manufacturer=1"; }
	else									{ url=url+"&manufacturer=0"; }
	
	if(elsupplier.checked)			{ url=url+"&supplier=1"; }
	else									{ url=url+"&supplier=0"; }
	
	if(elseller.checked)				{ url=url+"&seller=1"; }
	else									{ url=url+"&seller=0"; }
	
	if(elbuyer.checked)				{ url=url+"&buyer=1"; }
	else									{ url=url+"&buyer=0"; }
	
	if(elimporter.checked)			{ url=url+"&importer=1"; }
	else									{ url=url+"&importer=0"; }
	
	if(elexporter.checked)			{ url=url+"&exporter=1"; }
	else									{ url=url+"&exporter=0"; }
	
	if(elserviceprovider.checked)	{ url=url+"&serviceprovider=1"; }
	else									{ url=url+"&serviceprovider=0"; }
	
	if(elagent.checked)				{ url=url+"&agent=1"; }
	else									{ url=url+"&agent=0"; }
	
	
	url=url+"&category="+elcategory.options[elcategory.selectedIndex].value;
	url=url+"&subcategory="+elsubcategory.options[elsubcategory.selectedIndex].value;
	url=url+"&subsubcategory="+elsubsubcategory.options[elsubsubcategory.selectedIndex].value;
	
	url=url+"&year="+elyear.options[elyear.selectedIndex].value;
	url=url+"&noe="+elnoe.options[elnoe.selectedIndex].value;
	url=url+"&sales="+elsales.options[elsales.selectedIndex].value;
	
	
	url=url+"&code="+encodeURIComponent(elcode.value);
	
	if(elagree.checked)
		{		
			url=url+"&agree=1";
		}
	else
		{
			url=url+"&agree=0";
		}
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=function() { verify_create_account(); }
	xmlHttp.open("POST",urltosend,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-Length", url.length);
	xmlHttp.setRequestHeader("Connection", "close"); 
	xmlHttp.send(url);
}

function verify_create_account() 
{ 
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	responses=xmlHttp.responseText.split('#ER#');
	
	elerrors1=locate_el('errors1');
	elerrors2=locate_el('errors2');
	elerrors3=locate_el('errors3');
	elerrors4=locate_el('errors4');
	elerrors5=locate_el('errors5');
	elerrors6=locate_el('errors6');
	elerrors7=locate_el('errors7');
	elerrors8=locate_el('errors8');
	
	elnewaccbox=locate_el('newaccbox');

	
	if((responses[0]=='OK') || (responses[0]=='NOTOK'))
		{
			if(responses[0]=='OK')
				{
					elnewaccbox.innerHTML=responses[1];
				}
			
			if(responses[0]=='NOTOK')
				{
					elerrors1.innerHTML=responses[1];
				}
		}
	else
		{
			if(responses[0]!='No errors')
				{
					elerrors1.innerHTML=responses[0];
				}
			else
				{
					elerrors1.innerHTML='';	
				}
			if(responses[1]!='No errors')
				{
					elerrors2.innerHTML=responses[1];
				}
			else
				{
					elerrors2.innerHTML='';	
				}
			if(responses[2]!='No errors')
				{
					elerrors3.innerHTML=responses[2];
				}
			else
				{
					elerrors3.innerHTML='';	
				}
			if(responses[3]!='No errors')
				{
					elerrors4.innerHTML=responses[3];
				}
			else
				{
					elerrors4.innerHTML='';	
				}
			if(responses[4]!='No errors')
				{
					elerrors5.innerHTML=responses[4];
				}
			else
				{
					elerrors5.innerHTML='';	
				}
			if(responses[5]!='No errors')
				{
					elerrors6.innerHTML=responses[5];
				}
			else
				{
					elerrors6.innerHTML='';	
				}
				
			if(responses[6]!='No errors')
				{
					elerrors7.innerHTML=responses[6];
				}
			else
				{
					elerrors7.innerHTML='';	
				}
				
			if(responses[7]!='No errors')
				{
					elerrors8.innerHTML=responses[7];
				}
			else
				{
					elerrors8.innerHTML='';	
				}
		}
		
		window.scroll(0, 0);
}
}





// roll in first page




function constantcheck()
{
	x=Math.random();
	if(x<0.5)
		{
			checkfornew_buying();
			//alert ('buy!')
		}
	else
		{
			checkfornew_selling();	
			//alert ('sell!')
		}
}

function checkfornew_buying()
{
	el_primabuying=locate_el('primabuying');
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  return;
	  }
	 
	var url="./actions/checkfornew_buying.php";
	url=url+"?prima="+el_primabuying.value;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=function() {
		decide_newbuying();
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function decide_newbuying() 
{ 
if (xmlHttp.readyState==4)
{
	el_primabuying=locate_el('primabuying');
	response=xmlHttp.responseText;
	pbval=el_primabuying.value.toString();
	if(el_primabuying.value!=response)
		{
				req_newbuying();
				el_primabuying.value=response;
		}
	else
		{
			setTimeout('constantcheck()',1000);
		}
}
}

function req_newbuying()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  	return;
	  }
	 
	
	el_startcolorbuy=locate_el('startcolorbuy');
	 
	var url="./actions/req_newbuying.php";
	url=url+"?col="+el_startcolorbuy.value;
	url=url+"&sid="+Math.random();
	
	if(el_startcolorbuy.value==1)
		{
			el_startcolorbuy.value=0;
		}
	else
		{
			el_startcolorbuy.value=1;
		}
	
	xmlHttp.onreadystatechange=function() {
		display_newbuying();
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function display_newbuying() 
{ 
if (xmlHttp.readyState==4)
{
	el_latestbuying=locate_el('latestbuying');
	
	response=xmlHttp.responseText;
	el_latestbuying.innerHTML=response;
	setTimeout('constantcheck()',1000);
}
}





function constantcheck_sell()
{
	checkfornew_selling();
}

function checkfornew_selling()
{
	el_primaselling=locate_el('primaselling');
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  return;
	  }
	 
	var url="./actions/checkfornew_selling.php";
	url=url+"?prima="+el_primaselling.value;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=function() {
		decide_newselling();
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function decide_newselling() 
{ 
if (xmlHttp.readyState==4)
{
	el_primaselling=locate_el('primaselling');
	response=xmlHttp.responseText;
	pbval=el_primaselling.value.toString();
	if(el_primaselling.value!=response)
		{
				req_newselling();
				el_primaselling.value=response;
		}	
	else
		{
			setTimeout('constantcheck()',1000);
		}
}
}

function req_newselling()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  	return;
	  }
	 
	
	el_startcolorsell=locate_el('startcolorsell');
	 
	var url="./actions/req_newselling.php";
	url=url+"?col="+el_startcolorsell.value;
	url=url+"&sid="+Math.random();
	
	if(el_startcolorsell.value==1)
		{
			el_startcolorsell.value=0;
		}
	else
		{
			el_startcolorsell.value=1;
		}
	
	xmlHttp.onreadystatechange=function() {
		display_newselling();
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function display_newselling() 
{ 
if (xmlHttp.readyState==4)
{
	el_latestselling=locate_el('latestselling');
	
	response=xmlHttp.responseText;
	el_latestselling.innerHTML=response;
	setTimeout('constantcheck()',1000);
}
}




// AJAX function used
// ADV arata categoriile
function adv_settype()
{
	elamt_type=locate_el('amt_type');
	
		
	
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/adv_settype.php";
	url=url+"?type="+elamt_type.options[elamt_type.selectedIndex].value;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=show_adv_settype;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function show_adv_settype() 
{ 
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	response=xmlHttp.responseText;
	
	eladv_cat=locate_el('adv_cat');

	
	eladv_cat.innerHTML=response;
	
}
}


// AJAX function used
// Account creation
function swith_acctype()
{
	eltc1=locate_el('tipcont1');
	eltc2=locate_el('tipcont2');
	
	x='1';
	if(eltc1.checked)
		{
			x='1';
		}
	else if(eltc2.checked)
		{
			x='2';
		}
		
	
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/swith_acctype"+x+".php";
	url=url+"?sid="+Math.random();
	
	xmlHttp.onreadystatechange=show_swith_acctype;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function show_swith_acctype() 
{ 
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	response=xmlHttp.responseText;
	
	elnewaccbox=locate_el('newaccbox');

	
	elnewaccbox.innerHTML=response;
	
}
}




// AJAX function used
// Account creation
function edit_account()
{
	elpassword=locate_el('password');
	elpassword2=locate_el('password2');
	
	elcode=locate_el('code');
	elagree=locate_el('agree');
	
	elcountry=locate_el('country');
	elregion=locate_el('region');
	elcity=locate_el('city');
	eladdress=locate_el('address');
	elzip=locate_el('zip');
	elphone=locate_el('phone');
	elfax=locate_el('fax');
	elmap=locate_el('map');
	elweb=locate_el('web');
	elperson=locate_el('person');
	elposition=locate_el('position');
	
	elshortdesc=locate_el('shortdesc');
	elkeywords=locate_el('keywords');
	
	PrepareSave();
	eldescription=locate_el('DataTextarea');
	
	elmanufacturer=locate_el('manufacturer');
	elsupplier=locate_el('supplier');
	elseller=locate_el('seller');
	elbuyer=locate_el('buyer');
	elimporter=locate_el('importer');
	elexporter=locate_el('exporter');
	elserviceprovider=locate_el('serviceprovider');
	elagent=locate_el('agent');
	
	elyear=locate_el('year');
	elnoe=locate_el('noe');
	elsales=locate_el('sales');
	
	
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var urltosend="./actions/editaccount.php";
	var url="";
	url=url+"password="+encodeURIComponent(elpassword.value);
	url=url+"&password2="+encodeURIComponent(elpassword2.value);


	url=url+"&country="+elcountry.options[elcountry.selectedIndex].value;
	url=url+"&region="+encodeURIComponent(elregion.value);
	url=url+"&city="+encodeURIComponent(elcity.value);
	url=url+"&address="+encodeURIComponent(eladdress.value);
	url=url+"&zip="+encodeURIComponent(elzip.value);
	url=url+"&phone="+encodeURIComponent(elphone.value);
	url=url+"&fax="+encodeURIComponent(elfax.value);
	url=url+"&map="+encodeURIComponent(elmap.value);
	url=url+"&web="+encodeURIComponent(elweb.value);
	url=url+"&person="+encodeURIComponent(elperson.value);
	url=url+"&position="+encodeURIComponent(elposition.value);
	
	
	url=url+"&shortdesc="+encodeURIComponent(elshortdesc.value);
	url=url+"&keywords="+encodeURIComponent(elkeywords.value);
	url=url+"&description="+encodeURIComponent(eldescription.value);
	
	if(elmanufacturer.checked)		{ url=url+"&manufacturer=1"; }
	else									{ url=url+"&manufacturer=0"; }
	
	if(elsupplier.checked)			{ url=url+"&supplier=1"; }
	else									{ url=url+"&supplier=0"; }
	
	if(elseller.checked)				{ url=url+"&seller=1"; }
	else									{ url=url+"&seller=0"; }
	
	if(elbuyer.checked)				{ url=url+"&buyer=1"; }
	else									{ url=url+"&buyer=0"; }
	
	if(elimporter.checked)			{ url=url+"&importer=1"; }
	else									{ url=url+"&importer=0"; }
	
	if(elexporter.checked)			{ url=url+"&exporter=1"; }
	else									{ url=url+"&exporter=0"; }
	
	if(elserviceprovider.checked)	{ url=url+"&serviceprovider=1"; }
	else									{ url=url+"&serviceprovider=0"; }
	
	if(elagent.checked)				{ url=url+"&agent=1"; }
	else									{ url=url+"&agent=0"; }
	
	url=url+"&year="+elyear.options[elyear.selectedIndex].value;
	url=url+"&noe="+elnoe.options[elnoe.selectedIndex].value;
	url=url+"&sales="+elsales.options[elsales.selectedIndex].value;
	
	
	url=url+"&code="+encodeURIComponent(elcode.value);
	
	if(elagree.checked)
		{		
			url=url+"&agree=1";
		}
	else
		{
			url=url+"&agree=0";
		}
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=function() { verify_edit_account(); }
	xmlHttp.open("POST",urltosend,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-Length", url.length);
	xmlHttp.setRequestHeader("Connection", "close"); 
	xmlHttp.send(url);

}

function verify_edit_account() 
{ 
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	responses=xmlHttp.responseText.split('#ER#');
	
	elerrors1=locate_el('errors1');
	elerrors2=locate_el('errors2');
	elerrors3=locate_el('errors3');
	elerrors4=locate_el('errors4');
	elerrors5=locate_el('errors5');
	elerrors6=locate_el('errors6');
	elerrors7=locate_el('errors7');
	elerrors8=locate_el('errors8');
	
	elnewaccbox=locate_el('newaccbox');

	
	if((responses[0]=='OK') || (responses[0]=='NOTOK'))
		{
			if(responses[0]=='OK')
				{
					elnewaccbox.innerHTML=responses[1];
				}
			
			if(responses[0]=='NOTOK')
				{
					elerrors1.innerHTML=responses[1];
				}
		}
	else
		{
			if(responses[0]!='No errors')
				{
					elerrors1.innerHTML=responses[0];
				}
			else
				{
					elerrors1.innerHTML='';	
				}
			if(responses[1]!='No errors')
				{
					elerrors2.innerHTML=responses[1];
				}
			else
				{
					elerrors2.innerHTML='';	
				}
			if(responses[2]!='No errors')
				{
					elerrors3.innerHTML=responses[2];
				}
			else
				{
					elerrors3.innerHTML='';	
				}
			if(responses[3]!='No errors')
				{
					elerrors4.innerHTML=responses[3];
				}
			else
				{
					elerrors4.innerHTML='';	
				}
			if(responses[4]!='No errors')
				{
					elerrors5.innerHTML=responses[4];
				}
			else
				{
					elerrors5.innerHTML='';	
				}
			if(responses[5]!='No errors')
				{
					elerrors6.innerHTML=responses[5];
				}
			else
				{
					elerrors6.innerHTML='';	
				}
				
			if(responses[6]!='No errors')
				{
					elerrors7.innerHTML=responses[6];
				}
			else
				{
					elerrors7.innerHTML='';	
				}
				
			if(responses[7]!='No errors')
				{
					elerrors8.innerHTML=responses[7];
				}
			else
				{
					elerrors8.innerHTML='';	
				}
		}
		
		window.scroll(0, 0);
}
}



// Password recovery
function recover_password()
{
	elemail=locate_el('email');
	elcode=locate_el('code');

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/recoverpassword.php";
	url=url+"?email="+elemail.value;
	url=url+"&code="+elcode.value;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=verify_recover_password;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function verify_recover_password()
{ 
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	responses=xmlHttp.responseText.split('#ER#');
	elerrors1=locate_el('errors1');
	elerrors3=locate_el('errors3');
	elpassword_recovery_box=locate_el('password_recovery_box');

	
	if((responses[0]=='OK') || (responses[0]=='NOTOK'))
		{
			if(responses[0]=='OK')
				{
					elpassword_recovery_box.innerHTML=responses[1];
				}
			
			if(responses[0]=='NOTOK')
				{
					elerrors1.innerHTML=responses[1];
				}
		}
	else
		{
			if(responses[0]!='No errors')
				{
					elerrors1.innerHTML=responses[0];
				}
			else
				{
					elerrors1.innerHTML='';	
				}
			if(responses[1]!='No errors')
				{
					elerrors3.innerHTML=responses[1];
				}
			else
				{
					elerrors3.innerHTML='';	
				}
		}
}
}


// timer
//
function starttimer(ucn)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/req_timer.php";
	url=url+"?ucn="+ucn;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=updatetimer;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updatetimer()
{
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	response=xmlHttp.responseText;

	elucn=locate_el('ucntime');
	
	eladdingpics=locate_el('timer', window.parent.document);
	
	
	eladdingpics.innerHTML=response;
	
	setTimeout('starttimer("'+elucn.value+'")',1000);
}
}







//display brands
function req_brands()
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	  
	eltype=locate_el('category');
	elcatsel=locate_el('subcatsel');
	 
	var url="./actions/req_brands.php";
	url=url+"?category="+eltype.options[eltype.selectedIndex].value;
	url=url+"&catsel="+elcatsel.value;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=display_brands; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function display_brands()
{
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	response=xmlHttp.responseText;

	elmarca=locate_el('subcategoryelement');
	
	elmarca.innerHTML=response;
req_subcats()
}
}

//display brands
function req_subcats()
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	  
	eltype=locate_el('subcategory');
	elcatsel=locate_el('subsubcatsel');
	 
	var url="./actions/req_subcats.php";
	url=url+"?subcategory="+eltype.options[eltype.selectedIndex].value;
	url=url+"&catsel="+elcatsel.value;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=display_subcats;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function display_subcats()
{
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	response=xmlHttp.responseText;

	ewlmarca=locate_el('subsubcategoryelement');
	
	ewlmarca.innerHTML=response;
	
	
}
}


function req_position()
{
	elcatsel=locate_el('catsel');	
	elsubcatsel=locate_el('subcatsel');

	if(elcatsel.value!=0)
	  	{
				req_brands();
		}

}



//display pictures
function req_images(ucn)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/req_images.php";
	url=url+"?ucn="+ucn;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=display_pictures;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


//display extra pictures
function req_images_extra(ucn)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/req_images_extra.php";
	url=url+"?ucn="+ucn;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=display_pictures;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



//display extra pictures
function req_images_user(ucn)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/req_images_user.php";
	url=url+"?ucn="+ucn;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=display_pictures;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}




//delete pictures
function delpic(ofid, pid)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/delpic.php";
	url=url+"?ofid="+ofid;
	url=url+"&pid="+pid;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=display_pictures;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



//delete extra pictures
function delpic_extra(ofid, pid)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/delpic_extra.php";
	url=url+"?ofid="+ofid;
	url=url+"&pid="+pid;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=display_pictures;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



//delete extra pictures
function delpic_user(ofid, pid)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/delpic_user.php";
	url=url+"?ofid="+ofid;
	url=url+"&pid="+pid;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=display_pictures;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function display_pictures()
{
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	response=xmlHttp.responseText;

	eladdingpics=locate_el('addingpics', window.parent.document);
	
	
	eladdingpics.innerHTML=response;
}
}





//addbookmark
function acc_add_bookmark(ucn)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="./actions/addbookmark.php";
	url=url+"?ucn="+ucn;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=refreshbookmarks;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function refreshbookmarks()
{
if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	hideajaxloader();
	response=xmlHttp.responseText;

	elbookmarks_items=locate_el('bookmarks_items', window.parent.document);
	eladdbooklink=locate_el('addbooklink', window.parent.document);
	
	eladdbooklink.innerHTML='<div id="bookmarks_addedok">Added to favorites...</div>';
	elbookmarks_items.innerHTML=response;
}
}




// Accommodation offer editing
function editoffer()
{
	elucn=locate_el('ucn');
	elcategory=locate_el('category');
	elsubcategory=locate_el('subcategory');
	elsubsubcategory=locate_el('subsubcategory');
	eltitle=locate_el('titlex');
	elprice=locate_el('price');
	elcurency=locate_el('curency');
	elshortdesc=locate_el('shortdesc');
	elkeywords=locate_el('keywords');
	eldsm=locate_el('dsm');
	
	eldatastop=locate_el('datastop');
	

	
	PrepareSave();
	eldescription=locate_el('DataTextarea');

	
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var urltosend="./actions/editoffer.php";
	var url='';
	url=url+"ucn="+elucn.value;
	url=url+"&category="+elcategory.options[elcategory.selectedIndex].value;
	url=url+"&subcategory="+elsubcategory.options[elsubcategory.selectedIndex].value;
	url=url+"&subsubcategory="+elsubsubcategory.options[elsubsubcategory.selectedIndex].value;
	url=url+"&title="+encodeURIComponent(eltitle.value);
	url=url+"&price="+encodeURIComponent(elprice.value);
	url=url+"&curency="+elcurency.options[elcurency.selectedIndex].value;
	url=url+"&description="+encodeURIComponent(eldescription.value);
	url=url+"&shortdesc="+encodeURIComponent(elshortdesc.value);
	url=url+"&keywords="+encodeURIComponent(elkeywords.value);
	url=url+"&dsm="+eldsm.value;
	if(eldsm.value==1)
		{
			url=url+"&datastop="+eldatastop.options[eldatastop.selectedIndex].value;
		}




	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=function() { verify_editoffer(); }
	xmlHttp.open("POST",urltosend,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-Length", url.length);
	xmlHttp.setRequestHeader("Connection", "close"); 
	xmlHttp.send(url);
}

function verify_editoffer() 
{ 

if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	window.scroll(0, 0);
	hideajaxloader();
	responses=xmlHttp.responseText.split('#ER#');
	elerrors1=locate_el('errors1');
	elerrors2=locate_el('errors2');
	elerrors3=locate_el('errors3');
	elerrors4=locate_el('errors4');
	elerrors5=locate_el('errors5');
	elucn=locate_el('ucn');
	elnpid=locate_el('npid');
	eladdofferbox=locate_el('addofferbox');

	
	if((responses[0]=='OK') || (responses[0]=='NOTOK'))
		{
			if(responses[0]=='OK')
				{
					//eladdofferbox.innerHTML=responses[1];
					window.location='edit-my-offer-attributes?npid='+elnpid.value;
				}
			
			if(responses[0]=='NOTOK')
				{
					elerrors1.innerHTML=responses[1];
				}
		}
	else
		{
			if(responses[0]!='No errors')
				{
					elerrors1.innerHTML=responses[0];
				}
			else
				{
					elerrors1.innerHTML='';	
				}
			if(responses[1]!='No errors')
				{
					elerrors2.innerHTML=responses[1];
				}
			else
				{
					elerrors2.innerHTML='';	
				}
			if(responses[2]!='No errors')
				{
					elerrors3.innerHTML=responses[2];
				}
			else
				{
					elerrors3.innerHTML='';	
				}
			if(responses[3]!='No errors')
				{
					elerrors4.innerHTML=responses[3];
				}
			else
				{
					elerrors4.innerHTML='';	
				}
		}
}
}







// Accommodation extra offer editing
function editoffer_extra()
{
	elucn=locate_el('ucn');
	elcity=locate_el('city');
	elcategory=locate_el('category');
	elmaplocation=locate_el('maplocation');
	elextratitle=locate_el('extratitle');
	
	PrepareSave();
	eldescription=locate_el('DataTextarea');

	eltelephone=locate_el('telephone');
	elemail=locate_el('email');
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var urltosend="./actions/editoffer_extra.php";
	var url='';
	url=url+"ucn="+elucn.value;
	url=url+"&city="+elcity.options[elcity.selectedIndex].value;
	url=url+"&category="+elcategory.options[elcategory.selectedIndex].value;
	url=url+"&maplocation="+encodeURIComponent(elmaplocation.value);
	url=url+"&extratitle="+encodeURIComponent(elextratitle.value);
	url=url+"&description="+encodeURIComponent(eldescription.value);
	url=url+"&telephone="+encodeURIComponent(eltelephone.value);
	url=url+"&email="+encodeURIComponent(elemail.value);
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=verify_editoffer_extra;
	xmlHttp.open("POST",urltosend,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-Length", url.length);
	xmlHttp.setRequestHeader("Connection", "close"); 
	xmlHttp.send(url);
}

function verify_editoffer_extra() 
{ 

if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	window.scroll(0, 0);
	hideajaxloader();
	responses=xmlHttp.responseText.split('#ER#');
	elerrors1=locate_el('errors1');
	elerrors2=locate_el('errors2');
	elerrors3=locate_el('errors3');
	elerrors4=locate_el('errors4');
	elerrors5=locate_el('errors5');
	elucn=locate_el('ucn');
	eladdofferbox=locate_el('addofferbox');

	
	if((responses[0]=='OK') || (responses[0]=='NOTOK'))
		{
			if(responses[0]=='OK')
				{
					eladdofferbox.innerHTML=responses[1];
				}
			
			if(responses[0]=='NOTOK')
				{
					elerrors1.innerHTML=responses[1];
				}
		}
	else
		{
			if(responses[0]!='No errors')
				{
					elerrors1.innerHTML=responses[0];
				}
			else
				{
					elerrors1.innerHTML='';	
				}
			if(responses[1]!='No errors')
				{
					elerrors2.innerHTML=responses[1];
				}
			else
				{
					elerrors2.innerHTML='';	
				}
			if(responses[2]!='No errors')
				{
					elerrors3.innerHTML=responses[2];
				}
			else
				{
					elerrors3.innerHTML='';	
				}
			if(responses[3]!='No errors')
				{
					elerrors4.innerHTML=responses[3];
				}
			else
				{
					elerrors4.innerHTML='';	
				}
			if(responses[4]!='No errors')
				{
					elerrors5.innerHTML=responses[4];
				}
			else
				{
					elerrors5.innerHTML='';	
				}
		}
}
}




// Accommodation extra offer editing
function editcomp()
{
	elucn=locate_el('ucn');
	elcity=locate_el('city');
	eladdress=locate_el('address');
	elcompany=locate_el('company');

	PrepareSave();
	eldescription=locate_el('DataTextarea');

	eltelephone=locate_el('telephone');
	elfax=locate_el('fax');
	elemail=locate_el('email');
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var urltosend="./actions/editcomp.php";
	var url='';
	url=url+"ucn="+elucn.value;
	url=url+"&city="+elcity.options[elcity.selectedIndex].value;
	url=url+"&address="+encodeURIComponent(eladdress.value);
	url=url+"&company="+encodeURIComponent(elcompany.value);
	url=url+"&description="+encodeURIComponent(eldescription.value);
	url=url+"&telephone="+encodeURIComponent(eltelephone.value);
	url=url+"&fax="+encodeURIComponent(elfax.value);
	url=url+"&email="+encodeURIComponent(elemail.value);
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=verify_editcomp;
	xmlHttp.open("POST",urltosend,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-Length", url.length);
	xmlHttp.setRequestHeader("Connection", "close"); 
	xmlHttp.send(url);
}

function verify_editcomp() 
{ 

if (xmlHttp.readyState!=4)
{
	showajaxloader();
}
if (xmlHttp.readyState==4)
{
	window.scroll(0, 0);
	hideajaxloader();
	responses=xmlHttp.responseText.split('#ER#');
	elerrors1=locate_el('errors1');
	elerrors2=locate_el('errors2');
	elerrors3=locate_el('errors3');
	elerrors4=locate_el('errors4');
	elerrors5=locate_el('errors5');
	elucn=locate_el('ucn');
	eladdofferbox=locate_el('addofferbox');

	
	if((responses[0]=='OK') || (responses[0]=='NOTOK'))
		{
			if(responses[0]=='OK')
				{
					eladdofferbox.innerHTML=responses[1];
				}
			
			if(responses[0]=='NOTOK')
				{
					elerrors1.innerHTML=responses[1];
				}
		}
	else
		{
			if(responses[0]!='No errors')
				{
					elerrors1.innerHTML=responses[0];
				}
			else
				{
					elerrors1.innerHTML='';	
				}
			if(responses[1]!='No errors')
				{
					elerrors2.innerHTML=responses[1];
				}
			else
				{
					elerrors2.innerHTML='';	
				}
			if(responses[2]!='No errors')
				{
					elerrors3.innerHTML=responses[2];
				}
			else
				{
					elerrors3.innerHTML='';	
				}
			if(responses[3]!='No errors')
				{
					elerrors4.innerHTML=responses[3];
				}
			else
				{
					elerrors4.innerHTML='';	
				}
			if(responses[4]!='No errors')
				{
					elerrors5.innerHTML=responses[4];
				}
			else
				{
					elerrors5.innerHTML='';	
				}
		}
}
}




