var win = null;
var selectedPhoto = 1;

function refreshParteneri() {
	document.location.replace("parteneri.php");
}

function NewWindow(mypage,myname,w,h,scroll){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no,';
      settings +='dependent=yes';

  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function loadBigPhotos(id) {
	NewWindow('/detalii-foto.php?id=' + id + '&sel=' + selectedPhoto, 'detalii', '730', '650', 'no');
}

function checkPrieten() {
	if (document.formPrieten.numeprieten.value == "") {
		alert("Freund Name ist Pflichtfeld !");
		return false;
	}
	
	if (document.formPrieten.emailprieten.value == "") {
		alert("Freund E-mail ist auch Pflichtfeld !");
		return false;
	}
	
	if (document.formPrieten.emailprieten.value != "" && !isEmail(document.formPrieten.emailprieten.value)) {
		alert("Bitte tragen Sie eine gültige E-mail Adresse ein !");
		return false;
	}
	
	if (document.formPrieten.nume.value == "") {
		alert("Ihre Name ist Pflichtfeld !");
		return false;
	}
	
	if (document.formPrieten.email.value == "") {
		alert("Ihre E-Mail Adresse ist Pflichtfeld !");
		return false;
	}
	
	if (document.formPrieten.email.value != "" && !isEmail(document.formPrieten.emailprieten.value)) {
		alert("Bitte tragen Sie eine gültige E-mail Adresse ein !");
		return false;
	}
	
	return true;
}

function openPdf(mypage) {
	mypage =  mypage + "&link_img=" + document.getElementById("picbig").src;  
	mypage = mypage.replace("/text/","/normal/");  
	document.location.href = mypage;
}

function NewPdfWindow(mypage,myname,w,h,scroll){
	
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no,';
      settings +='dependent=yes';
      
  mypage =  mypage + "&link_img=" + document.getElementById("picbig").src;  
  mypage = mypage.replace("/text/","/normal/");  
  
  win=window.open(mypage,myname,settings);     
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}     
}

function checkmail(email_param)
{
	var emailcheck;	
	
	emailcheck = eval("document." + email_param + ".value");	
	
	if (emailcheck != "" && !isEmail(emailcheck)) {
		alert("Bitte tragen Sie eine gültige E-mail Adresse ein !");
		return false;
	}
	else
	{			
	document.alerta.action="/alerta-email.php";
	document.alerta.submit();	
	}
	
}


function stergeFavorite()
{
	
	var anunturi_selectate = getSelected_fav();
	var cookie_name;
	
	anunt_array = anunturi_selectate.split("#");
	
	if (anunturi_selectate == "")
	{
		alert ("Um Fahrzeuge aus dem Parkplatz zu entfernen, bitte mindestens eine auswählen !");	
	}
	else
	{
		intreb = confirm('Sind Sie einverstanden alle Fahrzeuge aus dem Parkplatz zu entfernen ?');
		
		if (intreb) 
		{			
				cookie_name =  Get_Cookie('favorites');
				cookie_split = cookie_name.split("#");
				Delete_Cookie('favorites', '/', ''); 	
				cookie_name = "";
							
				for (j=0; j<cookie_split.length-1; j++)
					{
					contor=0;
					for (i=0; i<anunt_array.length-1; i++)
						{								
								if (cookie_split[j].indexOf(anunt_array[i])!=-1)
								{									
									contor=1;									
								}									
						}		
					if (contor==0)
							{
							  cookie_name = cookie_name + cookie_split[j]+"#";								  							  
							}
					}	
											
			if (cookie_name == "")
			{
				Delete_Cookie('favorites', '/', ''); 	
			}				
			else 
			{
				Set_Cookie('favorites', cookie_name, '365', '/', '', '') ;								
			}
			
			document.location.href = "anunturi-favorite.php";			
		}  
		
				
	
		
	}
		
		return false;
		
}

		var nrmoto = 0;
		var nrauto = 0;
		

function Corect_Cookie(paramid)
{
	cookie_name =  Get_Cookie('favorites');		
	cookie_name = cookie_name.replace(paramid+"#", "");	
	Set_Cookie('favorites', cookie_name, '365', '/', '', '') ;
}


function getSelected_fav()
{
		var strChecked = "";
		
		for (i = 0; i < document.formFavorite.checkboxgroup.length-1; i++) {
			if (document.formFavorite.checkboxgroup[i].checked == true)
			{				
				strChecked = strChecked + document.formFavorite.checkboxgroup[i].value + "#";
				if (document.formFavorite.checkboxgroup[i].title=="auto") {nrauto+=1;}
				if (document.formFavorite.checkboxgroup[i].title=="moto") {nrmoto+=1;}
			}
		}				
		return strChecked;	
}



