/* =========================================================================== */
/* Javascript Librairie Pixelo ets, last update : 19 - 10 - 2007
*/

/* == Client Window Object =================================================== */

function ClientWindow() {
/* == CONSTRUCTEUR :: init navigator type & size window == */

	if (navigator.appName=="Netscape"){
	this.height = window.innerHeight;
	this.width = window.innerWidth;
	this.typePosition = 'fixed';
	}
	else if (navigator.appName=="Microsoft Internet Explorer"){
		if(document.body.scrollHeight <= document.body.clientHeight){
			this.height = document.body.clientHeight;}
		else{	this.height = document.body.scrollHeight;}
		if(document.body.scrollWidth <= document.body.clientWidth){
			this.width = document.body.clientWidth;}
		else{	this.width = document.body.scrollWidth;}
	this.typePosition = 'absolute';
	}
	else{
	this.height = window.innerHeight;
	this.width = window.innerWidth;
	this.typePosition = 'fixed';
	}
	
/* == METHODE DE L'OBJET INIT == */
   this.getHeight = function() {
     return this.height;
   }
   
   this.getWidth = function() {
     return this.width;
   }
   
   this.getTypePosition = function() {
     return this.typePosition;
   }
}


/* == Div Up Fonction ======================================================== */

function divup(url){

/* == on instancie l'objet Init ============ */
	obj = new ClientWindow();
	
/* == on affiche la transparence =========== */
	var divup = document.getElementById("divup");
	if(!divup.style.display) divup.style.display = 'none';
	if(divup.style.display == 'none'){
		divup.style.height = obj.getHeight()+"px";
		divup.style.width = obj.getWidth()+"px";
		divup.style.position = obj.getTypePosition();
		divup.style.display = 'block';
	}
	else{
		divup.style.display = 'none';
	}
	
/* == on affiche le contenu ================= */
	var contentDivup = document.getElementById("contentDivup");
	contentDivup.style.width = '700px';
	/*contentDivup.style.height = '400px';*/
	var marg = (obj.getWidth()-700)/2+"px";
	contentDivup.style.marginLeft = marg;
	contentDivup.style.marginRight = marg;
	if(!contentDivup.style.display) contentDivup.style.display = 'none';
	if(contentDivup.style.display == 'none'){
		contentDivup.style.display = 'block';}
	else{
		contentDivup.innerHTML = "";
		contentDivup.style.display = 'none';}
	if(url){
		  var options = {
		    method: "post",
		    onLoading: function(xhr, obj) {document.getElementById("loading").style.display = 'block';},
		    onComplete: function(xhr, obj) {document.getElementById("loading").style.display = 'none';},
		    onSuccess: function(xhr, obj) {document.getElementById("loading").style.display = 'none';},
		    onFailure: function(xhr, obj) {}
		  };
		  var ajaxCall = new Ajax.Updater('contentDivup',url,options);
	}
}


/* == Ajax Custom Fonction =================================================== */
function MyAjaxPost(id,url,div){
  var options = {
	method: "post",
	asynchronous: true,
	contentType: 'application/x-www-form-urlencoded',
	encoding: 'utf-8',
	postBody: $(id).serialize(true),
	onLoading: function(xhr, obj) {},
	onComplete: function(xhr, obj) {},
	onSuccess:  function(xhr, obj) {},
	onFailure: function(xhr, obj) {},
	evalScripts:true
  };
  var ajaxCall = new Ajax.Updater(div,url,options);
}


function MyAjaxGet(url,div){
  var options = {
    method: "get",
    onLoading: function(xhr, obj) {},
    onComplete: function(xhr, obj) {},
    onSuccess:  function(xhr, obj) {},
    onFailure: function(xhr, obj) {},
    evalScripts:true
  };
  var ajaxCall = new Ajax.Updater(div,url,options);
}


/* == Confirm Fonction ======================================================= */

