﻿function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange=callbackfunc
this.ajaxobj.open('GET', url+"?"+parameters, true)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', url, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}

adTime = 50;  // seconds ad reminder is shown
chanceAd = 1; // ad will be shown 1 in X times (put 1 for everytime)

var ns = (document.layers);
var ie = (document.all);
var w3 = (document.getElementById && !ie);
var calunit = ns ? "" : "px"
adCount = 0;
function initAd() {
    if (!ns && !ie && !w3) return;
    if (ie) adDiv = eval('document.all.survey_pop.style');
    else if (ns) adDiv = eval('document.layers["survey_pop"]');
    else if (w3) adDiv = eval('document.getElementById("survey_pop").style');
    randAd = Math.ceil(Math.random() * chanceAd);
    if (ie || w3)
        adDiv.visibility = "visible";
    else
        adDiv.visibility = "show";
    if (randAd == 1) showAd();
}
function showAd() {
    if (adCount < adTime * 10) {
        adCount += 1;
        if (ie) {
            documentWidth = truebody().offsetWidth / 2 + truebody().scrollLeft - 120;
            documentHeight = truebody().offsetHeight / 2 + truebody().scrollTop - 20;
        }
        else if (ns) {
            documentWidth = window.innerWidth / 2 + window.pageXOffset - 100;
            documentHeight = window.innerHeight / 2 + window.pageYOffset - 120;
        }
        else if (w3) {
            documentWidth = self.innerWidth / 2 + window.pageXOffset - 100;
            documentHeight = self.innerHeight / 2 + window.pageYOffset - 20;
        }
        adDiv.left = documentWidth - 200 + calunit; adDiv.top = documentHeight - 200 + calunit;
        setTimeout("showAd()", 100);
    } else closeAd();
}
function closeAd() {
    if (ie || w3)
        adDiv.display = "none";
    else
        adDiv.visibility = "hide";
}

function truebody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function togglecont(mlv, mla, mlm) {
    var div1 = document.getElementById(mlv);
    var div2 = document.getElementById(mla);
    div1.style.display = 'none';
    div2.style.display = 'block';
    ajaxpack.postAjaxRequest('/func/c_stat.asp', 'process=1&click=' + mlm, temop, 'txt');
}

function temop() {
    //
}