/*  Copyright websline, 2008 | www.websline.de
 * --------------------------------------------------------------------------
 *
 * The DHTML Calendar EXTENSION, version 1.0 
 * 
 * Formular-Überprüfungsfunktionen
 *   
 * Developed by melko
 *
 * This script is distributed under the GNU Lesser General Public License.
 * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html 
 * 
 * Don't change anything in this file !!! 
 ----------------------------------------------------------------------------
 */


/*
* Führt von der Variable [linkPage] abhängig entweder ein SUBMIT
* auf [frm] oder verlinkt dies per [link()] auf die [linkPage]
*/
function submitForm(){
	submitFormExt('');
}

/*
* Führt von der Variable [linkPage] bzw. [page] abhängig entweder ein
* SUBMIT auf [frm] oder verlinkt dies per [link()] bzw. [linkExt()]
*/
function submitFormExt(page){
	if(linkPage != '')
		link();
	else if(page != '')
		linkExt(page);
	else
		document.getElementById(frm).submit();
}

/*
* Verlinkt durch window.open [linkExt()] auf die [linkPage] und setzt
* die Werte der Felder [arrive_date] und [leave_date] als gleichnamige
* Parameter ein.
*/
function link(){
	linkExt(linkPage);
}

/*
* Verlinkt durch window.open auf die übergebene [page] und setzt
* die Werte der Felder [arrive_date] und [leave_date] als gleichnamige
* Parameter ein.
*/
function linkExt(page){	
    if(page.indexOf('?') != -1)
        page += '&';
    else
        page += '?';
       
    window.open(page + arrive_date + "=" + document.getElementById(arrive_date).value + "&" 
    + leave_date + "=" + document.getElementById(leave_date).value,"_parent");
}

/*
* Überprüft die übergebenen Parameter aus der URL
* und fügt diese der linkPage-Variable hinzu. 
*/
function checkParams() {
 var arr = window.location.search;
 arr = arr.substring(1, arr.length);
 
 var data = arr.split("&");
 var tag = "";
 var monat = "";
 var jahr = "";
 var personen = "";
 var naechte = "";
 var sptot = "";
 var tot = "";

  if(data.length > 2){
     
    for(i=0; i < data.length; i++){
        
        var tagValue = data[i].split("=");
        
        if(tagValue[0] == "datum"){
        
          var datum = tagValue[1].split(".");
          
          tag = "&ARR_DAY=" + datum[0];
          
          var month = datum[1] - 1;
          monat = "&ARR_MONTH=" + month;
          
          jahr = "&ARR_YEAR=" + datum[2];
        }
        if(tagValue[0] == "naechte"){
          naechte = "&NIGHTS=" + tagValue[1];
        }
        if(tagValue[0] == "personen"){
          personen = "&ADULTS=" + tagValue[1];
        }
        if(tagValue[0] == "sptot"){
          sptot = "&SPTOT=" + tagValue[1];
        }
        if(tagValue[0] == "tot"){
          tot = "&TOT=" + tagValue[1];
        }
    }
     
    if(maxSPResults != 0){
      var maxSearch = "&MAX_SP_RESULTS=" + 25;
    }
  }
  
  linkPage  += tag + monat + jahr + personen + naechte + sptot + tot + maxSearch;
}

/*
* Generiert einen IFRAME mit den übergebenen Werten und setzt die Parameter aus der jetzigen
* URL ebenfalls dazu. 
* 
* !WICHTIG! Variable no_frame MUSS definiert sein, welche den no_frame-Text beinhaltet
*/
function generateIframe(name, src, width, height, frameborder, align, scrolling, marginheight, marginweight, style, longdesc){
	var link = window.location.search;
  src = src + '&' + link.substr(1, link.length);
	
  var attribute = '';
	
	if(name != ''){
		attribute = attribute + " name='" + name + "'";
	}
	if(width != ''){
		attribute = attribute + " width='" + width + "'";
	}
	if(height != ''){
		attribute = attribute + " height='" + height + "'";
	}
	if(frameborder != ''){
		attribute = attribute + " frameborder='" + frameborder + "'";
	}
	if(align != ''){
		attribute = attribute + " align='" + align + "'";
	}
	if(scrolling != ''){
		attribute = attribute + " scrolling='" + scrolling + "'";
	}
	if(marginheight != ''){
		attribute = attribute + " marginheight='" + marginheight + "'";
	}
	if(marginweight != ''){
		attribute = attribute + " marginweight='" + marginweight + "'";
	}
	if(style != ''){
		attribute = attribute + " style='" + style + "'";
	}
	if(longdesc != ''){
		attribute = attribute + " longdesc='" + longdesc + "'";
	}

  document.write("<iframe src='" + src + "' " + attribute + "> " + no_frame + "</iframe>" );
}

/*
* Ermittelt die Werte aus den URL-Parametern [arrive_date] und [leave_date]
* und setzt diese in die gleichnamigen Felder ein.
*/
function getURLValue(){        
  var arr = window.location.search;
  var data = arr.split("&");
  
  for(x=0;x<data.length;x++){
    
    if(data[x].indexOf('?') != -1){
      data[x] = data[x].substr(1, data[x].length);
    }
    
    if(data[x].indexOf(arrive_date) != -1){
    
      var setValue = data[x].substr(arrive_date.length+1, data[x].length);
      window.document.getElementById(arrive_date).value=setValue;
    }
    else if(data[x].indexOf(leave_date) != -1){
      var setValue = data[x].substr(leave_date.length+1, data[x].length);
      window.document.getElementById(leave_date).value=setValue;
    }
  }
}

/*
* Ermittelt die Werte aus den URL-Parametern [arrive_date] und [leave_date]
* und setzt diese aufgeteilt nach Tag [arrive_day] [leave_day], 
* Monat [arrive_month] [leave_month], Jahr [arrive_year] [leave_year] 
* in die Felder ein.
*/
function getURLValue3(){        
  var arr = window.location.search;
  var data = arr.split("&");
  
  for(x=0;x<data.length;x++){
    
    if(data[x].indexOf('?') != -1){
      data[x] = data[x].substr(1, data[x].length);
    }
    
    if(data[x].indexOf(arrive_date) != -1){
           
      var setValue = data[x].substr(arrive_date.length+1, data[x].length);
      var saSplit_value = setValue.split('.');
      
      window.document.getElementById(arrive_day).value = saSplit_value[0];
      window.document.getElementById(arrive_month).value = saSplit_value[1];
      window.document.getElementById(arrive_year).value = saSplit_value[2];
    }
    else if(data[x].indexOf(leave_date) != -1){
      
      var setValue = data[x].substr(leave_date.length+1, data[x].length);
      var saSplit_value = setValue.split('.');
      
      window.document.getElementById(leave_day).value = saSplit_value[0];
      window.document.getElementById(leave_month).value = saSplit_value[1];
      window.document.getElementById(leave_year).value = saSplit_value[2];
    }
  }
}
