  //<![CDATA[

  var smart_abo_checked = 0;
	var smart_abo_subscriber_id = 0;
	var callback_urls_waiting = 0;
	var callback_urls;
	var callback_type;
	var TimingStart,TimingEnd;
	TimingStart=new Date().getTime();
  
	function check_item_input_all(only_check,init) {
		var ok = 1;
		var set_focus = false;
		for (var i=0;i<input_elements.length;i++) {
		  var element = dom.byId(input_elements[i]);
		  if (element) {
		  	check_item_input(element)
		  	if (element.className != "ok" ) {
		  		ok = 0;
		  	}
		  	if (init && !set_focus) {
					element.focus();
					set_focus = true;
		  	}
		  }
		}
		if (ok && !only_check) {
			step_enable_next('item_input');
			if (init) dom.byId('msisdn').focus();
		}
		return ok;
	}


	function check_item_input(element) {

		if (element.id=="message_text") {
			if (element.value.length > 0) {
					element.className = "ok";
			} else {
				element.className = "";
			}
		}

		if (element.id=="message_recipient_msisdn") {
			if (element.value.length > 0) {
			  var msisdn_clean = clean_msisdn(element.value);
			  var ok = check_msisdn(msisdn_clean,network_prefixes);
				if (ok==0) {
					element.className = "error";
				} else if (ok==1) {
					element.className = "ok";
				} else {
					element.className = "";
				}
			} else {
				element.className = "";
			}
		}

	}
	

 function check_splash_msisdn(msisdn_clean,network_prefixes) {
  var ok = 0;
  if (msisdn_clean.match(/^\d+$/)) {
    for (var i=0;i<network_prefixes.length;i++) {
      if (network_prefixes[i].indexOf(msisdn_clean) == 0 || msisdn_clean.indexOf(network_prefixes[i]) == 0) {
        if (msisdn_clean.match(/^\d{10,30}$/)) {
          return 1;
        } else {
          return -1;
        }
      }
    }
  }
  return 0;
}