function select_checkbox_fav(num)
{		
		if (document.formFavorite.checkboxgroup[num].checked==true) 
			{
					document.formFavorite.checkboxgroup[num].checked=false;
			}
			else
			{
				document.formFavorite.checkboxgroup[num].checked=true;
			}
		
		return false;
}



function compara_fav()
{
	nrmoto = 0;
	nrauto = 0;
	var anunturi_selectate = getSelected_fav();
	var url_compara = "";
	
	if ((nrauto!=0) && (nrmoto!=0)&&(nrauto>1)&&(nrmoto>1))
	{
		iRet =confirm("Compararea se poate face doar intre vehicule de acelasi tip.\n            Ati selectat "+nrauto+" masini si " + nrmoto+" motociclete.\nPentru comparare masini OK <--> CANCEL pentru comparare motociclete !")
		if (iRet)	
			{ 
			url_compara = "compara-anunturi.php?";
			}
		else
			{
			url_compara = "compara-anunturi-moto.php?";
			}
	}
	else 	
	{
	
		if (nrauto < nrmoto) 
			{ 
			url_compara = "compara-anunturi-moto.php?";
			}
		else
			{
			url_compara = "compara-anunturi.php?";
			}
	}	
	
	if ((nrauto!=0) && (nrmoto!=0)&&(nrauto==1)&&(nrmoto==1))
		{
		alert ("Pentru a compara anunturi, trebuie sa selectati cel putin 2 din acelasi tip de vehicule !");	
		return false;
		}
	
	
	
	anunt_array = anunturi_selectate.split("#");
	
	
	if ( anunt_array.length < 3 )
	{
		alert ("Pentru a compara anunturi, trebuie sa selectati cel putin 2 !");	
	}
	else
	{
		for (i=0; i<anunt_array.length-1; i++)
		{
			if (i!=0)	{ url_compara = url_compara + "&";	}		
			url_compara = url_compara + "id" + (i+1) + "=" + anunt_array[i];
		}			
		
		document.location.href=url_compara;		
	}
	
	return false;
	
}






function getSelected()
{
		var strChecked = "";
		for (i = 1; i < document.rezultate.checkboxgroup.length; i++) {
			if ((document.rezultate.checkboxgroup[i].checked == true) && (document.rezultate.checkboxgroup[i].value != "on"))
			{				
				strChecked = strChecked + document.rezultate.checkboxgroup[i].value + "#";
			}
		}
		return strChecked;	
}



function addFavorites()
{
	var anunturi_selectate = getSelected();
	var cookie_name;
	
	anunt_array = anunturi_selectate.split("#");
	
	if (anunturi_selectate == "")
	{
		alert ("Um Fahrzeuge zu parken, bitte mindesten eine Anzeige auswählen !");	
	}
	else
	{
			if (!Get_Cookie('favorites'))
			{
				Set_Cookie('favorites', anunturi_selectate, '365', '/', '', '') ;				
			}
			else
			{
				cookie_name =  Get_Cookie('favorites');
				
				for (i=0; i<anunt_array.length-1; i++)
				{
						if (cookie_name.indexOf(anunt_array[i])=="-1")
					  cookie_name = cookie_name + anunt_array[i]+"#";	
				}		
				Set_Cookie('favorites', cookie_name, '365', '/', '', '') ;
			}	
		
			intreb = confirm('Ausgewählte Anzeigen wurden geparkt ! \n                Wollen Sie den Parkplatz jetzt sehen ?');
		
			if (intreb) 
			{				
				document.location.href = "anunturi-favorite.php";			
			}  
			
	}
	
	return false;
	
}

function compara()
{
	var anunturi_selectate = getSelected();
	var url_compara = "compara-anunturi.php?";
	
	anunt_array = anunturi_selectate.split("#");
	
	
	if ( anunt_array.length < 3 )
	{
		alert ("Für Vergleich bitte mindesten 2 Anzeigen auswählen !");	
	}
	else
	{
		for (i=0; i<anunt_array.length-1; i++)
		{
			if (i!=0)	{ url_compara = url_compara + "&";	}		
			url_compara = url_compara + "id" + (i+1) + "=" + anunt_array[i];
		}			
		
		document.location.href=url_compara;
	}
	
	return false;
	
}

function comparaMoto()
{
	var anunturi_selectate = getSelected();
	var url_compara = "compara-anunturi-moto.php?";
	
	anunt_array = anunturi_selectate.split("#");
	
	
	if ( anunt_array.length < 3 )
	{
		alert ("Für Vergleich bitte mindesten 2 Anzeigen auswählen !");	
	}
	else
	{
		for (i=0; i<anunt_array.length-1; i++)
		{
			if (i!=0)	{ url_compara = url_compara + "&";	}		
			url_compara = url_compara + "id" + (i+1) + "=" + anunt_array[i];
		}			
		
		document.location.href=url_compara;
	}
	
	return false;
	
}

