﻿function load()
{}

var xProvince = 'xProvince';
var xAddComment = "xComment";

function closeDiv(whichDiv)
{
		var d = document.getElementById(whichDiv);
		if ( d != null)
		{
 		    document.body.removeChild(d);
		    var d2 = document.getElementById('shadow');
 		    document.body.removeChild(d2);
		    if (whichDiv=='divDiscuss')
		    {
			    //Detect Safari Browser
			    var vUserAgement = navigator.userAgent;
			    myString = vUserAgement;
			    rExp = /Safari/gi;
			    results = myString.search(rExp);
    			
			    if (results=="-1") {
				    window.location.reload();
			    }
		    }
		}
}

function callBackProvince(txt)
{
	//           ID          width   height  left  top
	creatediv(xProvince,txt,"200px","250px","0px","60px")
}

function callBackProvince(txt)
{
	//           ID          width   height  left  top
	creatediv(xProvince,txt,"200px","250px","0px","60px")
}

function callBackAddComment(txt, p_divID)
{
    creatediv(p_divID,txt,"400px","100px","0px","60px")
}

function popDiv(p_id,p_callback)
{
    if (!document.getElementById(p_id, p_callback))
	{
		loadXMLDocPopDiv('xml/' + p_id + '.xml?t=1', p_callback,p_id);
	}
	else
	{
		closeDiv(p_id);
	}
}

function callBackComment(txt)
{
   // alert(txt);
    closeDiv('popComment');
    window.location.href=window.location.href;
    
    
}
function addComment()
{
    var comment = document.getElementById("chrComment").value;
    		
    loadXMLDocV2('callAjax/addComment.aspx?chrComment=' + comment, callBackComment )

}



function popProvince()
{
    
	if (!document.getElementById(xProvince))
	{
		loadXMLDocV2('/xml/' + xProvince + '.xml?t=1', callBackProvince )
	}
	else
	{
		closeDiv(xProvince)
	}
}

function creatediv(id,html,width,height,left,top)
{
	var newdiv = document.createElement('div');
	var monContent=""
	newdiv.setAttribute('id',id);
	if(width)
	{
		newdiv.style.width = width;
	}
	if(height)
	{
		newdiv.style.height = height;
	}
	if((left || top)||(left && top))
	{
		newdiv.style.position = "absolute";
		if(left)
		{
			newdiv.style.left = "50%";
			
			monWidth=parseInt(width);
			maMarge=(monWidth-(monWidth*2))/2
			maMarge=""+maMarge+"px";
			newdiv.style.marginLeft = maMarge;
			
		}
		if(top)
		{
			newdiv.style.top = top;
		}
	}
	newdiv.style.background = "#FFFFFF";
	newdiv.style.border = "2px solid #98fb98";
	newdiv.style.padding = "35px";
	newdiv.style.zIndex = 99;
	//newdiv.style.overflow = "auto";
	newdiv.style.PageBreakInside = "avoid";
	if(id=='divPrint')
	{
	
	}
	else
	{
		monContent += "<div style='font-size:14px; color:#000000;'>" + html + "</div>";
	}
	
	//ajoute un X pour fermer la fenetre
	positionX=parseInt(width)+50;
	var id2 = '"' + id + '"';

	monContent += "<div style='position:absolute; top:5px; left:"+positionX+"px;'><a href='#' onClick='closeDiv("+id2+")' style='text-decoration:none; color:#ffd4dd; font-size:11px; font-weight:bold;'>X</a></div>"
	

	newdiv.innerHTML=monContent;
	document.body.appendChild(newdiv);
	if (id!="divPrint") createShadow(id);
	if (id=="divPrint") imprime();
}

function createShadow(id)
{
	var left = document.getElementById(id).style.left;
	var top = document.getElementById(id).style.top;
	var width = document.getElementById(id).style.width;
	var height = document.getElementById(id).style.height;
	var marginLeft = document.getElementById(id).style.marginLeft;
	
	//Offset pour le shadow
	top=parseInt(top)+5;
	top=top+'px';
	marginLeft=parseInt(marginLeft);
	marginLeft+=5;
	marginLeft=marginLeft+'px';
	
	/*alert (left)
	alert (top)
	alert (width)
	alert (height)*/
	
	var newdiv2 = document.createElement('div');
	newdiv2.setAttribute('id','shadow');
	newdiv2.style.position = "absolute";
	if(width)
	{
		newdiv2.style.width = width;
	}
	if(height)
	{
		newdiv2.style.height = height;
	}
	if(left)
	{
		newdiv2.style.left = left;
	}
	if(top)
	{
		newdiv2.style.top = top;
	}
	if(marginLeft)
	{
		newdiv2.style.marginLeft = marginLeft;
	}
	newdiv2.style.padding = "35px";
	newdiv2.style.border = "6px solid #000000";
	newdiv2.style.background = "#000000";
	newdiv2.style.zIndex = 98;
	
	newdiv2.style.opacity = '.1'
	newdiv2.style.filter = 'alpha(opacity=10)';
	
	document.body.appendChild(newdiv2);
}


// GOOGLE MAP FONCTION

function callBackGMap(txt)
{
	//           ID          width   height  left  top
	creatediv('popGoogleMap',txt,"200px","50px","0px","60px")
}


function popGMap()
{   
	if (!document.getElementById('popGoogleMap'))
	{
		loadXMLDocV2('xml/googlemap.xml?t=1', callBackGMap);
	}
	else
	{
		closeDiv('popGoogleMap');
	}
}

function addGoogleMap()
{
    var priority = document.getElementById("ddPriority").value;
    alert(location.href);
    loadXMLDocV2('callAjax/util.aspx?gsm=1&location=' + location.href + '&priority=' + priority, callBackGoogle )

}

function callBackGoogle(txt)
{   
    closeDiv('popGoogleMap');
}

// RSS 
function popRss()
{   
	if (!document.getElementById('popRss'))
	{
		loadXMLDocV2('xml/rss.xml?t=1', callBackRSS);
	}
	else
	{
		closeDiv('popRss');
	}
}


function callBackRSS(txt)
{
	creatediv("popRss",txt,"500px","350px","0px","60px")
	document.getElementById("rssTitle").value=  document.title;
	document.getElementById("rssLink").value=  location.href;
	
}