function clean_msisdn(msisdn){	
	
 var msisdn_filtered = msisdn.replace(/[\s\/\-\\\+]/g, "");	    //	valid: 0049, 49, 0176
 //var msisdn_filtered = msisdn.replace(/[^\d]/g, "");	
  if (msisdn_filtered.indexOf("00") == 0){
  		  msisdn_filtered = msisdn_filtered.slice(4, 30);
  		  msisdn_filtered = "0" + msisdn_filtered;
  }
  else if (msisdn_filtered.indexOf("0") != 0){
  		  msisdn_filtered = msisdn_filtered.slice(2, 30);
  		  msisdn_filtered = "0" + msisdn_filtered;
  }   

    return msisdn_filtered;

}

	function check_send_validation(element) {

		if (element.id=="mobile_operator_id") {
			if (element.value.length > 0) {
					element.className = "ok";
			} else {
				element.className = "";
				return;
			}
		}

		if (element.id=="msisdn") {
			if (element.value.length > 0) {
				var msisdn_clean = clean_msisdn(element.value);
			  var ok = check_splash_msisdn(msisdn_clean,network_prefixes);
				if (ok==0) {
					element.className = "error";
					return;
				} else if (ok==1) {
					element.className = "ok";
				} else {
					element.className = "";
				}
			} else {
				element.className = "";
				return;
			}
		}

    if (element.id=="gtc_read") {
		  if (element.checked == true) {
		    if (document.getElementById("gtc_read_text") && document.getElementById("gtc_read_text_error") && document.getElementById("button_send_validation_wrapper")) {
		     document.getElementById("button_send_validation_wrapper").style.display = '';
		     document.getElementById("gtc_read_text").style.display = '';
		     document.getElementById("gtc_read_text_error").style.display = 'none';
		    }
		    return true;
		  } else {
		    if (document.getElementById("gtc_read_text") && document.getElementById("gtc_read_text_error") && document.getElementById("button_send_validation_wrapper")) {
		      document.getElementById("button_send_validation_wrapper").style.display = 'none';
		      document.getElementById("gtc_read_text").style.display = 'none';
		      document.getElementById("gtc_read_text_error").style.display = '';
		    }
		    return false;
		  }
		}
	}
	function gtc_error_close() {
	  if (document.getElementById("gtc_read_text") && document.getElementById("gtc_read_text_error") && document.getElementById("button_send_validation_wrapper")) {
		      document.getElementById("button_send_validation_wrapper").style.display = '';
		      document.getElementById("gtc_read_text").style.display = '';
		      document.getElementById("gtc_read_text_error").style.display = 'none';
		    }
	}
	
	function process_send_validation_and_gtc() {
	  /* accept gtc by button before sending validation*/
	  if (document.getElementById("gtc_read")) document.getElementById("gtc_read").checked = true;
	  process_send_validation();
	}

  function loading_indicator(show) {
    var li_div = dom.byId('loading_indicator');
    if (li_div) {
      if (show) {
        li_div.style.display = '';
      } else {
        li_div.style.display = 'none';
      }
    }
  }

	function process_send_validation() {
	    
    
		var gtc_read = dom.byId("gtc_read");
		if (gtc_read && gtc_read.style.display != 'none') {
		  if (!check_send_validation(gtc_read)) return false;
		}

		var mobile_operator_id = dom.byId("mobile_operator_id");
		var msisdn             = dom.byId("msisdn");
		var device_company     = dom.byId("device_company");
		var device_id          = dom.byId("order_device_id");
		var button             = dom.byId("button_send_validation");   
	 
    if(msisdn.className!="ok"){
    	document.getElementById("error_msisdn_layer").style.display = "";
    }else{ 	
    	document.getElementById("error_msisdn_layer").style.display = "none";
    }
         
     if(mobile_operator_id.className!="ok"){
    	document.getElementById("error_mobile_operator_layer").style.display = "";
    }else{ 	
    	document.getElementById("error_mobile_operator_layer").style.display = "none";
    }
     

		if (!check_item_input_all(true)) {
			/*step_disable_all_next('item_input');*/
			return;
		}
    


//alert(mobile_operator_id.className+' - '+msisdn.className+' - '+device_id+' - '+device_id.className+' - '+button.style.cursor );
		if (mobile_operator_id.className=="ok" && msisdn.className=="ok" && (!device_id || device_id.className=="ok") && button.style.cursor != "wait") {

			step_enable('send_validation');
      
      loading_indicator(1);
      
			hide_error("error_send_validation");
			button.style.cursor = "wait";

			var send_validation_type = subtype_id == 8 ? "erotic" : "";

		  if (smart_abo_id) {
			  if (!smart_abo_checked) {
			    var post = 'cmd=check_smart_abo&smart_abo_id='+smart_abo_id+'&mobile_operator_id='+mobile_operator_id.value+'&msisdn='+clean_msisdn(msisdn.value);
				} else if (mobile_operator_id.value == 40) { // there are no online orders for vodafone
					var post = 'cmd=get_sms_order_info&class_id='+dom.byId("class_id").value+'&item_id='+dom.byId("item_id").value;
					new ajax('/mobile/xml.fcgi', {postBody: post, onComplete: processed_get_sms_order_info, onError: error_get_sms_order_info});
					process_campaign_callback_counter(1);
					return;
				} else {
				  process_campaign_callback_counter(1);
					var post = 'cmd=send_validation&mobile_operator_id='+mobile_operator_id.value+'&msisdn='+clean_msisdn(msisdn.value)+'&type='+send_validation_type;
				}
				new ajax('/mobile/abo/xml.fcgi', {postBody: post, onComplete: processed_send_validation, onError: error_send_validation});
			} else if (mobile_operator_id.value == 40 || mobile_operator_id.value == 41 || mobile_operator_id.value == 42) {
				var post = 'cmd=get_sms_order_info&class_id='+dom.byId("class_id").value+'&item_id='+dom.byId("item_id").value;
				new ajax('/mobile/xml.fcgi', {postBody: post, onComplete: processed_get_sms_order_info, onError: error_get_sms_order_info});
				process_campaign_callback_counter(1);
			} else {
				var post = 'cmd=send_validation&mobile_operator_id='+mobile_operator_id.value+'&msisdn='+clean_msisdn(msisdn.value)+'&type='+send_validation_type;
      	new ajax('/shop/mobile/xml.fcgi', {postBody: post, onComplete: processed_send_validation, onError: error_send_validation});
      	process_campaign_callback_counter(1);
      }
 		}
	}

	function processed_send_validation(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);

		dom.byId("button_send_validation").style.cursor = "pointer";
		loading_indicator(0);

		if (smart_abo_id && !smart_abo_checked) {
			smart_abo_subscriber_id = parseInt(tr_xml.SmartAboSubscriberId[0].data,10);
			if (tr_xml.Ok[0].data == "1") {
				/* make abo download */
				determine_content_selection_item_id();
				get_smart_message_order();
			} else if (smart_abo_id == 33 || smart_abo_id == 34 || smart_abo_id == 35 || smart_abo_id == 42 || smart_abo_id == 43 || smart_abo_id == 44) {
				show_error("error_send_validation","Die Bestellung f&uuml;r dieses Produkt ist leider nicht mehr m&ouml;glich. Weitere tolle Angebote findest du auf <a href='http://www.blinkogold.de/'>www.blinkogold.de</a>");				
			} else if (smart_abo_subscriber_id > 0) {
				/* make single download */
				smart_abo_id = 0;
				smart_abo_checked = 1;
				process_send_validation();
			} else {
				/* buy abo */
				if (tr_xml.AdditionalSmartAboSubscriberIds && tr_xml.AdditionalSmartAboSubscriberIds.length > 0) {
					/* show info layer that user will buy additional abo */
					document.getElementById('abo_info_text').style.display = '';
				}
				smart_abo_checked = 1;
				process_send_validation();
			}
		} else {
			if (tr_xml.Ok[0].data == "1") {
				step_enable('verify_validation');
				if (typeof pageTracker == 'object') pageTracker._trackPageview("/pin_entry.html");
			} else {
				show_error("error_send_validation", tr_xml.Error[0].data);
			}
		}
	}

	function error_send_validation() {
		show_error("error_send_validation");
		dom.byId("button_send_validation").style.cursor = "pointer";
		loading_indicator(0);
	}

	function processed_get_sms_order_info(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);

		dom.byId("button_send_validation").style.cursor = "pointer";
		loading_indicator(0);

  	if (tr_xml.Ok[0].data == "1") {
  		dom.byId('step_send_validation').style.display = 'none';
  		var sms_order_info = dom.byId('step_sms_order_info');
			var template = sms_order_info.innerHTML;
			template = template.replace("#{keyword}", tr_xml.Keyword[0].data);
			template = template.replace("#{shortcode}", tr_xml.Shortcode[0].data);
			template = template.replace("#{identifier}", tr_xml.Identifier[0].data);
			template = template.replace("#{sms_price}", tr_xml.SmsPrice[0].data);
			sms_order_info.innerHTML = template;
			dom.byId('step_sms_order_info').style.display = '';
		} else {
			show_error("error_send_validation", tr_xml.Error[0].data);
		}
	}

	function error_get_sms_order_info() {
		show_error("error_send_validation");
		dom.byId("button_send_validation").style.cursor = "pointer";
		loading_indicator(0);
	}

	function process_order_product_smart_abo() {

		var mobile_operator_id = dom.byId("mobile_operator_id");
		var msisdn = dom.byId("msisdn");
		var button = dom.byId("button_send_validation");

		if (mobile_operator_id.className=="ok" && msisdn.className=="ok") {

			hide_error("error_send_validation");
			button.style.cursor = "wait";
			loading_indicator(1);

			var post = 'cmd=order_product_smart_abo&mobile_operator_id='+mobile_operator_id.value+'&msisdn='+clean_msisdn(msisdn.value)+'&products_id='+products_id+'&products_info='+escape(products_info)+'&products_action_value='+escape(products_action_value)+'&orders_products_info='+escape(orders_products_info);
			new ajax('/shop/mobile/xml.fcgi', {postBody: post, onComplete: processed_order_product_smart_abo, onError: error_order_product_smart_abo});
		}
	}

	function processed_order_product_smart_abo(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);
		if (tr_xml.Ok[0].data == "2") {
		  smart_abo_checked = 0;
			step_enable('thank_you');
			if (typeof pageTracker == 'object') pageTracker._trackPageview("/order_ok.html");
			dom.byId("button_send_validation").style.cursor = "pointer";
			loading_indicator(0);
			redirect_to_start_page();
		} else {
			smart_abo_id = 0;
			step_enable('send_validation');
			show_error("error_send_validation", tr_xml.Error[0].data);
			dom.byId("button_send_validation").style.cursor = "pointer";
			loading_indicator(0);
		}
	}

	function error_order_product_smart_abo() {
		show_error("error_send_validation");
		dom.byId("button_send_validation").style.cursor = "pointer";
		loading_indicator(0);
	}


