function delconfirmation(name,link)
{
var dest = '';
var width = 600;
var height = 100;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
if(delconfirmation.arguments[3]) dest = delconfirmation.arguments[3];
if(delconfirmation.arguments[2]){
if( confirm("Are you sure you want to delete "+name+"?") ) send(dest+'',delconfirmation.arguments[2]+'',link+'');;
} else {
if( confirm("Are you sure you want to delete "+name+"?") ) window.location=link;
}
}
function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}
function send() {
newform= document.createElement("form");
newform.action = send.arguments[0];
newform.method = "post";
if (send.arguments.length) {
for (i = 1; i < send.arguments.length; i += 2) {
field = document.createElement("input");
field.type = "hidden";
field.name = send.arguments[i];
field.value = send.arguments[i + 1];
newform.appendChild(field);
}
document.body.appendChild(newform);
newform.submit();
}
}
//init new instance of XMLHttpRequest, prejquery
function initHTTP(){
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla
http_request = new XMLHttpRequest();
//http_request.timeout = 10000;
}
else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Your web browser is not compatible');
return false;
}
return http_request;
}
//preload loading image
pic1= new Image(16,16);
pic1.src="https://huhtis.fi/cssimages/loading.gif";
function ajaxpageload(address,handler)
{
//set 'loading' or some other text
if(ajaxpageload.arguments[2] && ajaxpageload.arguments[3] && document.getElementById(ajaxpageload.arguments[2]) )
if(ajaxpageload.arguments[3] == 'image' )
{
$('#'+ajaxpageload.arguments[2]).append("
");
document.getElementById('loadingimage').src=pic1.src;
}
else
document.getElementById(ajaxpageload.arguments[2]).innerHTML=ajaxpageload.arguments[3];
var starttime = (new Date).getTime();
var xmlhttp=initHTTP();
xmlhttp.open("GET", address+"",true);
if(handler) xmlhttp.onreadystatechange = function() { readyhandler(xmlhttp,handler,starttime); };
else xmlhttp.onreadystatechange = function() { readyhandler(xmlhttp,null,starttime); };
xmlhttp.ontimeout = function() { handler('
Timeout
'); }
xmlhttp.send();
// Usage example:
// define the handler:
// function updatetestdata(idata){
// document.getElementById('test').innerHTML = idata;
// }
// call pageload. when this is done, it will call the handler
// ajaxpageload('/weather/ajaxupdate.php',updatetestdata);
}
function readyhandler(http_requestobj,handler,starttime) {
if (http_requestobj.readyState == 4){
if (http_requestobj.status == 200) {
var diff = (new Date).getTime() - starttime;
if(handler)
{
if(document.getElementById('ajaxloadtime')) document.getElementById('ajaxloadtime').innerHTML = "Ajax delay is "+diff+" ms.";
handler(http_requestobj.responseText);
}
}
if (http_requestobj.status == 404) {
if(handler) handler("
Ajax error:404
");
setTimeout("self.location.href = '/index.php';",5000);
}
}
}
function ajaxdelete(name,address,handler)
{
if(confirm("Are you sure you want to "+name+"?")) ajaxpageload(address,handler);
}
function updateaphorism()
{
setTimeout(function updateaph(){
ajaxpageload('/ajax.php?getaphorism',function aphor(idata){
$("#aphorism").fadeOut(function() {
$(this).text(idata).fadeIn();
});
updateaphorism();
});
},30000);
}
updateaphorism();
function flashelement(element,color,time1,time2,time3)
{
if(typeof element == 'undefined') return null;
color = (typeof color !== 'undefined') ? color : 'green';
time1 = (typeof time1 !== 'undefined') ? time1 : 1000;
time2 = (typeof time2 !== 'undefined') ? time2 : 1000;
time3 = (typeof time3 !== 'undefined') ? time3 : 1000;
$(element).addClass(color,time1);
setTimeout(function(){
$(element).removeClass( color,time3);
}, time2);
}