		/*
     General AJAX technique samples--how to talk to the server + return data and do stuff with it.
     Direct questions, answers, rants, flames to sbenfield@clearnova.com

      1.0: 2005-07-14   Initial Release
      1.1: 2005-07-15   Fixed bugs, changed text for clarity, added ability to register for updates
      1.2: 2005-07-21   Cleaned up samples for clarity. Original version was all over the board using all sorts of different ways of calling XMLHTTPRequest
                        This version is cleaner. Only ping uses its own custom AJAX handling, everything else uses AJAXRequest
			Added many many comments
			
     If you find any bugs or have any ideas of enhancement--send them on.
     
*/
     
var _ms_XMLHttpRequest_ActiveX = ""; // Holds type of ActiveX to instantiate
var _ajax;                           // Reference to a global XMLHTTPRequest object for some of the samples
var _logger = true;                  // write output to the Activity Log
var _status_area;                    // will point to the area to write status messages to

BASE_URL = "."
if ( document.location.href.indexOf("www.clearnova.com") > 0 ) {
	BASE_URL = "/ThinkCAP"
}

if (!window.Node || !window.Node.ELEMENT_NODE) {
    var Node = { ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5,
                  ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, 
    		  DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12 };
}

// From prototype.js @ www.conio.net | Returns an object reference to one or more strings
// ignore the fact that there are no arguments to this method -- javascript doesn't care how many you send (not strongly typed)
// The method checks the actual # of arguments -- returns a single object or an array
function $() {
    var elements = new Array();

    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];

        if (typeof element == 'string')
            element = document.getElementById(element);

        if (arguments.length == 1)
            return element;

        elements.push(element);
    }

    return elements;
}

// Method to get text from an XML DOM object
function getTextFromXML( oNode, deep ) {
    var s = "";
    var nodes = oNode.childNodes;

    for (var i = 0; i < nodes.length; i++) {
        var node = nodes[i];

        if (node.nodeType == Node.TEXT_NODE) {
            s += node.data;
        } else if (deep == true && (node.nodeType == Node.ELEMENT_NODE || node.nodeType == Node.DOCUMENT_NODE
                                       || node.nodeType == Node.DOCUMENT_FRAGMENT_NODE)) {
            s += getTextFromXML(node, true);
        };
    }

    ;
    return s;
}

;

// If you plan on doing anything outside of North America, then you'd better encode the things you pass back and forth
// the escape() method in Javascript is deprecated -- should use encodeURIComponent if available
function encode( uri ) {
    if (encodeURIComponent) {
        return encodeURIComponent(uri);
    }

    if (escape) {
        return escape(uri);
    }
}

function decode( uri ) {
    uri = uri.replace(/\+/g, ' ');

    if (decodeURIComponent) {
        return decodeURIComponent(uri);
    }

    if (unescape) {
        return unescape(uri);
    }

    return uri;
}

// log information to the status area textfield
function logger( text, clear ) {
    if (_logger) {
        if (!_status_area) {
            _status_area = document.getElementById("status_area");
        }

        if (_status_area) {
            if (clear) {
                _status_area.value = "";
            }

            var old = _status_area.value;
            _status_area.value = text + ((old) ? "\r\n" : "") + old;
        }
    }
}


/*
 * AJAXRequest: An encapsulated AJAX request. To run, call
 * new AJAXRequest( method, url, async, process, data )
 *
 */

function executeReturn( AJAX ) {
    if (AJAX.readyState == 4) {
        if (AJAX.status == 200) {
            logger('AJAXRequest is complete: ' + AJAX.readyState + "/" + AJAX.status + "/" + AJAX.statusText);
	    if ( AJAX.responseText ) {
		    logger(AJAX.responseText);
		    logger("-----------------------------------------------------------");
		    eval(AJAX.responseText);
	    }
	}
    }
}