//removes all characters expecting numbers
function clean_verify_validation(entered_code){		
 var entered_code = entered_code.replace(/[^\w]/g, "");
 return entered_code;
}

	function check_verify_validation(element) {
		if (element.id=="validation_code") {
			element.className = "";
			return;
		}
	}

	function process_verify_validation() {

    document.getElementById('abo_info_text').style.display = 'none';

		var mobile_operator_id = dom.byId("mobile_operator_id");
		var msisdn = dom.byId("msisdn");
		var validation_code = dom.byId("validation_code");	
		var button = dom.byId("button_verify_validation");
		

//alert('process_verify_validation: '+mobile_operator_id.className+' - '+msisdn.className+' - '+button.style.cursor);
		if (mobile_operator_id.className=="ok" && msisdn.className=="ok" && button.style.cursor != "wait") {

			step_enable('verify_validation');
			if (typeof pageTracker == 'object') pageTracker._trackPageview("/pin_entry.html");

			hide_error("error_verify_validation");
			button.style.cursor = "wait";
			loading_indicator(1);

			var verify_validation_type = subtype_id == 8 ? "erotic" : "";

			var post = 'cmd=verify_validation&mobile_operator_id='+mobile_operator_id.value+'&msisdn='+clean_msisdn(msisdn.value)+'&code='+clean_verify_validation(validation_code.value)+'&type='+verify_validation_type;
			new ajax('/shop/mobile/xml.fcgi', {postBody: post, onComplete: processed_verify_validation, onError: error_verify_validation});
			process_campaign_callback_counter(2);
			process_campaign_callback('pin');
		}
	}

	function processed_verify_validation(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);
		if (tr_xml.Ok[0].data == "1") {
			dom.byId("validation_code").className = "ok";
			determine_content_selection_item_id();
			if (dom.byId('item_id') && dom.byId('item_id').value > 0) {
			  get_smart_message_order();
			} else {
			  process_order_smart_abo();
			}
		} else {
			dom.byId("validation_code").className = "error";

			show_error("error_verify_validation", tr_xml.Error[0].data);

			dom.byId("button_verify_validation").style.cursor = "pointer";
			loading_indicator(0);
		}
	}

	function error_verify_validation() {
		show_error("error_verify_validation");
		dom.byId("button_verify_validation").style.cursor = "pointer";
		loading_indicator(0);
	}

	var transaction_id = 0;

	function process_order_product() {

		var mobile_operator_id = dom.byId("mobile_operator_id");
		var msisdn = dom.byId("msisdn");
		var validation_code = dom.byId("validation_code");
		var button = dom.byId("button_verify_validation");

		if (mobile_operator_id.className=="ok" && msisdn.className=="ok" && validation_code.className=="ok" && transaction_id==0) {

			hide_error("error_verify_validation");
			button.style.cursor = "wait";
			loading_indicator(1);

			var verify_validation_type = subtype_id == 8 ? "erotic" : "";

			var post = 'cmd=order_product&mobile_operator_id='+mobile_operator_id.value+'&msisdn='+clean_msisdn(msisdn.value)+'&code='+clean_verify_validation(validation_code.value)+'&type='+verify_validation_type+'&products_id='+products_id+'&products_info='+escape(products_info)+'&products_action_value='+escape(products_action_value)+'&orders_products_info='+escape(orders_products_info);
			new ajax('/shop/mobile/xml.fcgi', {postBody: post, onComplete: processed_order_product, onError: error_order_product});
		}
	}

	function processed_order_product(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);
		if (tr_xml.Ok[0].data == "2") {
			step_enable('thank_you');
			process_campaign_callback('splash');
			if (typeof pageTracker == 'object') pageTracker._trackPageview("/order_ok.html");
			dom.byId("button_verify_validation").style.cursor = "pointer";
			loading_indicator(0);
			if (tr_xml.CallbackUrl) {
			  if (tr_xml.CallbackType[0].data == "image") {
			    callback_urls_waiting = tr_xml.CallbackUrl.length;
          var preloader = new ImagePreloader(tr_xml.CallbackUrl, callback_urls_loaded, '');
			  }
			} else {
			  redirect_to_start_page();
			}
		} else if (tr_xml.Ok[0].data == "1") {
			transaction_id = parseInt(tr_xml.TransactionId[0].data);
			window.setTimeout("process_check_transaction()",5000);
			if (tr_xml.Location[0].data) {
				dom.byId("order_popup").src = tr_xml.Location[0].data;
				dom.byId("order_popup").style.display = "";
			}
		} else {
			show_error("error_verify_validation", tr_xml.Error[0].data);
			dom.byId("button_verify_validation").style.cursor = "pointer";
			loading_indicator(0);
		}
	}

	function error_order_product() {
		show_error("error_verify_validation");
		dom.byId("button_verify_validation").style.cursor = "pointer";
		loading_indicator(0);
	}

	function process_check_transaction() {
		if (transaction_id > 0) {
			var post = 'cmd=check_transaction&transaction_id='+transaction_id+'&products_id='+products_id+'&products_info='+escape(products_info)+'&products_action_value='+escape(products_action_value)+'&orders_products_info='+escape(orders_products_info);
			new ajax('/shop/mobile/xml.fcgi', {postBody: post, onComplete: processed_check_transaction, onError: error_check_transaction});
		}
	}

	function processed_check_transaction(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);
		if (tr_xml.Ok[0].data == "2") {
			transaction_id = 0;
			step_enable('thank_you');
			if (typeof pageTracker == 'object') pageTracker._trackPageview("/order_ok.html");
			dom.byId("button_verify_validation").style.cursor = "pointer";
			loading_indicator(0);
			redirect_to_start_page();
		} else if (tr_xml.Ok[0].data == "1") {
			window.setTimeout("process_check_transaction()",5000);
		} else {
			show_error("error_verify_validation", tr_xml.Error[0].data);
			transaction_id = 0;
			dom.byId("button_verify_validation").style.cursor = "pointer";
			loading_indicator(0);
		}
	}

	function error_check_transaction() {
		window.setTimeout("process_check_transaction()",5000);
	}

	function process_order_smart_abo() {

		var mobile_operator_id = dom.byId("mobile_operator_id");
		var msisdn = dom.byId("msisdn");
		var validation_code = dom.byId("validation_code");
		var button = dom.byId("button_verify_validation");
		var message_text             = dom.byId("message_text");
		var message_recipient_msisdn = dom.byId("message_recipient_msisdn");

		if (mobile_operator_id.className=="ok" && msisdn.className=="ok" && validation_code.className=="ok" && smart_abo_subscriber_id==0) {

			hide_error("error_verify_validation");
			button.style.cursor = "wait";
			loading_indicator(1);

			var verify_validation_type = subtype_id == 8 ? "erotic" : "";
      
      // read optional first plus sms
      var message_text_val             = '';
      var message_recipient_msisdn_val = '';
      if (message_text && message_recipient_msisdn && message_text.className=="ok" && message_recipient_msisdn.className=="ok") {
        message_text_val             = encodeURIComponent(message_text.value);
        message_recipient_msisdn_val = clean_msisdn(message_recipient_msisdn.value);
      }
      
			var post = 'cmd=order_smart_abo&mobile_operator_id='+mobile_operator_id.value+'&msisdn='+clean_msisdn(msisdn.value)+'&code='+clean_verify_validation(validation_code.value)+'&type='+verify_validation_type+'&smart_abo_id='+smart_abo_id+'&products_id='+products_id+'&products_info='+escape(products_info)+'&products_action_value='+escape(products_action_value)+'&orders_products_info='+escape(orders_products_info)+'&message_text='+message_text_val+'&message_recipient_msisdn='+message_recipient_msisdn_val;
			new ajax('/mobile/abo/xml.fcgi', {postBody: post, onComplete: processed_order_smart_abo, onError: error_order_smart_abo});
		}
	}

	function processed_order_smart_abo(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);
		if (tr_xml.Ok[0].data == "1") {
			smart_abo_checked = 0;
			smart_abo_subscriber_id = parseInt(tr_xml.SmartAboSubscriberId[0].data);
			window.setTimeout("process_check_order_smart_abo()",5000);
		} else {
			show_error("error_verify_validation", tr_xml.Error[0].data);
			dom.byId("button_verify_validation").style.cursor = "pointer";
			loading_indicator(0);
		}
	}

	function error_order_smart_abo() {
		show_error("error_verify_validation");
		dom.byId("button_verify_validation").style.cursor = "pointer";
		loading_indicator(0);
	}


	function process_check_order_smart_abo() {

		var msisdn = dom.byId("msisdn");

		if (smart_abo_subscriber_id > 0) {
			var post = 'cmd=check_order_smart_abo&msisdn='+clean_msisdn(msisdn.value)+'&smart_abo_id='+smart_abo_id;
			new ajax('/mobile/abo/xml.fcgi', {postBody: post, onComplete: processed_check_order_smart_abo, onError: error_check_order_smart_abo});
		}
	}

	function processed_check_order_smart_abo(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);
		if (tr_xml.Ok[0].data == "1") {
			step_enable('thank_you');
			process_campaign_callback('splash');
			if (typeof pageTracker == 'object') pageTracker._trackPageview("/order_ok.html");
			dom.byId("button_verify_validation").style.cursor = "pointer";
			loading_indicator(0);
			if (tr_xml.CallbackUrl) {
			  if (tr_xml.CallbackType[0].data == "image") {
			    callback_urls_waiting = tr_xml.CallbackUrl.length;
          var preloader = new ImagePreloader(tr_xml.CallbackUrl, callback_urls_loaded, '');
			  }
			} else {
			  redirect_to_start_page();
			}
		} else if (tr_xml.Ok[0].data == "2") {
			window.setTimeout("process_check_order_smart_abo()",5000);
		} else {
			show_error("error_verify_validation", tr_xml.Error[0].data);

			smart_abo_subscriber_id = 0;
			dom.byId("button_verify_validation").style.cursor = "pointer";
			loading_indicator(0);
		}
	}

	function error_check_order_smart_abo() {
		window.setTimeout("process_check_order_smart_abo()",5000);
	}

	var products_id = 0;
	var products_info = "";
	var products_action_value = "";
	var orders_products_info = "";

	function get_smart_message_order() {

		var mobile_operator_id = dom.byId("mobile_operator_id");
		var msisdn = dom.byId("message_recipient_msisdn");
		if (!msisdn) msisdn = dom.byId("msisdn");
		var device_id = dom.byId("order_device_id");
		var button = dom.byId("button_verify_validation");
//alert('get_smart_message_order: '+mobile_operator_id.className+' - '+msisdn.className+' - '+device_id+' - '+device_id.className);
		if (mobile_operator_id.className=="ok" && msisdn.className=="ok" && (!device_id || device_id.className=="ok")) {

			hide_error("error_verify_validation");
			button.style.cursor = "wait";
			loading_indicator(1);

			var post = 'cmd=get_smart_message_order&mobile_operator_id='+mobile_operator_id.value+'&msisdn='+clean_msisdn(msisdn.value)+'&item_id='+dom.byId("item_id").value;
			if (dom.byId("mono_class_id")) {
				post = post+'&class_id='+dom.byId("mono_class_id").value;
			} else {
				post = post+'&class_id='+dom.byId("class_id").value;
			}
			if (device_id) {
			  post = post+'&device_id='+device_id.value;
			} else {
				post = post+'&device_id='+dom.byId("device_id").value;
			}
			/* check for name wallpaper text */
			/*if (amount_text_lines) {
  		  post = post+'&amount_text_lines='+escape(amount_text_lines);
  		  for (var i=1;i<=amount_text_lines;i++) {
			    if (dom.byId('text_'+i)) post = post+'&text_'+i+'='+escape(dom.byId('text_'+i).value);
  		  }
  		}*/

			if (dom.byId("message_text")) post = post+'&message_text='+escape(dom.byId("message_text").value);
			if (dom.byId("audio_id")) post = post+'&audio_id='+dom.byId("audio_id").value;
			new ajax('/mobile/xml.fcgi', {postBody: post, onComplete: got_smart_message_order, onError: error_smart_message_order});
		}
	}

	function got_smart_message_order(request) {
		var tr_xml = dom.treeXML(request.responseXML.documentElement);
//alert('got_smart_message_order '+smart_abo_id+' - '+smart_abo_subscriber_id);
		if (tr_xml.Ok[0].data == "1") {
			products_id = tr_xml.ProductsId[0].data;
			products_info = tr_xml.ProductsInfo[0].data;
			products_action_value = tr_xml.ProductsActionValue[0].data;
			orders_products_info = tr_xml.OrdersProductsInfo[0].data;

			if (smart_abo_id && smart_abo_subscriber_id) {
			  process_order_product_smart_abo();
			} else if (smart_abo_id) {
				process_order_smart_abo();
			} else {
			  process_order_product();
			}
		} else {
			if (smart_abo_id) {
				show_error("error_send_validation", tr_xml.Error[0].data);
			  dom.byId("button_send_validation").style.cursor = "pointer";
			} else {
			  show_error("error_verify_validation", tr_xml.Error[0].data);
		  	dom.byId("button_verify_validation").style.cursor = "pointer";
		  }
		  loading_indicator(0);
		}
	}

	function error_smart_message_order() {
		show_error("error_verify_validation");
		dom.byId("button_verify_validation").style.cursor = "pointer";
		loading_indicator(0);
	}

	function step_disable(step) {
//		alert('step_disable '+step);
	}

	function step_enable(step) {
		/*alert('step_enable '+step);*/
		for(var i=0; i<steps.length;i++) {
		  if (step!=steps[i]) {
		    dom.byId('step_'+steps[i]).style.display = 'none';
		  } else {
		    dom.byId('step_'+steps[i]).style.display = '';
		  }
		}
	}

	function step_disable_all_next(step_name) {
//alert('step_disable_all_next '+step_name);
	}

	function step_enable_next(step_name) {
//		alert('step_enable_next '+step_name);
	}

	function init() {
	  // count script/ajax loaded
    TimingEnd = new Date().getTime();
    process_campaign_callback('init');
		step_disable_all_next('item_input');
		show_legal_notice();
		check_item_input_all(false,true);
		if (typeof pageTracker == 'object') pageTracker._trackPageview("/msisdn_entry.html");
	}

	function show_legal_notice() {
	  if (document.getElementById('splash_legal_'+legal_info_id)) {
	    document.getElementById('splash_legal_'+legal_info_id).style.display ='';
	  } else {
	    //document.getElementById('splash_legal_ent_flat').style.display = '';
	  }
	}

  function callback_urls_loaded(aImages, nImages, return_href) {
    if ( nImages != callback_urls_waiting ) {
      // Images didnt load properly
      if (dom.byId("image_load_info")) {
        dom.byId("image_load_info").innerHTML = '<b>Incomplete Image Load.</b>';
      }
    }
    // do nothing window.location.href = return_href;
  }