function JavaConfirm(link,mess) {
	if(confirm(mess)){
	document.location.href=link.href;}
	else {return false;}
}


/* == HightLight Fonction ==================================================== */

// remove the registerOverlay call to disable the controlbar
hs.registerOverlay(
{
	thumbnailId: null,
	overlayId: 'controlbar',
	position: 'top right',
	hideOnMouseOut: true
	}
);

hs.graphicsDir = '/ui/js/highslide/graphics/';
hs.outlineType = 'rounded-white';
window.onload = function() {
hs.preloadImages(5);
}

/* == Login Fonction ======================================================== */
function submit_login(form, url, div, evnt)
{
	if (evnt.which){ touche = evnt.which } else { if (evnt.keyCode){ touche = evnt.keyCode } else { touche = 0 }}
	if (touche == 13){MyAjaxPost(form,url,div);} else {return true;}
}
/* == Caddie Fonction ======================================================== */

function refresh_panier(action, id, url)
{
	switch (action)
	{
	  case 'add':
	    var url = url+"&qte="+id
	    MyAjaxGet(url,'panier_recap');
	   break;
	  case 'del':
	     MyAjaxGet(url,'panier_recap');
	    break;

	  default:
	   break;
	}
}
function refresh_panier_key(action, id, url, evnt)
{
	if (evnt.which){ touche = evnt.which } else { if (evnt.keyCode){ touche = evnt.keyCode } else { touche = 0 }}
	if (touche == 13){refresh_panier(action, id, url);} else {return true;}
}


/* == Google Map Fonction ===================================================== */

function createMyInfoWindow(point,html) {
	application.map.openInfoWindowHtml(point,html);
}
function createMyInfoWindow(point,html) {
	application.map.openInfoWindowHtml(point,html);
}
var markerCircle;
function underlineSpot(point) {
	var baseIcon = new GIcon();
	baseIcon.iconSize = new GSize(63, 63);
	baseIcon.iconAnchor = new GPoint(33, 33);
	var icon = new GIcon(baseIcon);
	icon.image = 'http://www.paraspot.com/ui/img/icon/cible.png';
	markerCircle = new GMarker(point, {draggable: false, icon: icon});
	application.map.addOverlay(markerCircle);
}
function deleteUnderline() {
	if(markerCircle){application.map.removeOverlay(markerCircle);}
}


/* == Textarea MaxSize ======================================================== */

function testclick(element){
if(element.value == 'Ecrivez en français'){element.value = '';}
if(element.value == 'Write in english'){element.value = '';}
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}


/* == FONCTION SCRIPTACULOUS SHOW DIV ========================================= */

var statDiv = [];

function showDiv(divId) {
  div=document.getElementById(divId);
  if(statDiv[divId] == false) {
	new Effect.BlindUp(div);
	statDiv[divId] = true;}
  else{new Effect.BlindDown(div);
	statDiv[divId] = false;}
}


/* == Upload File : ProgressBar ============================================== */

var URL_upload;
var errorUpload = false;
var barWidth;
var percent = new Array();
percent[0] = 0;
var percentI = 1;
var min=0;
var cen=0;
var sec=0;
var secTotal=0;
var chronoBool = false;

function chrono(){
	cen++;
	chronoBool = true;
	if(cen>9){cen=0; sec++; secTotal++;}
	if(sec>59){sec=0; min++;}
	if(errorUpload == false){$('timerUpload').innerHTML = 'time : '+min+' m '+sec+' s';}
	else {$('timerUpload').innerHTML = '';}
	setTimeout('chrono()',100);
}
function startUpload(URL) {
	URL_upload = URL;
	$('form_footer_upload').hide();
	$('upload_zone').hide();
	$('progressContent').style.display = 'block';
	if(chronoBool==false){chrono();}
	setTimeout("progressUpload()",1000);
}