function AJAXRequest( method, url, data, process, async, dosend) {
    // self = this; creates a pointer to the current function
    // the pointer will be used to create a "closure". A closure
    // allows a subordinate function to contain an object reference to the
    // calling function. We can't just use "this" because in our anonymous
    // function later, "this" will refer to the object that calls the function 
    // during runtime, not the AJAXRequest function that is declaring the function
    // clear as mud, right?
    // Java this ain't
    
    var self = this;

    // check the dom to see if this is IE or not
    if (window.XMLHttpRequest) {
	// Not IE
        self.AJAX = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
	// Hello IE!
        // Instantiate the latest MS ActiveX Objects
        if (_ms_XMLHttpRequest_ActiveX) {
            self.AJAX = new ActiveXObject(_ms_XMLHttpRequest_ActiveX);
        } else {
	    // loops through the various versions of XMLHTTP to ensure we're using the latest
	    var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                        "Microsoft.XMLHTTP"];

            for (var i = 0; i < versions.length ; i++) {
                try {
		    // try to create the object
		    // if it doesn't work, we'll try again
		    // if it does work, we'll save a reference to the proper one to speed up future instantiations
                    self.AJAX = new ActiveXObject(versions[i]);

                    if (self.AJAX) {
                        _ms_XMLHttpRequest_ActiveX = versions[i];
                        break;
                    }
                }
                catch (objException) {
                // trap; try next one
                } ;
            }

            ;
        }
    }
    
    // if no callback process is specified, then assing a default which executes the code returned by the server
    if (typeof process == 'undefined' || process == null) {
        process = executeReturn;
    }

    self.process = process;

    // create an anonymous function to log state changes
    self.AJAX.onreadystatechange = function( ) {
        //logger("AJAXRequest Handler: State =  " + self.AJAX.readyState);
        self.process(self.AJAX);
    }

    // if no method specified, then default to POST
    if (!method) {
        method = "POST";
    }

    method = method.toUpperCase();

    if (typeof async == 'undefined' || async == null) {
        async = true;
    }

    logger("----------------------------------------------------------------------");
    logger("AJAX Request: " + ((async) ? "Async" : "Sync") + " " + method + ": URL: " + url + ", Data: " + data);

    self.AJAX.open(method, url, async);

    if (method == "POST") {
        //self.AJAX.setRequestHeader("Connection", "close");
        self.AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        self.AJAX.setRequestHeader("Method", "POST " + url + "HTTP/1.1");
    }

    // if dosend is true or undefined, send the request
    // only fails is dosend is false
    // you'd do this to set special request headers
    if ( dosend || typeof dosend == 'undefined' ) {
	    if ( !data ) data=""; 
	    self.AJAX.send(data);
    }
    return self.AJAX;
}