function ImagePreloader(imagesrcs, callback, return_href) {

   // store the call-back
   this.callback = callback;

   // store my return link
   this.return_href = return_href;

   // initialize internal state.
   this.nLoaded = 0;
   this.nProcessed = 0;
   this.aImages = new Array;

   // record the number of images.
   this.nImages = imagesrcs.length;

   // for each image, call preload()
   for ( var i = 0; i < imagesrcs.length; i++ )
      this.preload(imagesrcs[i].data);
}

ImagePreloader.prototype.preload = function(image) {
   // create new Image object and add to array
   var oImage = new Image;
   this.aImages.push(oImage);

   // set up event handlers for the Image object
   oImage.onload = ImagePreloader.prototype.onload;
   oImage.onerror = ImagePreloader.prototype.onerror;
   oImage.onabort = ImagePreloader.prototype.onabort;

   // assign pointer back to this.
   oImage.oImagePreloader = this;
   oImage.bLoaded = false;

   // assign the .src property of the Image object
   oImage.src = image;
}

ImagePreloader.prototype.onComplete = function() {
   this.nProcessed++;
   if ( this.nProcessed == this.nImages ) {
      this.callback(this.aImages, this.nLoaded, this.return_href);
   }
}

ImagePreloader.prototype.onload = function() {
   this.bLoaded = true;
   this.oImagePreloader.nLoaded++;
   this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onerror = function() {
   this.bError = true;
   this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onabort = function() {
   this.bAbort = true;
   this.oImagePreloader.onComplete();
}

  function determine_content_selection_item_id() {
    if (document.getElementById('content_selection')) {
      var item_amount = document.content_selection.radio_item_id.length;
      var item_id = false;
      for(var i=0; i<item_amount;i++) {
        if (document.content_selection.radio_item_id[i].checked) {
          item_id = document.content_selection.radio_item_id[i].value;
          document.getElementById('item_id').value = item_id;
        }
      }
      return item_id;
    } else {
      return false;
    }
  }

  function redirect_to_start_page() {
    if (redirect_to.length >= 1) {
      window.setTimeout("window.location.href = '"+redirect_to+"';",3000);
    }
  }

  function determine_quiz_answer() {
    if (document.getElementById('quiz_content')) {
      var answer_amount = document.quiz_content.radio_quiz_answer.length;
      var answer = false;
      for(var i=0; i<answer_amount;i++) {
        if (document.quiz_content.radio_quiz_answer[i].checked) {
          answer = document.quiz_content.radio_quiz_answer[i].value;
          document.getElementById('quiz_answer').value = answer;
        }
      }
      return answer;
    } else {
      return false;
    }
  }

  function determine_callback_params(splash_type) {
    // determine params given to campaign callback
    var callback_params;
    if (splash_type == 'init') {
      callback_params = 'lt='+(TimingEnd-TimingStart)+'&ts='+TimingStart+'&te='+TimingEnd;
    } else if (splash_type == 'pin') {
      callback_params = 'lt='+(TimingEnd-TimingStart)+'&ts='+TimingStart+'&ep='+clean_verify_validation(dom.byId("validation_code").value);
    } else if (!splash_type || splash_type == 'splash') {
      var quiz_answer = determine_quiz_answer();
      quiz_answer = (quiz_answer) ? quiz_answer : '';
      var msisdn             = dom.byId("msisdn");
      var mobile_operator_id = dom.byId("mobile_operator_id");
      callback_params = 'smart_abo_subscriber_id='+smart_abo_subscriber_id+'&msisdn='+clean_msisdn(msisdn.value)+'&mobile_operator_id='+mobile_operator_id.value+'&quiz_answer='+quiz_answer+'&lt='+(TimingEnd-TimingStart)+'&ts='+TimingStart+'&ep='+encodeURIComponent(dom.byId("validation_code").value);
    } else {
      callback_params = '';
    }
    return callback_params;
  }

  function process_campaign_callback(splash_type) {
    var callback_params = determine_callback_params(splash_type);

    var post = 'cmd=default&log_entry_id='+lid+'&campaign_id='+cid+'&partner_id='+pid+'&callback_params='+encodeURIComponent(callback_params);
	  new ajax('/campaign/xml.fcgi', {postBody: post, onComplete: processed_campaign_callback, onError: error_campaign_callback});
  }

  function processed_campaign_callback(request) {
	  	var tr_xml = dom.treeXML(request.responseXML.documentElement);
		  if (tr_xml.Ok[0].data == "1") {
  			//alert('callback_values updated');
	  	} else {
		    //alert('callback_values update error: '+tr_xml.Error[0].data);
		  }
	  }

	function error_campaign_callback() {
		//alert('error_campaign_callback');
	}

  var registered_reminder_action = false;
  function process_campaign_callback_counter(step) {
    var timestamp = (new Date()).getTime();
    if (pid == '18') {
      //preload tracking pixel for iCrossing
      var tracking_urls = [];
      if (step == 1) {
        tracking_urls[tracking_urls.length] = {data: 'https://www.traffictrack.de/tracking/tracking.php?kunde=buongiorno&cat=2&cid=2&ordnr='+lid};
      } else if (step == 2) {
        tracking_urls[tracking_urls.length] = {data: 'https://www.traffictrack.de/tracking/tracking.php?kunde=buongiorno&cat=3&cid=3&ordnr='+lid};
      }
      var preloader = new ImagePreloader(tracking_urls, function(){}, '');

    } else if (pid == '29') {
      // tracking pixel for DSNR
      var tracking_urls = [];
      if (step == 1) {
        tracking_urls[tracking_urls.length] = {data: 'http://ad.yieldmanager.com/pixel?id=314880&t=2&rnd='+timestamp};
      } else if (step == 2) {
        tracking_urls[tracking_urls.length] = {data: 'http://ad.yieldmanager.com/pixel?id=314880&t=2&rnd='+timestamp};
      }
      var preloader = new ImagePreloader(tracking_urls, function(){}, '');
    }
    
    var msisdn = dom.byId("msisdn");
    if (step == 1 && !registered_reminder_action && msisdn.className=="ok") {
      // register sms reminder
      var post = 'cmd=register_reminder&log_entry_id='+lid+'&campaign_id='+cid+'&partner_id='+pid+'&step='+step+'&msisdn='+clean_msisdn(msisdn.value)+'&smart_abo_id='+smart_abo_id;
	    new ajax('/campaign/xml.fcgi', {postBody: post, onComplete: function(){}, onError: function(){}});
	    registered_reminder_action = true;
    }
    
    // call counter
    var post = 'cmd=step_counter&log_entry_id='+lid+'&campaign_id='+cid+'&partner_id='+pid+'&step='+step;
	  new ajax('/campaign/xml.fcgi', {postBody: post, onComplete: processed_campaign_callback_counter, onError: error_campaign_callback_counter});
  }
  function processed_campaign_callback_counter(request) {
  }
	function error_campaign_callback_counter() {
	}

	function check_message(element) {

		if (element.name=="message_recipient_msisdn") {
			if (element.value.length > 0) {
			  var msisdn_clean = clean_msisdn(element.value);
				var ok = check_msisdn(msisdn_clean,network_prefixes);
				if (ok==0) {
					element.className = "error";
					return;
				} else if (ok==1) {
					element.className = "ok";
				} else {
					element.className = "";
				}
			} else {
				element.className = "";
				return;
			}
		}

		if (element.name=="message_text") {
			sms_message_char_counter();

			if (element.value.length > 0) {
					element.className = "ok";
			} else {
				element.className = "";
				return;
			}
		}
	}

function sms_message_char_counter(chars_max) {
	var text_chars=0, text_length=0;

	var message_text = document.getElementById("message_text");
	var message_char_left = document.getElementById("message_char_left");
	var message_sms_count = document.getElementById("message_sms_count");

	var text = message_text.value;

	if (!chars_max) chars_max = 160;

	for (var i=0; i<text.length; i++) {
		var schar = text.charAt(i);
		if (schar=='€' || schar=='~' || schar=='^' || schar=='\\' || schar=='{' || schar=='}' || schar=='[' || schar==']' || schar=='|') {
			if (text_chars>(chars_max-2)) { break };
			text_chars+=2;
		} else if (schar=="\r") {
			// not count linefeed
		} else {
			if (text_chars>(chars_max-1)) { break };
			text_chars++;
		}
		text_length = i+1;
	}

	if (text.length > text_length) {
		message_text.value = text.substring(0,text_length);
	}

	if (message_char_left) message_char_left.value = chars_max-text_chars;
	if (message_sms_count) {
		if (text_length > 160) {
			message_sms_count.value = parseInt((text_chars-1)/153)+1;
		} else {
			message_sms_count.value = 1;
		}
	}
}


/* START SubmitFormOnEnter */
function SubmitFormOnEnter(elem,cancel,fn){
   
   var me = this;
   this.elem = document.getElementById(elem);
   
  //Keycodes que devem ser monitorados
   var ENTER = 13;
   
   //Rotina no KEYUP (pegar input)
   me.elem.onkeyup = function(ev) {
     var key = me.getKeyCode(ev);
	   
	   check_send_validation(this);
	   
     if (key == ENTER) {
      if (fn) {
        // dont submit, call function, cancel event bubbleing
        fn();
      } else {
        var frm = me.elem.form;
        frm.submit();
        me.cancelEvent(ev);
      }
      if (cancel == true) me.cancelEvent(ev);
     }
   };
   
   me.elem.onkeydown = function(ev) {
     var key = me.getKeyCode(ev);
     
     if (key == ENTER) {
       if (cancel == true) me.cancelEvent(ev);
     }
   };
   
   
  //HELPER FUNCTIONS
   
   /********************************************************
   Helper function to determine the keycode pressed in a 
   browser-independent manner.
   ********************************************************/
   this.getKeyCode = function(ev)
   {
    if(ev)   //Moz
    {
     return ev.keyCode;
    }
    if(window.event) //IE
    {
     return window.event.keyCode;
    }
   };
   
   /********************************************************
   Helper function to determine the event source element in a 
   browser-independent manner.
   ********************************************************/
   this.getEventSource = function(ev)
   {
    if(ev)   //Moz
    {
     return ev.target;
    }
   
    if(window.event) //IE
    {
     return window.event.srcElement;
    }
   };
   
   /********************************************************
   Helper function to cancel an event in a 
   browser-independent manner.
   (Returning false helps too).
   ********************************************************/
   this.cancelEvent = function(ev)
   {
    if(ev)   //Moz
    {
     ev.preventDefault();
     ev.stopPropagation();
    }
    if(window.event) //IE
    {
     window.event.returnValue = false;
    }
   }
  }
  /* END SubmitFormOnEnter */



//]]>
 