function comparaCamioane()
{
	var anunturi_selectate = getSelected();
	var url_compara = "compara-camioane.php?";
	
	anunt_array = anunturi_selectate.split("#");
	
	
	if ( anunt_array.length < 3 )
	{
		alert ("Für Vergleich bitte mindesten 2 Anzeigen auswählen !");	
	}
	else
	{
		for (i=0; i<anunt_array.length-1; i++)
		{
			if (i!=0)	{ url_compara = url_compara + "&";	}		
			url_compara = url_compara + "id" + (i+1) + "=" + anunt_array[i];
		}			
		
		document.location.href=url_compara;
	}
	
	return false;
	
}

function select_checkbox(num)
{
		if (document.rezultate.checkboxgroup[num].checked==true) 
			{
					document.rezultate.checkboxgroup[num].checked=false;
			}
			else
			{
				document.rezultate.checkboxgroup[num].checked=true;
			}
		
		return false;
}


function select_all(sender) {
	var i;
	
	if (document.rezultate.checkboxgroup[0].checked)
		newvalup = true;
	else newvalup = false;
	if (document.rezultate.checkboxgroup[document.rezultate.checkboxgroup.length - 1].checked)
		newvaldown = true;
	else newvaldown = false;
	
	switch (sender) {
		case "checkup": {
			for (i = 1; i < document.rezultate.checkboxgroup.length; i++) {
				document.rezultate.checkboxgroup[i].checked = !newvalup;
			}
			break;
		}
		case "checkdown": {
			for (i = 0; i < document.rezultate.checkboxgroup.length - 1; i++) {
				document.rezultate.checkboxgroup[i].checked = !newvaldown;
			}
			break;
		}
		case "linkup": {
			for (i = 0; i < document.rezultate.checkboxgroup.length; i++) {
				document.rezultate.checkboxgroup[i].checked = !newvalup;
			}
			break;
		}
		case "linkdown": {
			for (i = 0; i < document.rezultate.checkboxgroup.length; i++) {
				document.rezultate.checkboxgroup[i].checked = !newvaldown;
			}
		}
	}
}


function generatePages(nrOfPages, baseLink, viewedPage, startPage) {
	afisString = "<td width=80 style=\"color:#115A8F;text-align:left;\">Seite:</td>";
	if (viewedPage == "") viewedPage = 1;
	if (startPage == "") startPage = 1;
	document.getElementById("divpagini").innerHTML = "";
	document.getElementById("paginijos").innerHTML = "";
	if (viewedPage == "1")
		afisString += "<td width=23 style='color:#000000;'>|<<</td>";
	else
		afisString += "<td width=23><a href='"+baseLink+"1'>|<<</a></td>";
	
	if (nrOfPages - startPage < 8)
		startPage = nrOfPages - 7;
	
	if (startPage == "1")
		afisString += "<td width=23 style='color:#000000;'><</td>";
	else
		afisString += "<td width=23><a href=\"#\" onClick=\"return generatePages('"+nrOfPages+"','"+baseLink+"','"+viewedPage+"','"+(parseInt(startPage)-1)+"')\"><</a></td>";
	i = startPage;
	
	while (i < parseInt(startPage) + 8) {
		if (i == viewedPage) viewer = "<td width=23>"+i+"</td>";
		else viewer = "<td width=23><a href='"+baseLink+i+"'>"+i+"</a></td>";
		afisString += viewer;
		i++;
	}
	
	if (i-1 == nrOfPages)
		afisString += "<td width=23 style='color:#000000;'>></td>";
	else afisString += "<td width=23><a href=\"#\" onClick=\"return generatePages('"+nrOfPages+"','"+baseLink+"','"+viewedPage+"','"+(parseInt(startPage)+1)+"')\">></a></td>";
	
	if (viewedPage == nrOfPages)
		afisString += "<td width=23 style='color:#000000;'> >>|</td>";
	else afisString += "<td width=23><a href='"+baseLink+""+nrOfPages+"'>>>|</a></td>";
	document.getElementById("divpagini").innerHTML = "<table style=\"color:#FF0000;text-align:center;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;font-weight:bold;\"><tr>"+afisString+"</tr></table>";
	document.getElementById("paginijos").innerHTML = "<table style=\"color:#FF0000;text-align:center;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;font-weight:bold;\"><tr>"+afisString+"</tr></table>";
	
	return false;
}



function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}



// Returns true if string s is empty or 
// whitespace characters only.
var whitespace = " \t\n\r";
function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}



function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}


function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function feedbackOk() {
	with (document.feedback) {
		if (mailsender.value == "" || !isEmail(mailsender.value)) {
			alert('Tragen Sie bitte eine gültige E-Mail Adresse ein !');
			return false;
		}
		if (message.value == "") {
			alert('Bemerkungen sind wichtig für uns !');
			return false;
		}
		
		alert ("Ihre Nachricht wurde gesendet ! Sie werden Antwort in Kürze erhalten.");
		return true;
	}
}