function showImage(language_id, gallery_id, image_id){
  newWindow = window.open("images.php?lang=" + language_id + "&g_id=" + gallery_id + "&i_id=" + image_id, "Images",  "SCROLLBARS=YES, RESIZABLE=YES, WIDTH=640, HEIGHT=310");
  newWindow.focus();
}

function mailing_subscribe(email) {
	new ajax ('mailing_list.php', {postBody: 'email='+email, update: $('box_mailing')});
	
}



function infoMail(id) {
  newInfoWindow = window.open("povprasevanje.php?realestate_id=" + id, "Info", "RESIZABLE=YES, WIDTH=500, HEIGHT=570");
  newInfoWindow.focus();
}


function showImage(image_id){
  newWindow = window.open("slike.php?image_id=" + image_id, "Pomoč",  "SCROLLBARS=NO, RESIZABLE=YES, WIDTH=360, HEIGHT=280");
  newWindow.focus();
}


function PreveriVnos() {
	strKvadratura=document.frmIskalnik.kvadratura.value ;
	strCena=document.frmIskalnik.cena.value ;
	if (isNaN(strKvadratura)==true) {alert("Vrednost v polju 'Kvadratura' ni veljavno ±tevilo!");}
	else if (isNaN(strCena)==true) {alert("Vrednost v polju 'Cena' ni veljavno ±tevilo!");}
	else {document.frmIskalnik.submit(); }
}


/* AJAX */

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

}

function mailbox_updater() {
	if(xmlHttp.readyState==4) {
		if (xmlHttp.responseText == '0') {
			document.getElementById("box_mailing_info").innerHTML="<strong class=\"errorMsg\">Vneseni e-mail naslov je neveljaven!</strong>";
			document.m_form.email.value="";
		} else if (xmlHttp.responseText == '1') {
			document.getElementById("box_mailing_info").innerHTML="<p>E-mail naslov je bil dodan na mailing listo.</p>";
			document.getElementById("box_mailing_frm").innerHTML="";
		} else if (xmlHttp.responseText == '2') {
			document.getElementById("box_mailing_info").innerHTML="<p>E-mail naslov je bil odstranjen iz mailing liste.</p>";
			document.getElementById("box_mailing_frm").innerHTML="";
		} else {
			// Do nothing
		}
	}
}

function add_member() {
	
	if (document.getElementById("box_mailing_info")) document.getElementById("box_mailing_info").innerHTML="";
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	email = document.m_form.email.value;
	
	var url="mailing_list.php";
	url=url+"?email="+email;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=mailbox_updater;
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	
}

function remove_member() {
	
	if (document.getElementById("box_mailing_info")) document.getElementById("box_mailing_info").innerHTML="";
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	email = document.m_form.email.value;

	var url="mailing_list.php";
	url=url+"?email="+email;
	url=url+"&task=remove";
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=mailbox_updater;
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

// GALLERY
function gallery_load_image(g_id, i_id) {
	
	document.getElementById("photo_gallery_image").innerHTML="<div id=\"photo_gallery_loader\"><img src=\"template/images_gallery/loading.gif\"></div>";
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	
	var url="gallery_image.php";
	url=url+"?g_id="+g_id;
	url=url+"&i_id="+i_id;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=gallery_image_updater;
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	
}

function gallery_image_updater() {
	if(xmlHttp.readyState==4) {
		if (xmlHttp.responseText != '') {
			document.getElementById("photo_gallery_image").innerHTML=xmlHttp.responseText;
		} else {
			document.getElementById("photo_gallery_image").innerHTML="Error!";
		}
	}
}

// CENIKI
function change_product(p_id, lang) {
	document.getElementById("search").disabled= true;

	change_product_widths(p_id);
	change_product_lengths(p_id);
	change_product_image(p_id);
}


function change_product_widths(p_id) {
	
	xmlHttp_1 = GetXmlHttpObject();
	if (xmlHttp_1==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	var url="plist_widths.php";
	url=url+"?p_id="+p_id;
	url=url+"&sid="+Math.random();
	xmlHttp_1.onreadystatechange=change_product_widths_updater;
	xmlHttp_1.open("GET", url, true);
    xmlHttp_1.send(null);
	
}

function change_product_widths_updater() {
	if(xmlHttp_1.readyState==4) {
		if (xmlHttp_1.responseText != '') {
			document.getElementById("plist_wd").innerHTML=xmlHttp_1.responseText;			
		} else {
			document.getElementById("plist_wd").innerHTML="Error!";
		}
	}
}

function change_product_lengths(p_id) {
	
	xmlHttp_2 = GetXmlHttpObject();
	if (xmlHttp_2==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	var url="plist_lengths.php";
	url=url+"?p_id="+p_id;
	url=url+"&sid="+Math.random();
	xmlHttp_2.onreadystatechange=change_product_lengths_updater;
	xmlHttp_2.open("GET", url, true);
    xmlHttp_2.send(null);
	
	// change_product_image(p_id);
	
}

function change_product_lengths_updater() {
	if(xmlHttp_2.readyState==4) {
		if (xmlHttp_2.responseText != '') {
			document.getElementById("plist_ln").innerHTML=xmlHttp_2.responseText;
		} else {
			document.getElementById("plist_ln").innerHTML="Error!";
		}
	}
}

function change_product_image(p_id) {
	
	document.getElementById("plist_img").innerHTML="<div id=\"plist_img\"><img src=\"template/images_gallery/loading.gif\"></div>";
	
	xmlHttp_3 = GetXmlHttpObject();
	if (xmlHttp_3==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	
	var url="plist_image.php";
	url=url+"?p_id="+p_id;
	url=url+"&sid="+Math.random();
	xmlHttp_3.onreadystatechange=change_product_image_updater;
	xmlHttp_3.open("GET", url, true);
    xmlHttp_3.send(null);
	
}

function change_product_image_updater() {
	if(xmlHttp_3.readyState==4) {
		if (xmlHttp_3.responseText != '') {
			document.getElementById("plist_img").innerHTML=xmlHttp_3.responseText;
			document.getElementById("search").disabled= false;
		} else {
			document.getElementById("plist_img").innerHTML="Error!";
		}
	}
}