/*
urs März / April 2010 
fuer beles shop; diverse scripten 
urs@gigaperls.org
*/

// positioniert die Warenkorbfunktion unten an der Seite (mit Scrollgimmick)
var slideTime = 800;
var floatAtBottom = true;

window.onload = function()
{
  winOnResize(); // set initial position
  xAddEventListener(window, 'resize', winOnResize, false);
  xAddEventListener(window, 'scroll', winOnScroll, false);
}

function winOnResize() {
  //xWidth('cartPreview', xClientWidth());

  winOnScroll(); // initial slide
}
function winOnScroll() {
  var y = xScrollTop();
  if (floatAtBottom) {
    y += xClientHeight() - xHeight('cartPreview'); /*  urs: hier hoehe der unteren kante des shopmoduls reinrechnen*/
  }
  xSlideTo('cartPreview', 0, y, slideTime);
}

// checkt ob alle Kartenfelder befüllt sind	
function checkit() {

//alert('test');


  /* if (document.kakarte.i_name.value == "") {
	Dialog.alert("<br>Bitte den Namen eingeben!", {className:"alphacube", width:300, height:100, okLabel: "OK", ok:function(win) {document.getElementById('versender').style.visibility= 'visible'; document.kakarte.i_name.focus(); return true; }})
return false;	
  } */
   	   
	   if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	   { //test for MSIE x.x;
		//var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		//if (ieversion>=8)
		//document.write("You're using IE8 or above")
		//else if (ieversion>=7) 
		//document.write("You're using IE7.x")
		//else if (ieversion>=6)
		//document.write("You're using IE6.x")
		//else if (ieversion>=5)
		//document.write("You're using IE5.x")
		}
	else
		{
			if ((document.kakarte.cc_cardtype.value != 'Mastercard')&&(document.kakarte.cc_cardtype.value != 'Visa')){
		//document.getElementsByName('cc_cardtype').style.display= 'block';
			Dialog.alert("<br>Visa oder Mastercard?", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) {/* document.kakarte.cc_cardtype.focus();*/ return true; }})
			return false;
			} 
		
		}
	   
	   
	   
  
 	  if (document.kakarte.cc_name.value == "") {
	 	Dialog.alert("<br>Bitte den Namen wie auf der Kreditkarte eingeben", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) { document.kakarte.cc_name.focus(); return true; }})
		return false;	
	  }  
  
	  if (document.kakarte.cc_code1.value == "") {
	 	Dialog.alert("<br>Bitte die vollst&auml;ndige Kartennummer eingeben", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) { document.kakarte.cc_code1.focus(); return true; }})
		return false;	
	  } 

	  	  if (document.kakarte.cc_code2.value == "") {
	 	Dialog.alert("<br>Bitte die vollst&auml;ndige Kartennummer eingeben", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) { document.kakarte.cc_code2.focus(); return true; }})
		return false;	
	  } 

	  if (document.kakarte.cc_code3.value == "") {
	 	Dialog.alert("<br>Bitte die vollst&auml;ndige Kartennummer eingeben", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) { document.kakarte.cc_code3.focus(); return true; }})
		return false;	
	  } 

	  if (document.kakarte.cc_code4.value == "") {
	 	Dialog.alert("<br>Bitte die vollst&auml;ndige Kartennummer eingeben", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) { document.kakarte.cc_code4.focus(); return true; }})
		return false;	
	  } 	  

 
     if (document.kakarte.cc_month1.value == "") {
	 	Dialog.alert("<br>Bitte den Monat eingeben", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) { document.kakarte.cc_month1.focus(); return true; }})
		return false;	
	  }
	  
	  if (document.kakarte.cc_year1.value == "") {
	 	Dialog.alert("<br>Bitte das Jahr eingeben", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) { document.kakarte.cc_year1.focus(); return true; }})
		return false;	
	  }

	   if (document.kakarte.cc_seccode1.value == "") {
	 	Dialog.alert("<br>Bitte den dreistelligen Code der Rückseite eingeben", {className:"alert", width:300, height:100, okLabel: "OK", ok:function(win) { document.kakarte.cc_seccode1.focus(); return true; }})
		return false;	
	  } 
	  
	  // ++++++++++++++++++++++++++++++++
	  // ok, alle eingaben wurden korrekt gemacht

	 wurst = window.document.forms['kakarte'].elements['cc_name'].value;

	  //Dialog.info("<br>Die Kartendaten werden geprüft", {className:"alert", width:300, height:100, showProgress: true, okLabel: "OK", ok:function(win) {return true; }})
	ajaxFunction();

	// Kreditkartenprüfung unsichtbarschalten
	document.getElementById('okidoki0').style.display= 'none'; 
		// ok sichtbarschalten
	document.getElementById('okidoki1').style.display= 'block'; 
	document.getElementById('finalsendenbutton').style.display= 'block';


	return true;
}


