    top.opener = null;
    function toggleTerminals() {
        var terminalsDiv = $('terminals');
        terminalsDiv.style.display = (terminalsDiv.style.display == 'none' ? 'block' : 'none');
        return false;
    }
    
    var puting = false;
    
    function aocPut(link) {
    	//jesli juz pobieramy to nie wysylamy wiecej zadan do serwera
        if (($('ajaxInProgress') != null) || (puting)) {
            return false;
        }
        //jesli nie waliduje sie msisdn to nie pozwalamy kupic elementu
        if (document.phoneForm && 
            document.phoneForm.phoneNumber.value.length != 9 &&
            document.phoneForm.phoneNumber.value.length != 11) {
            if ($('errorMsisdn')) {
	        	$('errorMsisdn').style.display = 'block';
	        }            
            return false;
        }       
        else {
        	if ($('errorMsisdn')) {
        		$('errorMsisdn').style.display = 'none';
        	}
		}            
        //zaznaczamy ze jestesmy w trakcie zakupu
        puting = true;
        showWait();
        var oSpan = document.createElement("span");
        oSpan.id = 'ajaxInProgress';
        $('aocDownloadDiv').appendChild(oSpan);
        var rcv = "";        
        if (document.phoneForm) {
        	if (link.indexOf('?') == -1) {
	        	rcv = "?pl_tls_mdpl_rcv_msisdn=" + document.phoneForm.phoneNumber.value;
	        }
	        else {
	        	rcv = "&pl_tls_mdpl_rcv_msisdn=" + document.phoneForm.phoneNumber.value;	        	
	        }	
        }
        var myAjax = new Ajax.Updater('aocDownloadDiv', link + rcv, {evalScripts: true});
        puting = false;
    }
    function aocPutWithParsFromForm(link) {
        showWait();
        var pars = Form.serialize('wwwSendPostcardForm');
        var myAjax = new Ajax.Updater('aocDownloadDiv', link, {evalScripts: true, parameters: pars});
    }
    function sendPostcardForm() {
        showWait();
        var url = $('wwwSendPostcardForm').action;
        var pars = Form.serialize('wwwSendPostcardForm');
        var myAjax = new Ajax.Updater('aocDownloadDiv', url, {method: 'post', parameters: pars, evalScripts: true});
        return false;
    }

    function sendTo() {
        $('toggle_terminals_div').style.display = "block";
        $('send_to_div').style.display = "none";
    }    
    
    function validatePhone(obj) {
        if ((obj.value[obj.value.length-1] < '0') || (obj.value[obj.value.length-1] > '9')) {
            obj.value = obj.value.substring(0, obj.value.length - 1);    
        }
        obj.value = obj.value.substring(0,11);     
        //jesli msisdn jest za krotki to wyswietlamy komunikat o bledzie
        if (obj.value.length == 11 || obj.value.length == 9) {
        	$('errorMsisdn').style.display = 'none';
        }
    }
	function toself(phone) {
        $("toself").style.display = "block";
        $("toother").style.display = "none";
        if (document.phoneForm) {
        	document.phoneForm.phoneNumber.value = phone;
        }
        return false;
    }
    function toother() {
    	$("toself").style.display = "none";
		$("toother").style.display = "block";
        return false;
    }
    function isEmpty(field) {
   		if ((field.value.length==0) || (field.value==null)) {
     		return true;
   		}
   		else { return false; }
	}
    
    
    function checkFormAndGoto(link,element,defaultPhoneNumber) {

    	var rcv = "";
    	var destPhoneNumber="";
    	
		if (document.phoneForm && !isEmpty(document.phoneForm.phoneNumber)) {
			if (document.phoneForm && document.phoneForm.phoneNumber.value.length != 9 && document.phoneForm.phoneNumber.value.length != 11) {
            	if ($('errorMsisdn')) {
	        		$('errorMsisdn').style.display = 'block';
	        	}            
            	return false;
            } else {
            	if ($('errorMsisdn')) {
        			$('errorMsisdn').style.display = 'none';
        		}
        		destPhoneNumber = document.phoneForm.phoneNumber.value;
            }
        }else {
        	destPhoneNumber = defaultPhoneNumber;
        }
        
        if (document.phoneForm){
        	if (link.indexOf('?') == -1) {
        		rcv = "?pl_tls_mdpl_rcv_msisdn=" + destPhoneNumber;
        	}
        	else {
        		rcv = "&pl_tls_mdpl_rcv_msisdn=" + destPhoneNumber;	        	
        	}
        }       
      
       	element.href = link + rcv ;
       	return true;
   
    }
    
