document.state = 'browse'; document.site = ''; //mode='debug'; mode='normal'; apps=new Object(); apps.logs={ajaxurl:'http://www.gpsrace.ch/wp-content/themes/hpf/modules_app/logs'}; apps.gpsrace={ajaxurl:'http://www.gpsrace.ch/wp-content/themes/hpf/modules_app/gpsrace'}; apps.paypal={ajaxurl:'http://www.gpsrace.ch/wp-content/themes/hpf/modules_app/paypal'}; apps.translate={ajaxurl:'http://www.gpsrace.ch/wp-content/themes/hpf/modules_app/translate'}; registered_modules = new Array(); loaded_app_css = new Array(); front_module_name = ""; ajax_calls = 0; app_team_name = ""; timediff=0; username=""; token=""; // cache ajax_cache = new Array(); cache_patterns = new Array(); cache_patterns[0]=/get_module\.php/; cache_patterns[1]=/cmd=set_page/; cache_patterns[2]=/cmd=get_trip_data/; // ping ping_delay_slow=40000; ping_delay_fast=10000; ping_delay = ping_delay_slow; window.onerror = function(m,f,r) { //alert(m+'\n'+f+'\n'+r); null; } function clear_page() { //hide modules for (var a in registered_modules) { if (a!='banner' && a!='state' && a!='panel' && a!='tabs' && a!='ajax_sender' && a!= 'debug') { if(registered_modules[a].style.display!='none') registered_modules[a].hide(); } } } function set_page(description, refresh_param, clear, header) { if (registered_modules['debug']) { registered_modules['debug'].set_type('user'); registered_modules['debug'].add_text('set_page('+description+','+refresh_param+','+clear+','+header+')'); } //if (clear==1) clear_page(); //submit request to get new page layout AjaxPOSTRequest('','process.php', 'cmd=set_page&description='+description+'&refresh_param='+refresh_param); if (header && registered_modules.state) { document.site = header; registered_modules.state.refresh(); } } function set_page_modules(page_modules, refresh_param) { var active_modules=new Object(); for (var i=0; i0) nr_pages++; var t=document.createElement('TABLE'); pages_container.appendChild(t); var r=t.insertRow(0); for (var i=1; i<=nr_pages; i++) { var l=r.insertCell(i-1); l.innerHTML=""+i+""; l.setAttribute((document.all ? 'className' : 'class'), 'paging_element'); l.onmouseout = function() {if (this.t.current_page!=this.i) this.style.background='';}; l.t=this; l.i=i; l.onclick=function() {this.t.render(this.i);}; this.pages[i]=l; } } //populate multi_actions_div with multi-actions this.refresh_multi_actions = function() { if(!this.multi_actions_div || !this.multi_actions || !this.multi_actions_div.innerHTML) { return; } var a = this.get_checked(); var nr_selected=a.length; if (nr_selected<=1) this.multi_actions_div.style.visibility='hidden'; var showing_actions=0; if (nr_selected>1) { this.multi_actions_div.innerHTML = ''; var t=document.createElement('TABLE'); this.multi_actions_div.appendChild(t); var r=t.insertRow(0); for (var i=0; i'; l.onmouseover = function() {this.style.background='url(http://www.gpsrace.ch/wp-content/themes/hpf/images/nr_high.png)'}; l.onmouseout = function() {this.style.background='';}; l.t = this; l.i = i; l.onclick = function() { this.t.multi_actions[this.i].callback(this.t.get_checked()); }; showing_actions++; } } if(showing_actions>0) this.multi_actions_div.style.visibility=''; } } my_table.prototype.clear_data = function() { for(var i=0; ib[column_name]); } else return 0; } this.data.sort(sort_me); if (sort_order=='desc') this.data.reverse(); }; my_table.prototype.render = function(pagenr) { if(this.row_events.table_render_start) this.row_events.table_render_start(); if(!pagenr) pagenr=1; this.current_page=pagenr; //clear highlighted pages and reset highlight on current page for (var i=1; i<=this.pages.length-1; i++) { this.pages[i].style.background=''; } if(this.pages.length) this.pages[pagenr].style.background='url(http://www.gpsrace.ch/wp-content/themes/hpf/images/nr_high.png)'; this.clear_data(); //now this.data rows var start_nr=this.style.page_size*(this.current_page)-this.style.page_size; var end_nr=this.style.page_size*(this.current_page); this.data_table.rows = new Array(); for (var i=start_nr; i'; cell.onclick = function() { this.t.actions[this.action_id].callback(this.key, this.data); } } row.appendChild(cell); } } if(this.row_events.row_constructor && !row.ref.constructor_called) { this.row_events.row_constructor(row); row.ref.constructor_called = 1; } if (this.row_events.row_show) this.row_events.row_show(row); } if(this.row_events.table_render_end) this.row_events.table_render_end(); }; my_table.prototype.get_checked = function() { var a = new Array(); for (var i=0; i name of the module, must be unique // module_parent => module_name of the container module, "" if top level // module_class => CSS class of the DIV tag // module_html => html code for the UI, this can contain elements // module_functions => [ // array of js functions of the form: // f = function(p) {alert(p);} // ] // ] ///////////////////////////////////////////////////////////////////////////////////////////////// function register_module(module) { if (!loaded_app_css[module.app]) { load_app_css(module.app); } if (mode=='debug' && registered_modules['debug']) { registered_modules['debug'].set_type('module'); registered_modules['debug'].add_text('creating module '+module.module_name); } var id = module.module_name; var has_constructor = 0; // check if a module with the same name is already registered if (registered_modules[id]) { //alert("error occurred while trying to register module "+id+" - it's already registered"); return; } // create a new DIV tag for the new module var new_div = document.createElement('div'); new_div.setAttribute('id', id); new_div.id=id; new_div.init = new Array(); new_div.init.top = -10; new_div.init.left = -10; new_div.init.height = -10; new_div.init.width = -10; if (module.border_width) new_div.init.border_width=parseInt(module.border_width); else new_div.init.border_width=20; new_div.z_front = 101; new_div.z_back = 100; new_div.className = 'module '+module.module_class; new_div.fancy_border = new Array(); // create fancy border border_factory = function(loc, c) { var border_cell = document.createElement('div'); border_cell.className= 'border_'+c+'_'+loc; return border_cell; }; var locs = new Array('tl', 't', 'tr', 'c', 'bl', 'b', 'br', 'l', 'r'); for (var i in locs) { new_div.fancy_border[locs[i]] = border_factory(locs[i], module.module_class); new_div.appendChild(new_div.fancy_border[locs[i]]); } // end fancy border var cell = document.createElement('div'); if (module.has_menu == 1) { new_div.border_top_all = cell; cell.className= 'module_menu'; new_div.appendChild(cell); cell.innerHTML = module.module_name; cell.onmousedown = function(e) { var target; if(!window.ActiveXObject){ target=e.target; } else { target=event.srcElement; e=event; } if (new_div.moveable==1 && new_div.style.zIndex == new_div.z_front) { new_div.do_move=1; moving_module = new_div.id; dragOBJ(new_div,e); document.action = 'moving'; new_div.onselectstart = function() { return false; }; new_div.unselectable = "on"; new_div.style.MozUserSelect = "none"; new_div.style.cursor = "default"; } } cell = document.createElement('div'); cell.className= 'closer'; cell.onclick = function(e) { new_div.destroy(); if(resizer_div) resizer_div.style.visibility = 'hidden'; } new_div.appendChild(cell); cell = document.createElement('div'); if(module.main_div_class) cell.className = module.main_div_class; else cell.className= 'module_main_div'; } else { if(module.main_div_class) cell.className = module.main_div_class; else cell.className= 'module_main_div_nomenu'; } cell.innerHTML = module.module_html; new_div.appendChild(cell); if(module.moveable==1 && module.has_menu!=1) { cell = document.createElement('div'); cell.className='mover_menu_div'; cell.style.width=module.w-40+'px'; cell.innerHTML = ''; cell.onmousedown=function(e) { var target; if(!window.ActiveXObject){ target=e.target; } else { target=event.srcElement; e=event; } new_div.do_move=1; moving_module = new_div.id; dragOBJ(new_div,e); document.action = 'moving'; } new_div.appendChild(cell); } if(module.has_closer==1 && module.has_menu!=1) { cell = document.createElement('div'); cell.className='closer'; cell.innerHTML = ''; cell.onmousedown=function(e) { var target; if(!window.ActiveXObject){ target=e.target; } else { target=event.srcElement; e=event; } new_div.destroy(); } new_div.appendChild(cell); } new_div.moveable = 0; new_div.resizeable = module.resizeable; new_div.has_destructor = 0; new_div.module_param = module.module_param; // add the new div to the container if (module.parent_id!="") { p=document.getElementById(module.parent_id); if (p) p.appendChild(new_div); else { alert("error occurred: parent module ("+module.parent_id+") for new module ("+module.module_name+") not found"); return; } } else { //document.getElementsByTagName("body")[0].appendChild(new_div); //document.getElementById('page-bdy').appendChild(new_div); if(document.getElementById('content')) document.getElementById('content').appendChild(new_div); else return; } // add the module's methods // it's done using eval something like this: // eval('new_div.f = function(x) {alert("x");}'); // where 'f = function.... ' comes from the module array var script_clean='null;'; //var to_eval = 'new_div.debug_me=function(a,t){module_send("debug", "set_type(t)");module_send("debug", "add_text(\''+id+': "+a+"\')");}'; var to_eval = 'new_div.debug_me=function(a,t){try{d=registered_modules.debug; d.set_type(t); d.add_text(""+id+": "+a);}catch(e){null;}}'; eval(to_eval); for(var i=0, j=module.module_scripts.length; i < j; i++) { script_clean = module.module_scripts[i].replace('\n',''); var fdef=script_clean.split(/{/)[0].replace(" ",""); var fname=fdef.split(/=/)[0].replace(" ",""); var fparams=fdef.split(/\(/)[1]; if (fname != 'hp_constructor') { to_eval='new_div.'+script_clean; } else { to_eval='new_div.'+script_clean; has_constructor = 1; } if (mode=='debug' && id!='debug' && id!='ajax_sender') { to_eval = 'new_div.'+script_clean.replace(/{/, '{if (registered_modules["debug"] && mode=="debug") registered_modules["debug"].add_text("'+id+'.'+fname+'('+fparams+';");'); } //if (mode=='debug') { try { eval(to_eval); } catch(e) {alert(module.module_name+':\n'+e.name+' -> '+e.description);} //} //else eval(to_eval); if (script_clean.substring(0,10) == 'destructor') { new_div.has_destructor = 1; } } // add common methods // show() to show the module // hide() to hide the module new_div.show = function() { if (new_div.id == 'Map') { new_div.style.visibility="visible"; } else { //new_div.style.display = 'block'; $(new_div).fadeIn('slow'); } front_module(new_div.id); if (new_div.show_me) new_div.show_me(); }; new_div.hide = function(init) { if (new_div.id=='Map') { new_div.style.visibility="hidden"; } else { //new_div.style.display = 'none'; $(new_div).fadeOut('slow'); } if (new_div.hide_me && !init) new_div.hide_me(); }; new_div.destroy = function() { //logit('closed module '+new_div.id); if (new_div.has_destructor == 1){ new_div.destructor(); } try{new_div.parentNode.removeChild(new_div);}catch(e){null;} delete registered_modules[new_div.id]; }; new_div.moveable = function(b) { new_div.moveable = b; }; new_div.set_height = function(h) { var h=parseInt(h); if(isNaN(h)) return; if (new_div.init.height==-10) new_div.init.height=h; if(h==-1) { new_div.style.bottom=new_div.init.border_width+'px'; new_div.style.top=new_div.init.border_width+'px'; } else { new_div.style.height = h+"px"; new_div.height = h; } if ('l' in new_div.fancy_border && new_div.height>new_div.init.border_width) { new_div.fancy_border.l.style.height = new_div.height-2*new_div.init.border_width + 'px'; new_div.fancy_border.r.style.height = new_div.height-2*new_div.init.border_width + 'px'; new_div.fancy_border.c.style.height = new_div.height-2*new_div.init.border_width + 'px'; } if(new_div.resize_callback) try{ new_div.resize_callback(new_div.width, h); } catch(error){null;} }; new_div.set_width = function(w) { w=parseInt(w); if(isNaN(w)) return; if (new_div.init.width==-10) new_div.init.width=w; if (w==-1) { new_div.style.right=new_div.init.border_width+'px'; new_div.style.left=new_div.init.border_width+'px'; } else { new_div.style.width = w+"px"; new_div.width = w; } if ('t' in new_div.fancy_border && new_div.width>new_div.init.border_width) { new_div.fancy_border.t.style.width = new_div.width-2*new_div.init.border_width + 'px'; new_div.fancy_border.b.style.width = new_div.width-2*new_div.init.border_width+ 'px'; new_div.fancy_border.c.style.width = new_div.width-2*new_div.init.border_width+ 'px'; } if(new_div.resize_callback) try{ new_div.resize_callback(w, new_div.height); } catch(error) {null;} }; new_div.set_top = function(i) { i=parseInt(i); if(isNaN(i)) return; if (new_div.init.top == -10) new_div.init.top = i; if (i==-1) { if (window.ActiveXObject) { i = document.body.offsetHeight/2 - new_div.height/2; } else if (window.innerHeight) { i = window.innerHeight/2 - new_div.height/2; } else { i=100; } } //if (i<0) { // i=50; //} // alert(new_div.id+': setting top to '+i); new_div.style.top = i + "px"; new_div.top = i; }; new_div.set_left = function(i) { i=parseInt(i); if(isNaN(i)) return; if (new_div.init.left == -10) new_div.init.left = i; if (i==-1) { if (window.ActiveXObject) { i = document.body.offsetWidth/2 - new_div.width/2; } else if (window.innerWidth) { i = window.innerWidth/2 - new_div.width/2; } else { i=200; } } new_div.style.left = i + "px"; new_div.left = i; }; new_div.onmousedown = function(e) { front_module(new_div.id); }; //finally add it to the registered modules array registered_modules[module.module_name] = new_div; //hide the module per default // new_div.hide(1); if (new_div.id!='Map')new_div.style.display = 'none'; else new_div.hide(1); if (module.resizeable == 1) { new_div.onmouseover = function() { if (!document.action) { resizer_div.mother_div = this; resizer_div.style.top = parseInt(this.style.top) + parseInt(this.style.height) - 30 + 'px'; resizer_div.style.left = parseInt(this.style.left) + parseInt(this.style.width) - 30 + 'px'; resizer_div.style.visibility = "visible"; return false; } } } //end resizer //call the constructor method if (has_constructor == 1) { new_div.hp_constructor(); } // check and run if post-module command if (module.post_module_name && module.post_module_name != '') { module_send(module.post_module_name, module.post_module_message); } // finally bring it to the front, so it's visible and not behind another mod. front_module(new_div.id); if (module.post_js!='') { setTimeout('eval("'+module.post_js+'");', 50); } try_next_cmd(); } ///////////////////////////////////////////////////////////////////////////////////////////////// // module_send(module_name, message) // this function is used to communicate with the registered modules // e.g.: // module_send('test_module','show()'); ///////////////////////////////////////////////////////////////////////////////////////////////// function module_send(module_name, message) { if (registered_modules[module_name]) { try { eval("registered_modules['"+module_name+"']."+message); } catch (error) { null; } } } ///////////////////////////////////////////////////////////////////////////////////////////////// function AjaxPOSTRequest(app, url, param_string, sync) { var app_url='http://www.gpsrace.ch/wp-content/themes/hpf'; if(app in apps) app_url=apps[app].ajaxurl; url=app_url+'/'+url; var xmlHttpRequest; var uri=url; var cache_it=0; var from_cache=""; var do_cache=0; var ajax_indicator=0; var ajax_receiver=0; if (document.getElementById("ajax_indicator")) { ajax_indicator = document.getElementById("ajax_indicator"); } if (window.XMLHttpRequest) { xmlHttpRequest = new XMLHttpRequest(); can_cache=1; } else if (window.ActiveXObject) { try { xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert("no XMLHttp support detected on your browser"); return null; } } } if (param_string!=""){ uri=url+"?"+param_string; } from_cache = ""; for (var i=0; i "+param_string; try { registered_modules['debug'].set_type('ajax'); registered_modules['debug'].add_text(debug_message); } catch(error) {null;} } if (param_string.substring(0,8) != "cmd=ping") { ajax_calls++; module_send('ajax_sender', 'show()'); if (ajax_indicator!=0) ajax_indicator.style.visibility = "visible"; } if (from_cache == "" || sync) { xmlHttpRequest.send(param_string); if(sync) return xmlHttpRequest.responseText; } else { internal_callback(); } function internal_callback() { module_send('ajax_sender','receive()'); if (from_cache != "" || (xmlHttpRequest.readyState == 4 && xmlHttpRequest.responseText)) { if (param_string.substring(0,8) != "cmd=ping") { ajax_calls--; if (ajax_calls == 0) { module_send('ajax_sender', 'hide()'); if (ajax_indicator!=0) ajax_indicator.style.visibility = "hidden"; } } if (cache_it == 1) { ajax_cache[uri] = xmlHttpRequest.responseText; } var response = ""; if (from_cache != "") { response = from_cache; } else { response = xmlHttpRequest.responseText; } if (response=="") return; try { var ajax_array = eval("("+response+")"); } catch(e) { alert(e.name+':'+e.message+'\n'+param_string+'\n---->'+response); } if (ajax_array==undefined) return; delete xmlHttpRequest; if (ajax_array.alert) { alert(ajax_array.alert); } if (ajax_array.module && ajax_array.module.module_name) { register_module(ajax_array.module); } if(ajax_array.module_messages) { for(var i=0, j=ajax_array.module_messages.length; i < j; i++) { if (registered_modules['debug']) { try{ registered_modules['debug'].set_type('ajax module message'); } catch(error){null;} } module_send(ajax_array.module_messages[i].module_name, ajax_array.module_messages[i].message); } } if (ajax_array.javascript) { var re = //igm; var myScripts = ajax_array.javascript.split(re); for(var i=0, j=myScripts.length; i < j; i++) { try{ registered_modules['debug'].set_type('ajax js'); } catch(error){null;} eval(myScripts[i]); } } } } } function direct_callback(response) { var ajax_array = eval(response); if (ajax_array==undefined) { alert('error in direct_callback with response:\n'+response); return; } if(ajax_array.module) { register_module(ajax_array.module); } if(ajax_array.module_messages) { for(var i=0, j=ajax_array.module_messages.length; i < j; i++) { try{ registered_modules['debug'].set_type('ajax module message'); } catch(error){null;} module_send(ajax_array.module_messages[i].module_name, ajax_array.module_messages[i].message); } } if (ajax_array.alert) { alert(ajax_array.alert); } if (ajax_array.javascript) { var re = //igm; var myScripts = ajax_array.javascript.split(re); for(var i=0, j=myScripts.length; i < j; i++) { try{ registered_modules['debug'].set_type('ajax js'); } catch(error){null;} eval(myScripts[i]); } } } ///////////////////////////////////////////////////////////////////////////////////////////////// // ping() // this function pings to the server var ping_count = 0; function ping(delay) { // thing that must happen at the beginning if (ping_count == 0) { // get the client's time do_ping(); } else { if (delay) setTimeout('do_ping();', delay); else setTimeout('do_ping();', ping_delay); } ping_count++; } function do_ping() { if (ping_count == 0) { var d = new Date(); var value = d.getHours(); AjaxPOSTRequest('',"process.php", "cmd=client_time&value="+value); } else { AjaxPOSTRequest('',"process.php", "cmd=ping&ping_count="+ping_count); } ping_count++; } ////////////////////////////////////////////////////////////// //helpers ////////////////////////////////////////////////////////////// function two_digits(s) { if (s < 10) { return '0'+''+s; } else { return s; } } function is_in_range(num,min,max){ if(! (isNaN(num))){ if((num >= min) && (num <= max)) return true; else return false; } else{return false;} } function UTF_to_local(s) { var date,year,month,day,hours,minutes; var result = new Array(); year=s.substr(0,4); month=s.substr(5,2); day=s.substr(8,2); hours=s.substr(11,2); minutes=s.substr(14,2); date = new Date(); date.setUTCFullYear(year); date.setUTCMonth(month-1); date.setUTCDate(day); date.setUTCHours(hours); date.setUTCMinutes(minutes); result.year=date.getFullYear(); result.month=date.getMonth(); result.day=date.getDate(); result.hours=date.getHours(); result.minutes=date.getMinutes(); return result; } $(document).ready(function() { if (mode=='debug') add_module('debug'); add_module('paypal_start'); }); function field_validate(id, value, val_type) { AjaxPOSTRequest('', 'process.php', 'cmd=field_validate&id='+id+'&value='+value+'&val_type='+val_type); } function callback_field_validate(id, isok, err) { if(isok=='1') document.getElementById(id).style.background='#85cf85'; else { var el=document.getElementById(id); el.style.background='#e67f69'; el.original_value=el.value; if(err) { el.value=err; el.onclick=function() { this.value=this.original_value; this.style.background=''; this.onclick=''; }; } document.getElementById(id).style.background='#e67f69'; } }