// saugt und pusht die kartendaten vom und zum server
function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Browserproblem aufgetreten!");
				return false;
			}
		}
	}
	
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		// if(ajaxRequest.readyState == 4 && ajaxRequest.status==200)
		if(ajaxRequest.readyState == 4)
		{

			//document.getElementById('okidoki1').innerHTML = "" + ajaxRequest.responseText;	  // urs 
			document.getElementById('okidoki1').innerHTML=ajaxRequest.responseText;
		}
	}
	
	var x_first_name = window.document.forms['kakarte'].elements['dd_first_name'].value;
	var x_last_name = window.document.forms['kakarte'].elements['dd_last_name'].value;
	var x_street = window.document.forms['kakarte'].elements['dd_street'].value;
	var x_zip_code = window.document.forms['kakarte'].elements['dd_zip_code'].value;
	var x_city = window.document.forms['kakarte'].elements['dd_city'].value;
	var x_e_mail = window.document.forms['kakarte'].elements['dd_e_mail'].value;
	var x_destination_area = window.document.forms['kakarte'].elements['dd_destination_area'].value;
	var x_payment_mode = window.document.forms['kakarte'].elements['dd_payment_mode'].value;
	var x_annotation = window.document.forms['kakarte'].elements['dd_annotation'].value;
	var c_cardtype = window.document.forms['kakarte'].elements['cc_cardtype'].value;
	var c_name = window.document.forms['kakarte'].elements['cc_name'].value;
		var cc_code1 = window.document.forms['kakarte'].elements['cc_code1'].value;
		var cc_code2 = window.document.forms['kakarte'].elements['cc_code2'].value;
		var cc_code3 = window.document.forms['kakarte'].elements['cc_code3'].value;
		var cc_code4= window.document.forms['kakarte'].elements['cc_code4'].value;
	var c_code = cc_code1+cc_code2+cc_code3+cc_code4;
	var c_month1 = window.document.forms['kakarte'].elements['cc_month1'].value;
	var c_year1 = window.document.forms['kakarte'].elements['cc_year1'].value;
	var c_seccode1 = window.document.forms['kakarte'].elements['cc_seccode1'].value;
	var c_endsum = window.document.forms['kakarte'].elements['cc_endsum'].value;
	var c_waehrung = window.document.forms['kakarte'].elements['cc_waehrung'].value;
	
// und da wird hinkommuniziert
	//url = "http://127.0.0.1/patrikmuff.com/orderget_01.php?";
	url = "http://www.patrikmuff.com/orderget_01.php?";

	url=url+"x_first_name="+x_first_name;
	url=url+"&x_last_name="+x_last_name;
	url=url+"&x_street="+x_street;
	url=url+"&x_zip_code="+x_zip_code;
	url=url+"&x_city="+x_city;
	url=url+"&x_e_mail="+x_e_mail;
	url=url+"&x_destination_area="+x_destination_area;
	url=url+"&x_payment_mode="+x_payment_mode;
	url=url+"&x_annotation="+x_annotation;
	url=url+"&c_cardtype="+c_cardtype;
	url=url+"&c_name="+c_name;
	url=url+"&c_code="+c_code;
	url=url+"&c_month1="+c_month1;
	url=url+"&c_year1="+c_year1;
	url=url+"&c_seccode1="+c_seccode1;
	url=url+"&c_endsum="+c_endsum;
	url=url+"&c_waehrung="+c_waehrung;

		ajaxRequest.open('GET', url + Math.random(), true);
	ajaxRequest.send(); 


}






/* function fensterl () {
Dialog.confirm($('ortbox').innerHTML, {className:"alert", width:440, okLabel: "OK", onOk:function(win){ return false;}}); 
//Dialog.alert($('ortbox').innerHTML, {className:"alphacube", width:4400, okLabel: "OK", ok:function(win) {document.getElementById('versender').style.visibility= 'visible';  return true; }})
//return true;
} */

var timeout;
function openInfoDialog() {
  Dialog.info("Test of info panel, it will close <br>in 3s ...",
               {width:250, height:100, showProgress: true});
  timeout=3;
  setTimeout(infoTimeout, 1000)
}

function infoTimeout() {
  timeout--;
  if (timeout >0) {
    Dialog.setInfoMessage("Test of info panel, it will close <br>in " + timeout + "s ...")
    setTimeout(infoTimeout, 1000)
 }
 else
  Dialog.closeInfo()
  
  return false;
}

          
