var xmlHttp
var pxmlHttp
var status=0;
var curph=0;
var allph=0;
var max_height = 360;
var max_width = 660;

var propertyID= 0;
var lang = 0;
var photoID= 0;


function hideDivGallery(){
	document.getElementById("gallerycontent").style.display = "none";	
	document.getElementById("gallery").style.display = "none";
	document.getElementById("gallery").innerHTML="";
	document.getElementById("fonfix").style.display = "none";
	document.getElementById("conteiner").style.display = "none";	
	document.getElementById("content").style.display = "none";	
	document.getElementById("idclose").innerHTML="";

	var obj=document.getElementById("gallerycontent");	
	obj.style.display = "none";
	obj.style.width = 100+"px";
	obj.style.height = 100+"px";
	
	showSelectBoxes();
}

function showGallery(v_propertyID,v_lang,v_photoID,ind,cur_photo,all_photos,heightPic){

	hideSelectBoxes();
	
	var fondiv=document.getElementById("fonfix");	
	fondiv.style.display = "block";	
	
	var bwidth = document.documentElement.clientWidth;
	fondiv.style.width = bwidth+"px";		
	
	var bheight = document.body.scrollHeight;	
	bheight=bheight+15;
	fondiv.style.height = bheight+"px";		
	
	if(status!=ind) status=ind;
	if(ind==1) max_height=heightPic;
	
	if(curph!=cur_photo) curph=cur_photo;
	if(allph!=all_photos) allph=all_photos;
	
	if(propertyID!=v_propertyID) propertyID=v_propertyID;
	if(lang!=v_lang) lang=v_lang;
	if(photoID!=v_photoID) photoID=v_photoID;
	

	document.getElementById("conteiner").style.display = "block";	
	document.getElementById("gallerycontent").style.display = "block";		
	document.getElementById("gallery").style.display = "block";
	
	if(ind!=1) HeightDivDown(20);	
	OpGalleryDown(100,heightPic);
}

function SlideDive(heightPic){
	
	document.getElementById("gallery").innerHTML="";
		
	if(status==1){

		slideHeight(100);
	}
	else{			
		if(heightPic> max_height){
			slideHeightUp(heightPic,max_height);
		}
		else{
			slideHeightDown(heightPic,max_height);
		}		
	}
	if(max_height!=heightPic) max_height=heightPic;			
}

