function initiate_country_select( ccid, cctxtid ) { document.getElementById( ccid ).onchange = function( ) { fillCCbox( ccid ); }; document.getElementById( cctxtid ).onchange = function( ) { cc2cnt( document.getElementById( cctxtid ), document.getElementById( ccid ) ); }; document.getElementById( cctxtid ).onchange( ); } function initiate_call_form( ) { var destcc = document.getElementById( 'destcc' ); var srccc = document.getElementById( 'srccc' ); // Set up the addressbook dialog, if the link is showing. if( $('#address_book_link').css( 'display' ) != 'none' ) { // If the function exists, and we're not hiding the link, then // load the dialog box. if( typeof( $('#addressbook_dialog').dialog ) != 'undefined' ) { $('#addressbook_dialog').dialog( { autoOpen: false, modal: true, title: 'Select a contact to call', width: 620, height:400, resizable: false } ); $('#address_book_link').click( function( ) { $('#addressbook_dialog').dialog('open'); }); } } destcc.onchange = function () { fillCCbox('destcc'); frontpage_request_rate(); }; srccc.onchange = function () { fillCCbox('srccc'); frontpage_request_rate(); }; document.getElementById( 'destcctxt' ).onchange = function () { cc2cnt( document.getElementById( 'destcctxt' ), document.getElementById( 'destcc' ) ); }; // trigger now in case a value was set on page load document.getElementById( 'destcctxt' ).onchange( ); document.getElementById( 'srccctxt' ).onchange = function () { cc2cnt( document.getElementById( 'srccctxt' ), document.getElementById( 'srccc' ) ); }; // trigger now in case a value was set on page load document.getElementById( 'srccctxt' ).onchange( ); var srctn = document.getElementById( 'srctn' ); var desttn = document.getElementById( 'desttn' ); // max length is actually 15 - len(cc); cc is at least one, hence 14 /* WHOA -- can't do this nuless we allow ONLY numbers in the entry field; * ergo, we must allow some leeway in field length :| */ srctn.maxLength = desttn.maxLength = 30; // should be safe //srctn.onkeydown = desttn.onkeydown = numbers_only; srctn.onkeyup = desttn.onkeyup = frontpage_request_rate; /*document.getElementById( 'call' ).onclick = verifycall;*/ document.getElementById( 'call_form' ).onsubmit = verifycall; var ratefield = document.getElementById('currrate'); ratefield.style.display = 'none'; } function set_call_destination( cc, nsn ) { $('#destcctxt').val( cc ); $('#desttn').val( nsn ); cc2cnt( document.getElementById( 'destcctxt' ), document.getElementById( 'destcc' ) ); $('#addressbook_dialog').dialog( 'close' ); frontpage_request_rate( ); } function set_call_source( cc, nsn ) { $('#srccctxt').val( cc ); $('#srctn').val( nsn ); cc2cnt( document.getElementById( 'srccctxt' ), document.getElementById( 'srccc' ) ); frontpage_request_rate( ); } function frontpage_request_rate( e ) { // note that the first character of cc is '+' var srcccEl = document.getElementById('srccc'); var dstccEl = document.getElementById('destcc'); var src = srcccEl.options[srcccEl.selectedIndex].value; var dst = dstccEl.options[dstccEl.selectedIndex].value; var src_check = document.getElementById('srctn').value; var dst_check = document.getElementById('desttn').value; if( src_check.length > 2 && dst_check.length > 2 ) { // both non-null src = src.toString() + src_check; dst = dst.toString() + dst_check; request_rate( src, dst ); } } /** * Allows entry of a character if and only if it is a number. * Note that keycodes vary depending on which event is used. Be aware of this. * @param e Event which triggered the call. */ function numbers_only( e ) { if( !e ) var e = window.event; var ch = e.which ? e.which : e.keyCode; if( ch >= 48 && ch <= 57 && !e.shiftKey ) return true; // 0-9 else if( ch >= 96 && ch <=105 ) return true; else if( ch==8 || ch==46 || ( ch>=35 && ch<=37 ) || ch==39 ) return true; // bs, del, (end, home, left), right else return false; } /** * Ensures that all fields required to place a call are filled. */ function verifycall( ) { var sccEl = document.getElementById( 'srccc' ); var dccEl = document.getElementById( 'destcc' ); var scc = sccEl.options[ sccEl.selectedIndex ].value var dcc = dccEl.options[ dccEl.selectedIndex ].value var stn = document.getElementById( 'srctn' ).value; var dtn = document.getElementById( 'desttn' ).value; var form = document.getElementById( 'call_form' ); if( scc == '' ) alert( 'Please select the country from which you are calling.' ); else if( dcc == '' ) alert( 'Please select the country which you are calling.' ); else if( stn == '' ) alert( 'Please enter the phone number from which you are calling.' ); else if( dtn == '' ) alert( 'Please enter the phone number which you are calling.' ); else return true; //form.submit(); return false; } /* Thx to PPK */ function popup( url ) { var newwin = window.open( url, 'name', 'height=400,width=650' ); if( window.focus ) newwin.focus(); return false; }