var CostumWindow_obj;
Event.observe(window, 'load', function () {
	if($('cW_callback_open')) {
		CostumWindow_obj = new CostumWindow('cW_callback_open','cW_callback_close', 'cW_callback_content', 'bodyid');
		
		CostumWindow_obj.onWindowOpen = function() {
			$('cW_callback_percent_div').innerHTML = '';
			$('cW_callback_input').focus();
			
		}
	}
});

var progress = -400;
var progressPercent = 0;
//preload
bild01 = new Image();
bild01.src = "/layout/_general/feedback_hover_btn.png";
bild02 = new Image();
bild02.src = "/layout/_general/percentImage_back.png";
//trim func
function trimIt(x) {

	 // skip leading and trailing whitespace
	 // and return everything in between
	  x=x.replace(/^\s*(.*)/, "$1");
	  x=x.replace(/(.*?)\s*$/, "$1");
	  return x;
}




document.observe("dom:loaded", function () {
	//Das feld mit ESC schliesen
	Event.observe('cW_callback_input', 'keydown', function (evt) {
        keyDownActive = 1;
        if (getKeyCode(evt) == 27) 
        {
        	CostumWindow_obj.closeWindow();
        }
        keyDownActive = 0;
    });
	
	//zeichen des textfelds beschränken
	$('cW_callback_input').observe('keyup', function(){
		if($('cW_callback_input').value.length>500)
		{
			$('cW_callback_input').value = $('cW_callback_input').value.substr(0,500);
			$('cW_callback_input').scrollTop = $('cW_callback_input').scrollHeight;
		}
	});
	
	//zeichen des rufnummerfeldes beschränken
	$('cW_callback_input_rufnummer').observe('keyup', function(){	
		if($('cW_callback_input_rufnummer').value.length>20)
		{
			$('cW_callback_input_rufnummer').value = $('cW_callback_input_rufnummer').value.substr(0,20);
			$('cW_callback_input_rufnummer').scrollTop = $('cW_callback_input_rufnummer').scrollHeight;
		}
	});
	
	$('cW_callback_submit').observe('click', function() {
		
		
		//trim function
		x=trimIt($('cW_callback_input').value);
		x2=trimIt($('cW_callback_input_rufnummer').value);
			
		
		if(x == '')
			$('cW_callback_input').focus();
		else if(x2 == '')
			$('cW_callback_input_rufnummer').focus();
		else
		{

			showProgress();
			$('cW_callback_percent_div').setStyle({ color: '#04B404'});
			 var options = {
	            method: 'post',
	            parameters: {
	                tele:$('cW_callback_input_rufnummer').value,txt: $('cW_callback_input').value
	            }
	        };
	        new Ajax.Request('/inc/costumWindow/cW_callback_mail.php', options)
		}
	});
	
});
if(Prototype.Browser.IE  || Prototype.Browser.Opera)
	var refreshTime = 1;
else
	var refreshTime = 10;
	
function showProgress()
{
    $('cW_callback_status_bar_bg').show();
	$('scW_callback_status_bar').show();
	$('percentImage').style.backgroundPosition = progress + 'px';
	progress += 3;
	progressPercent += 0.745;
	$('cW_callback_percent_div').innerHTML = (Math.round(progressPercent)) + ' %';
	if(progress < 2)setTimeout("showProgress()",refreshTime);
	else {
		$('percentImage').style.backgroundPosition = 1 + 'px';
		progress = -400;
		progressPercent = 0;
		setTimeout('CostumWindow_obj.closeWindow();', 1000);
		setTimeout("$('scW_callback_status_bar').hide();",1001);
		setTimeout("$('cW_callback_status_bar_bg').hide();",1001);
		setTimeout("$('percentImage').style.backgroundPosition = '-120px';", 1300);
	   
	}
}