/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var responseConfirmation = false;
var deleteAll = false;

// Methodes XMLHTTPRequest
// Methode Update du contenu
function doUpdate(div,page,params) {
        $.ajax({
		   type: "GET",
		   url: page,
           data: params,
		   dataType:"html",
            error: function(xhr) {
                //$(div).html(msg);
                $(div).html(xhr.responseText);
            },
            success: function(data){
                $(div).html(data);
            }
        }).responseText;
}

// Methode Request
function doRequest(page,params) {
        $.ajax({
		   type: "GET",
           data: params,
		   url: page,
		   error: function(xhr) {
               alert(xhr.responseText);
				//$(div).html(msg);
                //$(div).html(xhr.responseText);
            }
        });
}
/**
 * Cette fonction met à jour l'onglet "général" des réglages d'une file d'attente,
 * en fonction des informations présentes dans les entrées cachées du document HTML.
 */
/* Fonctions complementaires */
function doAlert(div, msg) {
    $(div).dialog('open');
    $(div).html(msg);
}
/* Fonctions complementaires */
function doConfirm(div, msg) {
    $(div).dialog('open');
    $(div).html(msg);
}

function switchUL(div,index) {
    nb_li = 1;
    navRoot = document.getElementById(div);
    for (i=0; i<navRoot.childNodes.length; i++) {
        node = navRoot.childNodes[i];
        if (node.nodeName=="LI") {
            if (nb_li == index) {
                node.className += "selected";
				document.getElementById(div + "_img" + nb_li).src="../icones/state.png";
            } else {
                node.className=node.className.replace("selected", "");
				document.getElementById(div + "_img" + nb_li).src="../icones/empty.png";
            }
            nb_li++;
        }
    }
}

/*******************************************************************************
 *                               Tooltips JQuery                               *
 *******************************************************************************/
