var activex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var CantDetect = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));

function oopsPopup() {
	var windowName = "oops";
	var URLtoOpen = "http://download.skype.com/share/skypebuttons/oops/oops.html";
	var popW = 540, popH = 305;
	var scrollB = 'no';
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	oopswindow = window.open(URLtoOpen, windowName,'width=' + popW + ',height=' + popH + ',scrollbars=' + scrollB + ',screenx=' +leftPos +',screeny=' +topPos +',top=' +topPos +',left=' +leftPos);
	return false;
}

if(typeof(detected) == "undefined" && activex) {
    document.write(
        ['<script language="VBscript">',
        'Function isSkypeInstalled()',
        'on error resume next',
        'Set oSkype = CreateObject("Skype.Detection")',
        'isSkypeInstalled = IsObject(oSkype)',
        'Set oSkype = nothing',
        'End Function',
        '</script>'].join("\n")
    );
}

function skypeCheck() {
    if(CantDetect) {
        return true;
    } else if(!activex) {
        var skypeMime = navigator.mimeTypes["application/x-skype"];
        detected = true;
        if(typeof(skypeMime) == "object") {
            return true;
        } else {
            return oopsPopup();
        }
    } else {
        if(isSkypeInstalled()) {
            detected = true;
            return true;
        }
    }
    
    detected = true;
    return oopsPopup();
}

var please_wait = '<p align=center><img src="images/working.gif" hspace=5 width=16 height=16> Please wait...</p>';
/*
function ajax_Loader(url, id) {
	try {
		var r = null;
		if (window.XMLHttpRequest) {
			r = new XMLHttpRequest();
		} else {
			if (window.ActiveXObject) {
				r = new ActiveXObject("Microsoft.XMLHTTP");
			} else {
				r = new ActiveXObject("Msxml2.XMLHTTP");
			}
		}
		document.getElementById(id).innerHTML = please_wait;
		r.onreadystatechange = function() {
			if (r.readyState == 4) {
				if (r.status == 200) {
					parent.document.getElementById(id).innerHTML = r.responseText;
					r = null;
				} else {
					alert('There was a problem with the request. ' + r.status);
					r = null;
				}
			}
		};
		
		r.open('GET', url);
		r.send(null);
	} catch (e) {
		alert(e.message);
	}
}
*/
var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function open_url(url, targetId) {
	if(!xmlhttp)
		return false;
	var e=document.getElementById(targetId);
	if(!e)return false;
	if(please_wait)
		e.innerHTML = please_wait;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = function() { response(url, e); }
	try{
		xmlhttp.send(null);
	}catch(l){
		while(e.firstChild)
			e.removeChild(e.firstChild);//e.innerHTML="" the standard way
		e.appendChild(document.createTextNode("request failed"));
	}
}

function response(url, e) {
	if(xmlhttp.readyState != 4)
		return;
	var tmp = (xmlhttp.status == 200 || xmlhttp.status == 0) ? xmlhttp.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the following error code: " + xmlhttp.status+" "+xmlhttp.statusText;
	var d=document.createElement("div");
	d.innerHTML=tmp;
	setTimeout(function(){
		while(e.firstChild)
			e.removeChild(e.firstChild);//e.innerHTML="" the standard way
		e.appendChild(d);
	},10)
}