//-----------------------------------------------------
// Copyright (C) 2005-2009 Craig Spurrier
// http://www.asvcs.com
// Released under the terms of the GPL v2.
// See copying.txt for full license text.
//-----------------------------------------------------
// File: scripts.js
// Notes: This file contains much of the javascript used by ASVCS
//-----------------------------------------------------

function show_hide(area_id,action,focus_on_id,select_id){
if (action == 'swap'){
if (document.getElementById(area_id).style.display == 'inline'){
document.getElementById(area_id).style.display = 'none';
}else{
document.getElementById(area_id).style.display = 'inline';
}

}else if (action == 'show'){
document.getElementById(area_id).style.display = 'inline';
}else{
document.getElementById(area_id).style.display = 'none';
}

if(document.getElementById(focus_on_id)){
document.getElementById(focus_on_id).focus();
}
if(document.getElementById(select_id)){
document.getElementById(select_id).select();
}
}
function swap_values(replaced_id,replaced_with_id){
if(document.getElementById(replaced_with_id).value){
var replaced_with = document.getElementById(replaced_with_id).value;
}else if(document.getElementById(replaced_with_id).innerHTML){
var replaced_with = document.getElementById(replaced_with_id).innerHTML;
}else{
var replaced_with = "";
}
document.getElementById(replaced_id).value = replaced_with;
}

function change_location(url){
window.location = url;
}


function replace_array(replace,by,str) { 
  for (var i=0; i<replace.length; i++) { 
     str = str.replace(replace[i], by[i]); 
  } 
  return str; 
}

//miniajax by marcosbl
//used under the GNU General Public License v2
function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};
ajax={};
ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
ajax.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
ajax.send=function(u,f,m,a){var x=ajax.x();x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x.responseText)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)};
ajax.get=function(url,func){ajax.send(url,func,'GET')};
ajax.gets=function(url){var x=ajax.x();x.open('GET',url,false);x.send(null);return x.responseText};
ajax.post=function(url,func,args){ajax.send(url,func,'POST',args)};
ajax.update=function(url,elm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.get(url,f)};
ajax.submit=function(form_id,url,response_function){
ajax.post(url,response_function,ajax.serialize($(form_id)))
};
//end miniajax