this.screenshotPreview = function(){   
        /* CONFIG */
               
                xOffset = 10;
                yOffset = 30;
               
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result
               
        /* END CONFIG */
        $("a.screenshot").hover(function(e){
                this.t = this.title;
                this.title = "";       
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");                                                                
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");                                               
    },
        function(){
                this.title = this.t;   
                $("#screenshot").remove();
    }); 
        $("a.screenshot").mousemove(function(e){
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                    
};
this.imagePreview = function(){ 
        /* CONFIG */
               
                xOffset = 10;
                yOffset = 30;
               
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result
               
        /* END CONFIG */
        $("a.preview").hover(function(e){
                this.t = this.title;
                this.title = "";       
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");                                                                
                $("#preview")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");                                               
    },
        function(){
                this.title = this.t;   
                $("#preview").remove();
    }); 
        $("a.preview").mousemove(function(e){
                $("#preview")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                    
};
this.tooltip = function(){     
        /* CONFIG */           
                xOffset = 10;
                yOffset = 20;          
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result            
        /* END CONFIG */               
        $("div.tooltip").hover(function(e){
                this.t = this.title;
                this.title = "";                                                                         
                $("body").append("<p id='tooltip'>"+ this.t +"</p>");
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");               
    },
        function(){
                this.title = this.t;           
                $("#tooltip").remove();
    }); 
        $("div.tooltip").mousemove(function(e){
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                    
};

//Tooltip end.
/*******************************************************************************/



function initializeSolutions(link) {
	if (link == '') {
    	doUpdate("#main_content_left","solutions.php",null)
	} else if (link == 'cumulus_server') {
    	doUpdate("#main_content_left","cumulus_server.php",null)
	} else if (link == 'cumulus_editions') {
    	doUpdate("#main_content_left","cumulus_editions.php",null)
	} else if (link == 'canto_su') {
    	doUpdate("#main_content_left","canto_su.php",null)
	} else if (link == 'canto_su_en') {
    	doUpdate("#main_content_left","canto_su_en.php",null)
	} else if (link == 'solutions_idea7') {
    	doUpdate("#main_content_left","solutions_idea7.php",null)
	} else if (link == 'indexerpro') {
    	doUpdate("#main_content_left","indexerpro.php",null)
	} else if (link == 'dicomcataloging') {
    	doUpdate("#main_content_left","dicomcataloging.php",null)
	} else if (link == 'websuite') {
    	doUpdate("#main_content_left","websuite.php",null)
	} else if (link == 'wspro') {
    	doUpdate("#main_content_left","websuite/wspro.php",null)
	} else if (link == 'wslog') {
    	doUpdate("#main_content_left","websuite/wslog.php",null)
	} else if (link == 'wsorder') {
    	doUpdate("#main_content_left","websuite/wsorder.php",null)
	} else if (link == 'wsrecordsfiltering') {
    	doUpdate("#main_content_left","websuite/wsrecordsfiltering.php",null)
	} else if (link == 'wsactionfiltering') {
    	doUpdate("#main_content_left","websuite/wsactionfiltering.php",null)
	} else if (link == 'wsadvancedsearch') {
    	doUpdate("#main_content_left","websuite/wsadvancedsearch.php",null)
	} else if (link == 'wsadvancedsearch_en') {
    	doUpdate("#main_content_left","websuite/wsadvancedsearch_en.php",null)
	} else if (link == 'wsvideo') {
    	doUpdate("#main_content_left","websuite/wsvideo.php",null)
	} else if (link == 'wsvideo_en') {
    	doUpdate("#main_content_left","websuite/wsvideo_en.php",null)
	} else if (link == 'solutions_idea7_en') {
    	doUpdate("#main_content_left","solutions_idea7_en.php",null)
	} else if (link == 'indexerpro_en') {
    	doUpdate("#main_content_left","indexerpro_en.php",null)
	} else if (link == 'dicomcataloging_en') {
    	doUpdate("#main_content_left","dicomcataloging_en.php",null)
	} else if (link == 'websuite_en') {
    	doUpdate("#main_content_left","websuite_en.php",null)
	} else if (link == 'wspro_en') {
    	doUpdate("#main_content_left","websuite/wspro_en.php",null)
	} else if (link == 'wslog_en') {
    	doUpdate("#main_content_left","websuite/wslog_en.php",null)
	} else if (link == 'wsorder_en') {
    	doUpdate("#main_content_left","websuite/wsorder_en.php",null)
	} else if (link == 'wsrecordsfiltering_en') {
    	doUpdate("#main_content_left","websuite/wsrecordsfiltering_en.php",null)
	} else if (link == 'wsactionfiltering_en') {
    	doUpdate("#main_content_left","websuite/wsactionfiltering_en.php",null)
	} else if (link == 'sudus') {
    	doUpdate("#main_content_left","sudus.php",null)
	} else if (link == 'fsiviewer') {
    	doUpdate("#main_content_left","fsiviewer.php",null)
	} else if (link == 'fsipages') {
    	doUpdate("#main_content_left","fsiviewer/fsipages.php",null)
	} else if (link == 'fsishowcase') {
    	doUpdate("#main_content_left","fsiviewer/fsishowcase.php",null)
	} else if (link == 'fsiskins') {
    	doUpdate("#main_content_left","fsiviewer/fsiskins.php",null)
	} else if (link == 'helios') {
    	doUpdate("#main_content_left","helios.php",null)
	} else if (link == 'helioscompanion') {
    	doUpdate("#main_content_left","helios/helioscompanion.php",null)
	} else if (link == 'topicasa') {
    	doUpdate("#main_content_left","ejap/topicasa.php",null)
	} else if (link == 'topicasa_en') {
    	doUpdate("#main_content_left","ejap/topicasa_en.php",null)
	} else if (link == 'toflickr') {
    	doUpdate("#main_content_left","ejap/toflickr.php",null)
	} else if (link == 'toflickr_en') {
    	doUpdate("#main_content_left","ejap/toflickr_en.php",null)
	} else if (link == 'exportfields') {
    	doUpdate("#main_content_left","ejap/exportfields.php",null)
	} else if (link == 'exportfields_en') {
    	doUpdate("#main_content_left","ejap/exportfields_en.php",null)
	} else if (link == 'susight') {
    	doUpdate("#main_content_left","ejap/susight.php",null)
	} else if (link == 'susight_en') {
    	doUpdate("#main_content_left","ejap/susight_en.php",null)
	} else if (link == 'fsiviewer2cumulus') {
    	doUpdate("#main_content_left","fsiviewer2cumulus.php",null)
	} else if (link == 'fsiviewer2cumulus_en') {
    	doUpdate("#main_content_left","fsiviewer2cumulus_en.php",null)
	}
}

function initializeResources(link,product,params) {
	if (link == '') {
    	doUpdate("#main_content_left","resources.php",null)
	} else if (link == 'online') {
    	doUpdate("#main_content_left","form_online.php",null)
	} else if (link == 'download') {
    	doUpdate("#main_content_left","form_download.php?product=" + product,null)
	} else if (link == 'phone') {
    	doUpdate("#main_content_left","form_phone.php?product=" + product,null)
	} else if (link == 'datasheet') {
    	doUpdate("#main_content_left","form_datasheet.php?product=" + product,null)
	} else if (link == 'configurator') {
    	doUpdate("#main_content_left","form_configurator.php", null)
	} else if (link == 'send') {
    	doUpdate("#main_content_left","form_send.php",params);
	} else if (link.indexOf('thank_en') > -1) { //Doit etre place avant
    	doUpdate("#main_content_left","form_thanks_en.php","type=" + link);
	} else if (link.indexOf('thank') > -1) {
    	doUpdate("#main_content_left","form_thanks.php","type=" + link);
	} else if (link == 'datasheet_en') {
    	doUpdate("#main_content_left","form_datasheet_en.php?product=" + product,null)
	} else if (link == 'download_en') {
    	doUpdate("#main_content_left","form_download_en.php?product=" + product,null)
	} else if (link == 'send_en') {
    	doUpdate("#main_content_left","form_send_en.php",params);
	}
}

function initializeServices(link) {
	if (link == '') {
    	doUpdate("#main_content_left","services.php",null);
	} else if (link == 'installation') {
    	doUpdate("#main_content_left","installation.php",null);
	} else if (link == 'maintenance') {
    	doUpdate("#main_content_left","maintenance.php",null);
	} else if (link == 'formation') {
    	doUpdate("#main_content_left","formation.php",null);
	} else if (link == 'personnalisation') {
    	doUpdate("#main_content_left","personnalisation.php",null);
	}
}

function initializeCompany(link,n) {
	if (link == '') {
    	doUpdate("#main_content_left","company.php",null);
	} else if (link == 'contact') {
    	doUpdate("#main_content_left","contact.php",null);
	} else if (link == 'missions') {
    	doUpdate("#main_content_left","missions.php",null);
	} else if (link == 'news') {
    	doUpdate("#main_content_left","news.php","n=" + n);
	} else if (link == 'clients') {
    	doUpdate("#main_content_left","clients.php",null);
	} else if (link == 'legal') {
    	doUpdate("#main_content_left","legal.php",null);
	} else if (link == 'plansite') {
    	doUpdate("#main_content_left","plansite.php",null);
	} else if (link == 'event_200910') {
    	doUpdate("#main_content_left","form_event200910.php",null)
	} else if (link.indexOf('thank') > -1) {
    	doUpdate("#main_content_left","form_thanks_event.php",null);
	}
}

function initializePartners(link,params) {
	if (link == '') {
    	doUpdate("#main_content_left","partners.php",null);
	} else if (link == 'become') {
    	doUpdate("#main_content_left","become.php",null);
	} else if (link == 'send') {
    	doUpdate("#main_content_left","send.php",params);
	} else if (link == 'thanks') {
    	doUpdate("#main_content_left","thanks.php",null);
	}
}

function startDownload(params,lang) {
	var msg = 'Téléchargement en cours.';
	if (lang == 'en') msg = "Download in progress";
		
	doAlert("#popupDialog", msg);
	$('#invisibleIFrame').attr('src',"../support/download_auto.php?"+params);
}

function downloadDatasheet(params,msg) {
   	doUpdate("#invisibleDiv","../support/download_datasheet.php","d=" + params);
	doAlert("#popupDialog", msg);
}

function goSearch(value) {
	var params = "sp_a=sp10042ec4";
	params = params + "&sp_p=all";
	params = params + "&sp_f=ISO-8859-1";
	params = params + "&sp_q=" + value;
    doUpdate("#main_content_left","http://search.atomz.com/search/",params);
}

function controlRegister() {
	var isOK = true;
	if ($('#webkey').val() == '') {
		doAlert("#popupDialog", webkeyError);
		isOK = false;
	} else if ($('#serialnumber').val() == '') {
		doAlert("#popupDialog", serialnumberError);
		isOK = false;
	} else if ($('#productid').val() =='') {
		doAlert("#popupDialog", productidError);
		isOK = false;
	}	
    
    if (isOK) {
	    var params = "k=" + encodeURIComponent($('#webkey').val());
	    params += "&s=" + encodeURIComponent($('#serialnumber').val());
	    params += "&h=" + encodeURIComponent($('#hardwareid').val());
	    params += "&p=" + encodeURIComponent($('#productid').val());
	    doUpdate("#main_content_left","customersu_generate.php",params);
    }
}

function controlSend() {
	var isOK = true;
	var msg = "";
	if ($('#company').val() == '') {
		msg += companyError + "<br/>";
		isOK = false;
	}
	if ($('#salutation').val() == '--') {
		msg += salutationError + "<br/>";
		isOK = false;
	}
	if ($('#first_name').val() == '') {
		msg += firstnameError + "<br/>";
		isOK = false;
	}
	if ($('#last_name').val() =='') {
		msg += lastnameError + "<br/>";
		isOK = false;
	}
	if ($('#email').val() =='') {
		msg +=  emailError + "<br/>";
		isOK = false;
	}
	if ($('#email').val() != $('#confirm_email').val()) {
		msg +=  emailNotMatchError + "<br/>";
		isOK = false;
	}
	if ($('#confirm_email').val() =='') {
		msg +=  emailError + "<br/>";
		isOK = false;
	}
	if ($('#phone').val() =='') {
		msg +=  phoneError + "<br/>";
		isOK = false;
	}	
	if ($('#country').val() =='') {
		msg +=  countryError + "<br/>";
		isOK = false;
	}	
	if ($('#department').val() =='--') {
		msg +=  departmentError + "<br/>";
		isOK = false;
	}	
	if ($('#plateforme').val() =='--') {
		msg +=  plateformeError + "<br/>";
		isOK = false;
	}	
	if ($('#manage').val() =='--') {
		msg +=  manageConfiguratorError + "<br/>";
		isOK = false;
	}	
	if ($('#catalog_publish').val() =='--') {
		msg +=  publishingConfiguratorError + "<br/>";
		isOK = false;
	}	
	/*if ($('#product').val() =='--') {
		msg +=  productError + "<br/>";
		isOK = false;
	}*/	
	
	if ($('#type').val() == 'download') {
		if ($('#product').val() =='--') {
			msg +=  downloadError + "<br/>";
			isOK = false;
		}	
	}
	
	if ($('#type').val() == 'datasheet') {
		if ($('#product').val() =='--') {
			msg +=  datasheetError + "<br/>";
			isOK = false;
		}	
	}

	if ($('#type').val() == 'online') {
		if ($('#product').val() =='--') {
			msg +=  onlineError + "<br/>";
			isOK = false;
		}	
	}

	if (isOK) {
	    var params = "company=" + encodeURIComponent($('#company').val());
	    params += "&salutation=" + encodeURIComponent($('#salutation').val());
	    params += "&title=" + encodeURIComponent($('#title').val());
    	params += "&first_name=" + encodeURIComponent($('#first_name').val());
	    params += "&last_name=" + encodeURIComponent($('#last_name').val());
	    params += "&street=" + encodeURIComponent($('#street').val());
		params += "&zip=" + encodeURIComponent($('#zip').val());
    	params += "&city=" + encodeURIComponent($('#city').val());
	    params += "&phone=" + encodeURIComponent($('#phone').val());
	    params += "&email=" + encodeURIComponent($('#email').val());
	    params += "&country=" + encodeURIComponent($('#country').val());
	    params += "&state=" + encodeURIComponent($('#state').val());
	    params += "&department=" + encodeURIComponent($('#department').val());
	    params += "&department-other=" + encodeURIComponent($('#department-other').val());
	    params += "&comments=" + encodeURIComponent($('#comments').val());
	    params += "&plateforme=" + encodeURIComponent($('#plateforme').val());
	    params += "&product=" + encodeURIComponent($('#product').val());
	    params += "&00N20000001Es2o=" + encodeURIComponent($('#00N20000001Es2o').val());
	    params += "&00N20000001Ziva=" + encodeURIComponent($('#00N20000001Ziva').val());
	    params += "&type=" + encodeURIComponent($('#type').val());
		if ($('#type').val() == 'configurator') {
			params += "&manage=" + encodeURIComponent($('#manage').val());
			params += "&catalog_publish=" + encodeURIComponent($('#catalog_publish').val());
			params += "&users_cataloging=" + encodeURIComponent($('#users_cataloging').val());
			params += "&users_viewing=" + encodeURIComponent($('#users_viewing').val());
			params += "&users_read=" + encodeURIComponent($('#users_read').val());
			params += "&workflow=" + encodeURIComponent($('#workflow').val());
			params += "&integrate=" + encodeURIComponent($('#integrate').val());
			params += "&extended=" + encodeURIComponent($('#extended').val());
		}
		doUpdate("#main_content_left","form_send.php",params);
    } else {
		doAlert("#popupDialog", msg);
	}
}

function controlSendEvent() {
	var isOK = true;
	var msg = "";
	if ($('#company').val() == '') {
		msg += companyError + "<br/>";
		isOK = false;
	}
	if ($('#first_name').val() == '') {
		msg += firstnameError + "<br/>";
		isOK = false;
	}
	if ($('#last_name').val() =='') {
		msg += lastnameError + "<br/>";
		isOK = false;
	}
	if ($('#email').val() =='') {
		msg +=  emailError + "<br/>";
		isOK = false;
	}
	if ($('#phone').val() =='') {
		msg +=  phoneError + "<br/>";
		isOK = false;
	}	
	if ($('#personne').val() =='') {
		msg +=  personneError + "<br/>";
		isOK = false;
	}	
    
    if (isOK) {
	    var params = "company=" + encodeURIComponent($('#company').val());
	    params += "&salutation=" + encodeURIComponent($('#salutation').val());
    	params += "&first_name=" + encodeURIComponent($('#first_name').val());
	    params += "&last_name=" + encodeURIComponent($('#last_name').val());
	    params += "&phone=" + encodeURIComponent($('#phone').val());
	    params += "&email=" + encodeURIComponent($('#email').val());
	    params += "&personne=" + encodeURIComponent($('#personne').val());
	    params += "&comments=" + encodeURIComponent($('#comments').val());
	    params += "&product=" + encodeURIComponent($('#product').val());
	    params += "&type=event";
		doUpdate("#main_content_left","form_send_event.php",params);
    } else {
		doAlert("#popupDialog", msg);
	}
}


