var id = 0; // Nazwy miesięcy var monthNames = ['Jan','Feb','Mar','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec']; function getDateTime() { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); var hour = date.getHours(); var minutes = date.getMinutes(); var sec = date.getSeconds(); if ( minutes < 10 ) minutes = '0' + minutes; //12:05 Jul 28 return hour + ':' + minutes + ' ' + monthNames[ month ] + ' ' + day; } $(function() { $("#text-submit").click(function() { submit(); return false; }); $('#text-input').keyup(function(e) { if( e.keyCode == 13 ) { submit(); } }); function submit() { if ($("#text-input").val()=="") return false; toggle_loading(); add_message('user', $("#text-input").val()); //odpowiedz od serwera $.ajax({ type: "GET", cache: false, url: 'proxy.php?msg=' + $("#text-input").val(), success: function(output) { output = replaceAll( output, 'Arial', '' ); if (!check_if_url(output)) { $("#text-input").val(""); add_message('bot', output); } toggle_loading(); }, error: function(output) { $("#text-input").val(""); add_message('bot', '...'); toggle_loading(); } }); return false; }; $.ajax({ type: "GET", cache: false, url: 'proxy.php?cmd=welcome', success: function(output) { output = replaceAll( output, 'Arial', '' ); if (!check_if_url(output)) { $("#text-input").val(""); add_message('bot', output); } }, error: function(output) { $("#text-input").val(""); add_message('bot', '...'); } }); //$("#text-input").focus(); return false; }); function check_if_url(s) { var txt = s.split("|@|"); var url = txt[0]; if ( url.indexOf('url=') != -1 ) { url = url.substr(4, url.length ); if (window.opener) { if ( url.indexOf( dm ) != -1 ) { window.opener.location.href = url; } else { window.open( url,'640x480','width=640,height=480'); } } else { window.open( url,'640x480','width=640,height=480'); } if ( txt[1].length > 0 ) { add_message('bot', txt[1] ); } $("#text-input").val(""); return true; } return false; } function replaceAll(haystack, needle, replacement) { var strReplaceAll = haystack; var intIndexOfMatch = strReplaceAll.indexOf( needle ); while (intIndexOfMatch != -1){ strReplaceAll = strReplaceAll.replace( needle, replacement ); intIndexOfMatch = strReplaceAll.indexOf( needle ); } return strReplaceAll; } function add_message(who, message) { var sAddOn = ''; message = replaceAll( message, '|BR|', '
' ); //musi byc w jednej linijce bo sie psuje w IE6 if ( who == 'bot' ) { $("#messages").append(''); } else { $("#messages").append(''); } $("div#msg_"+ id).fadeIn(); id++; } var input_disabled = false; function toggle_loading() { if (!input_disabled) { $('#text-input').attr("disabled", true); $('input#input_submit').attr("disabled", true); } else { $('#text-input').removeAttr("disabled"); $('input#input_submit').removeAttr("disabled"); $('#text-input').focus(); } input_disabled = !input_disabled; var pane = document.getElementById('messages'); pane.scrollTop = pane.scrollHeight; }