function galleryContent(){

	var loadDiv=document.getElementById("load");
	loadDiv.style.display = "block";
	loadDiv.height=max_height+"px";
	document.getElementById("load").innerHTML="<table height="+max_height+" cellspacing='0' cellpadding='0' border='0'><tr><td width="+max_width+" height='100%' align='center' valign='middle'><img src='images/indicator2.gif'></td></tr></table>";
	
	
	pxmlHttp=GetXmlHttpObject()
	if (pxmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	
	var url="gallerycontent.php"
	url=url+"?propertyID="+propertyID
	url=url+"&lang="+lang
	url=url+"&photoID="+photoID
	url=url+"&sid="+Math.random()
	pxmlHttp.onreadystatechange=stateChangedPic 
	pxmlHttp.open("GET",url,true)
	pxmlHttp.send(null)	
}

function stateChangedPic() 
{ 
	if (pxmlHttp.readyState==4 || pxmlHttp.readyState=="complete")
	{	
		document.getElementById("gallery").innerHTML=pxmlHttp.responseText 	
		ShowPic();
	}
}
function ShowPic(){
	document.getElementById("load").style.display = "none";
	
	var GalleryDiv=document.getElementById("gallery");
	GalleryDiv.style.display = "block";	
	
	setOpacity('tdgallery',100);
	TextGallery();
	
}

function TextGallery(){	
	document.getElementById("content").style.display="block";	
	HeightDivUp(0);
	setOpacity('textgall',100);
	setOpacity('idclose',100);	
	document.getElementById("textgall").innerHTML=curph+"/"+allph;
	document.getElementById("idclose").innerHTML="<span onclick='hideDivGallery();' class='gallclose'><img src='images/closelabel.gif'></span>";
}

//---------------------------------------------------------------------------------
function slideHeightUp(height,max_height){
	if (height > max_height) {
		max_height =(1*max_height) + 10;			
		obj = document.getElementById("gallerycontent");
		obj.style.height = max_height+"px";
		window.setTimeout("slideHeightUp("+height+","+max_height+")", 10);
	}	
	else{	
	
		galleryContent();
	}
}

function slideHeightDown(height,max_height){
	if (height < max_height) {		
		max_height =(1*max_height) - 10;			
		obj = document.getElementById("gallerycontent");
		obj.style.height = max_height+"px";
		window.setTimeout("slideHeightDown("+height+","+max_height+")", 10);
	}	
	else{	
		galleryContent();
	}
}

function slideHeight(height){
	if (height <= max_height) {
		height =(1*height) + 10;			
		obj = document.getElementById("gallerycontent");
		obj.style.height = height+"px";
		window.setTimeout("slideHeight("+height+")", 10);
	}
	else{		
		slide(100);
	}
}

function slide(width){
	if (width < max_width) {
		width =(1*width) + 10;
		obj = document.getElementById("gallerycontent");
		obj.style.width = width +"px";
		window.setTimeout("slide("+width+")", 5);
	}
	else{
		galleryContent();
	}
}

//-------------------------------------------------------------------

function HeightDivUp (heightDiv){

	if (heightDiv <30) {
		heightDiv =(1*heightDiv) + 10;		

		obj = document.getElementById("gallerycontent");
		var newHeight=max_height+heightDiv+10;		
		obj.style.height = newHeight +"px";		
				
		obj = document.getElementById("content");
		obj.style.height = heightDiv +"px";		
		window.setTimeout("HeightDivUp("+heightDiv+")", 20);
	}
}

function HeightDivDown (heightDiv){

	if (heightDiv > 10) {
		heightDiv =(1*heightDiv) - 10;	
		
		obj = document.getElementById("gallerycontent");
		var newHeight=max_height+heightDiv-10;		
		obj.style.height = newHeight +"px";	
		
		obj = document.getElementById("content");
		obj.style.height = heightDiv +"px";		
		window.setTimeout("HeightDivDown("+heightDiv+")", 20);
	}
	else{

		document.getElementById("content").style.display="none";
	}
}

function OpGalleryDown(opacity,heightPic) {
	if (opacity > 0) {
		opacity =(1*opacity) - 10;
		
		setOpacity('tdgallery',opacity);
		window.setTimeout("OpGalleryDown("+opacity+","+heightPic+")", 20);
	}
	else{
		SlideDive(heightPic);
	}
}

function OpGalleryUp(opacity){
	if (opacity < 80) {
		opacity =(1*opacity) + 10;
		setOpacity('tdgallery',opacity);
		window.setTimeout("OpGalleryUp("+opacity+")", 20);
	}
	else{	
		setOpacity('tdgallery',100);
		TextGallery();
	}
}

function setOpacity(id,opacity){
		obj = document.getElementById(id);
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;		
}
//--------------------------------------------------------
function init(id,propertyID){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request")
	  return
	  }
	var url="gethint.php"
	url=url+"?id="+id+"&propertyID="+propertyID
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("picHint").innerHTML=xmlHttp.responseText
 }
}


// ---------------------------------------------------

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}


//----------------------------------------------------------
function divOverPrev(prev){
	if(prev>0){		
		document.getElementById("prevlebl").style.display = "block";	
	}	
}

function divOutPrev(){
	document.getElementById("prevlebl").style.display = "none";	
}

function divOverNext(next){
	if(next>0){		
		document.getElementById("nextlebl").style.display = "block";
	}
}
function divOutNext(){
	document.getElementById("nextlebl").style.display = "none";	
}

//---------------------------------------------------------
function checkCapture(field){

	pxmlHttp=GetXmlHttpObject()
	if (pxmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	var url="checkcap.php"
	url=url+"?field="+field
	url=url+"&sid="+Math.random()
	pxmlHttp.onreadystatechange=stateChangedCap
	pxmlHttp.open("GET",url,true)
	pxmlHttp.send(null)	
}

function stateChangedCap() 
{ 
	if (pxmlHttp.readyState==4 || pxmlHttp.readyState=="complete")
	{
		capturecode=pxmlHttp.responseText 	
		if(capturecode != "0"){
			if (validateEmail  (document.forms.sell.clientEmail))  document.forms.sell.submit();
			else document.getElementById('emailCell').style.color='#b02d32';
			
			document.getElementById('secCode').style.color='#494949';
		}
		else{
			
			if(!validateEmail  (document.forms.sell.clientEmail)) {
				document.getElementById('emailCell').style.color='#b02d32';
			}
			else {
			 document.getElementById('emailCell').style.color='#494949';
			}
			document.getElementById('secCode').style.color='#b02d32';					
		}
	}
}


//---------------------------------------------
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;
}