function progressUpload() {
    var idProgress=document.getElementById("progress_key").value;
	new Ajax.Request(URL_upload+'ui/plugins/progressUpload.php?progress_key='+idProgress, {
	  method:'get',
	  onSuccess: function(transport){
	     var objRep=eval("("+transport.responseText+")");
	     // creer un tableau des pourcentages avec indice i.
	     percent[percentI] = (objRep.current/objRep.total)*100;
	if(errorUpload == false){
	     $('progressInfo').innerHTML = '<h3>File : '+objRep.filename+'</h3>';
	     $('percentUpload').innerHTML = ' '+percent[percentI].toFixed(2)+'%';
	     rateTransfert = (objRep.current/secTotal)/1000;
	     amountTransfered = objRep.current/1000000;
	     amountTransfered2 = objRep.total/1000000;
	     $('rateUpload').innerHTML = 'rate : '+rateTransfert.toFixed(2)+' Ko/s';
	     $('rateUpload').innerHTML += '<br/>amount : '+amountTransfered.toFixed(3)+' Mo / '+amountTransfered2.toFixed(3)+' Mo';
	}
	new Effect.Scale('progressBarIn', percent[percentI], {scaleX:true, scaleY:false, fps:25, duration: 1.2, scaleFrom: percent[percentI-1].toFixed(2), scaleMode: { originalHeight: 10, originalWidth: 300 }});
	     percentI++;
	     if((objRep.cancel_upload!=undefined) && (objRep.cancel_upload!=0) && (objRep.cancel_upload!=4)) {
		MyAjaxGet('/ui/plugins/ajax.php?a=error_upload','progressInfo');
		errorUpload = true;
		$('rateUpload').innerHTML = '';
		$('percentUpload').innerHTML = '';
		}
	     if(transport.responseText=='false'){
		MyAjaxGet('/ui/plugins/ajax.php?a=error_upload','progressInfo');
		errorUpload = true;
		$('rateUpload').innerHTML = '';
		$('percentUpload').innerHTML = '';
		}
	     if(objRep.done==0) { startUpload(URL_upload);}
	     if(objRep.cancel_upload==0){$('progressInfo').innerHTML = 'Wait ...';}
	   }
	});
}
function addInput(originalRequest)
{
		$('inputrecept').innerHTML += originalRequest.responseText;
		$('inputrecept').scrollTo();
}
function signalAjax(id){
	monImg=document.createElement("img");    
	monImg.src = "/ui/img/ajax/ajax_load_file.gif"; 
	monImg.alt = "";
	span=document.getElementById(id+"_signalAjax");
	span.appendChild(monImg);  
}

/* == Photo Description :: FORM ============================================== */

function sendPhotoForm(i){
	MyAjaxPost('photo'+i,'/ui/plugins/ajax.php?a=photoUpdate&i='+i,'photoDiv'+i);
	$('photo'+i).hide();
}

/* == Photo Description :: FORM ============================================== */

function sendVideoForm(){
	MyAjaxPost('video','/ui/plugins/ajax.php?a=videoUpdate','videoDiv');
	$('video').hide();
}

/* == Photo Description :: FORM ============================================== */

function sendMeteoForm(action){
	MyAjaxPost('meteoForm','/ui/plugins/ajax.php?a='+action,'meteoDiv');
}

/* == Rate mouseover ::  ============================================== */

function rateOver(i){
	for(var j = 1; j<=5 ; j++){
		//alert("i:"+i+" j:"+j);
		if(i<j)
			$('star_'+j).src = "/ui/img/rate_2.jpg";
		if(i>=j)
			$('star_'+j).src = "/ui/img/rate_1.jpg";
	}
}

function clearRate(){
	for(var j = 1; j<=5 ; j++){
		var imgsrc = $('star_'+j).className;
		$('star_'+j).src = "/ui/img/"+imgsrc;
	}
}
function rateDo(rate,idspot){
	MyAjaxGet('/ui/plugins/ajax.php?a=insert_rate_spot&rate='+rate+'&idSpot='+idspot,'rate_zone');
}