// handle some key press events
function handleKeyUp( e ) {
    e = (!e) ? window.event : e;
    target = (!e.target) ? e.srcElement : e.target;

    if (e.type == "keyup") {
        // skip shift, alt, control keys
        if (e.keyCode == 16 || e.keyCode == 17 || e.keyCode == 18) {
        // do nothing
        }

        else {
            if (target.name == "state1" && !$('state1').value) {
                clearCustomersByState();
            } else if (target.name == "state2" && !$('state2').value) {
                clearCustomersByStateXML();
            } else if (target.name == "google_search") {
                if (target.value) {
                    getSuggest(target);
                } else {
                    $('google_suggest_target').innerHTML = "";
                }
            }
        }
    }
}



        //<!--
        var secs
        var timerID = null
        var timerRunning = false
        var delay = 1000

        function InitializeTimer()
        {
			
			var doc = document.URL;
			var ind = doc.indexOf("http://www.");
			if (ind == -1)
			{
				window.location="http://www.partirdiscount.com";
			}
            // Set the length of the timer, in seconds
            GetCurrentContent()
            secs = 10; // 3'tü ben değiştirdim - ilke
            StopTheClock()
            StartTheTimer()

        }
		function InitializeTimerAdmin(ProduitType)
        {
			var doc = document.URL;
			var ind = doc.indexOf("http://www.");
			if (ind == -1)
			{
				window.location="http://www.partirdiscount.com";
			}
            // Set the length of the timer, in seconds
            GetCurrentContentAdmin(ProduitType)
            secs = 10; // 3'tü ben değiştirdim - ilke
            StopTheClock()
            StartTheTimerAdmin(ProduitType)

        }

        function StopTheClock()
        {
            if(timerRunning)
                clearTimeout(timerID)
            timerRunning = false
        }

        function StartTheTimer()
        {
            if (secs==0)
            {
                StopTheClock()
                // Here's where you put something useful that's
                // supposed to happen after the allotted time.
                // For example, you could display a message:
                // alert("You have just wasted 10 seconds of your life.")
                GetCurrentContent();
				secs = 10;
				StartTheTimer();
	        // InitializeTimer();
            }
            else
            {
                // self.status = secs
                secs = secs - 1
                timerRunning = true
                timerID = self.setTimeout("StartTheTimer()", delay)
            }
        }
		
		
		function StartTheTimerAdmin(ProduitType)
        {
            if (secs==0)
            {
                StopTheClock()
                // Here's where you put something useful that's
                // supposed to happen after the allotted time.
                // For example, you could display a message:
                // alert("You have just wasted 10 seconds of your life.")
				ProduitType = ""
                GetCurrentContentAdmin(ProduitType);
				secs = 10;
				StartTheTimerAdmin(ProduitType);
	        // InitializeTimer();
            }
            else
            {
                // self.status = secs
                secs = secs - 1
                timerRunning = true
                timerID = self.setTimeout("StartTheTimerAdmin(" + ProduitType + ")", delay)
            }
        }
        //-->
        
        /* ****************************  Custom Zone  ************************** */ 
        /* ***************************  InstantPromo  ************************** */ 

			function GetCurrentContent(){
			var ajaxAleti = new AJAXRequest("POST", "/AjaxResponse/InstantPromo.asp", null
			, function() { }, false);
			
			var esasDiv = document.getElementById("zone_promo");
			esasDiv.innerHTML = ajaxAleti.responseText;
			
			//alert(esasDiv.innerHTML );
		}
		function GetCurrentContentAdmin(ProduitType)
		{
		URL = "/AjaxResponse/InstantPromoAdmin.asp"
		querystring = "?ProduitType=" + ProduitType
		
		var ajaxAleti = new AJAXRequest("POST", URL + querystring, null, function() { }, false); 
		var esasDiv = document.getElementById("zone_promo");
		esasDiv.innerHTML = ajaxAleti.responseText;

			
		//alert(esasDiv.innerHTML );
		}
		
		
		// function AJAXRequest( method, url, data, process, async, dosend)
		
		
		function GetContentToMail(){
			var i;
			var temp = new String("a");
			var HtmlContent = document.getElementById("contentRecap");

			text = HtmlContent.innerHTML;
			var modifiedstring = new String("") ;
			
			var index = 0;
			var countif =0;
			var countelse =0;
			var countloop= 0;
			
			for( i = 0; i <= text.length-1; i++)
			{
				if (text.charAt(i) == ' ' )
				{
					modifiedstring = modifiedstring.concat("#####");
					index=index+6;
					countif = countif+1;
				}
				
				else
				{
					modifiedstring = modifiedstring.concat(text.charAt(i));
//					modifiedstring.charAt(index) = text.charAt(i);
					index = index + 1;
					temp = temp.concat("a");
				}
			}
						
			var data = "data=" + modifiedstring;
			
			var URL = "/Mailer.asp";
			
			alert(modifiedstring);
			
			// PROBLEME
			var ajaxAleti = new AJAXRequest("POST", URL, data , function() {}, false);    
			//
			
			var esasDiv = document.getElementById("infospage");
			//esasDiv.innerHTML = ajaxAleti.responseText;
			
			alert(ajaxAleti.responseText);
		}	
				
		function ReloadPhotoAlbum(codeMarque, codeProduit, searchDeparture, nPhoto, nCentre){
			var ajaxAleti = new AJAXRequest("POST", "/1DiaporamaProduit.asp?codeMarque=" + codeMarque + "&codeProduit=" + codeProduit + "&searchDeparture=" + searchDeparture + "&nPhoto=" + nPhoto + "&nCentre=" + nCentre, null, function() { }, false);
			
			var esasDiv = document.getElementById("diaporama");
			esasDiv.innerHTML = ajaxAleti.responseText;
//			alert(esasDiv.innerHTML );
		}
		
	function GetSearchFlashOptions() {
        	
			var searchField = document.getElementById("searchCodeProduit");
			var postData = "searchCodeProduit" + searchField.value
			
			searchField = document.getElementById("searchCodeMarque");
			postData += "&searchCodeMarque=" + searchField.value;
			
			searchField = document.getElementById("searchType");
			postData += "&searchType=" + searchField.value;
			
			searchField = document.getElementById("searchCodeVilleDepart");
			postData += "&searchCodeVilleDepart=" + searchField.value;
			
		
        /* ***************************  SearchOptions  ************************** */ 
			
			var ajaxAleti = new AJAXRequest("POST", "/AjaxResponse/SearchProduits.asp", postData, function() {}, false);
			var searchForm = document.getElementById("ProduitCount");
			searchForm.innerHTML = ajaxAleti.responseText;
    }
		
		function GetSearchOptions() {
        	var minutes = 1000*60;
			var hours = minutes*60;
			var days = hours*24;
			var years = days*365;
			
			var d = new Date();
			var CurrentDate = d.getTime();
			var CurrentYear = Math.round(CurrentDate/years);
			var SelectedYear = 1970 + CurrentYear;

			var searchField = document.getElementById("searchDestination");
			var postData = "searchDestination=" + searchField.value
			
			searchField = document.getElementById("searchDeparture");
			postData += "&searchDeparture=" + searchField.value;
			
			searchField = document.getElementById("searchType");
			postData += "&searchType=" + searchField.value;
			
			searchField = document.getElementById("SearchMonth");
			postData += "&SearchMonth=" + searchField.value;
			
			var CurrentMonthIndex = searchField.selectedIndex;			
			if(searchField.value < CurrentMonthIndex)
			{
				SelectedYear += 1
			}
			postData += "&searchYear=" + SelectedYear;
			searchField = document.getElementById("searchYear");
			searchField.value = SelectedYear
			
			searchField = document.getElementById("searchBudget");
			postData += "&searchBudget=" + searchField.value;
			
			/*alert(postData);
			
			
        /* ***************************  SearchOptions  ************************** */ 
			
			/*var ajaxAleti = new AJAXRequest("POST", "/AjaxResponse/SearchCount.asp", postData, function() {}, false);*/
			var ajaxAleti = new AJAXRequest('Get', 'http://www.partirdiscount.com/Ajax/NombresProduits/NombresProduits.asmx/NombresProduits?' + postData, null, function() {}, false);
			var searchForm = document.getElementById("ProduitCount");
			var text = ajaxAleti.responseText;
			/*alert(text);*/
			var parser = new DOMImplementation();

            if(text.indexOf('<string') > 0)
            {
				var domDoc = parser.loadXML(text);
				if(domDoc)
				{           
				   var docRoot = domDoc.getDocumentElement();
				   if(docRoot)
				   {
					   var count   = docRoot.getElementsByTagName("string").item(0);
					   var SearchCount = count.getFirstChild().getNodeValue();
					   
					   var i;
					   var SearchCountHtml;
					   SearchCountHtml = ""
					   
					   for(i = 0; i < SearchCount.length; i++)
					   {
							SearchCountHtml += "<img src='/images/num_pink_" + SearchCount.charAt(i) + ".gif' alt='' />";  
					   }
					   SearchCountHtml += "<img src='/images/num_pink_dispos.gif' alt='' />" 
					   
					   /*alert(SearchCountHtml)*/
					   searchForm.innerHTML = SearchCountHtml;				   
				   }
				}
            }
    }
        
    function GetPrix() {  <!-- GET PRIX POUR LA PAGE DISPO.ASP-->
		/*	var searchField = document.getElementById("CodeMarque");			
			var postData = "CodeMarque=" + searchField.value;

			searchField = document.getElementById("CodeProduit");
			postData += "&CodeProduit=" + searchField.value;
						
			searchField = document.getElementById("villedepart");
			postData += "&SearchDeparture=" + searchField.value;
			
			searchField = document.getElementById("dureesejour");
			postData += "&Duree=" + searchField.value;
			
			searchField = document.getElementById("datedepartProduit");
			postData += "&DateDepart=" + searchField.value.substr(0,10);
							
			if (searchField.value=="") 
			{
				var searchForm = document.getElementById("block_ResultPromo");
				//searchForm.innerHTML = "";
			}
			else
			{
 
 /* ***************************  PrixDepart  ************************** 

				var ajaxAleti = new AJAXRequest("POST", "/AjaxResponse/ProduitImage.asp", postData, function() {}, false);
				var searchForm = document.getElementById("pourcentage");
				
				var ajaxAleti2 = new AJAXRequest("POST", "/AjaxResponse/ProduitPrix.asp", postData, function() {}, false);
				var searchForm2 = document.getElementById("RecapTotal");
				
				searchForm.innerHTML = ajaxAleti.responseText;
				//alert( ajaxAleti.responseText );
				
				
				str = ajaxAleti2.responseText;
				str = str.split('####');
				
				searchForm2.innerHTML  = str[0];
				var joursnuits = document.getElementById("joursnuits");
				jours = parseInt(str[1]) + 1;
				nuits = jours - 1;
				joursnuits.innerHTML = jours + ' jours / '+nuits+' nuits<br/>en formule';
				//alert( ajaxAleti2.responseText ); 
			}
			*/
    }
         
    function GetDuree() {
        	
		/*	var searchField = document.getElementById("CodeMarque");			
			var postData = "CodeMarque=" + searchField.value;
		
			searchField = document.getElementById("datedepartProduit")
			postData += "&CodeProduit=" + searchField.value.substr(11,20);	
			
			
			searchField = document.getElementById("villedepart");
			postData += "&SearchDeparture=" + searchField.value;
			
			searchField = document.getElementById("datedepart");
			postData += "&DateDepart=" + searchField.value.substr(0,10);
			
			if (searchField.value=="") 
			{
				var searchForm = document.getElementById("ProduitPrix");
				searchForm.innerHTML = "";}
			else
			{
				var ajaxAleti = new AJAXRequest("POST", "/AjaxResponse/DureeDepart.asp", postData, function() {}, false);
			
				var dureesejour = document.getElementById("divdureesejour");
				//alert(searchForm.innerHTML);
				dureesejour.innerHTML = ajaxAleti.responseText;
				//dureesejour.options[dureesejour.options.length] = new Option(strtxt,strval);
			}
				//alert(ajaxAleti.responseText);
				//alert(searchForm.innerHTML); */
											
    }
       /* ****************************  AYSUN  ************************** */ 
     function GetDepart() {
        	
			var searchField = document.getElementById("CodeMarque");			
			var postData = "CodeMarque=" + searchField.value;

			searchField = document.getElementById("CodeProduit");
			postData += "&CodeProduit=" + searchField.value;			
			
		
			
			if (searchField.value=="") 
			{
				var searchForm = document.getElementById("ProduitPrix");
				searchForm.innerHTML = "";}
			else
			{
				var ajaxAleti = new AJAXRequest("POST", "/AjaxResponse/DureeDepart.asp", postData, function() {}, false);
			
				var dureesejour = document.getElementById("villedepart");
				//alert(searchForm.innerHTML);
				dureesejour.innerHTML = ajaxAleti.responseText;
				//dureesejour.options[dureesejour.options.length] = new Option(strtxt,strval);
			}
				//alert(ajaxAleti.responseText);
				//alert(searchForm.innerHTML);
			
								
    }
		function GetPetitVignetteList(){
		var ajaxAleti = new AJAXRequest("POST", "MarmaraPictureRedirectAdmin.asp", null
		, function() { }, false);
					
		var esasDiv = document.getElementById("VignettePetitToFill");
		esasDiv.innerHTML = ajaxAleti.responseText;
					
		//alert(esasDiv.innerHTML );
	}


        /* ****************************  End Of Custom Zone  ************************** */ 
