﻿var xmlHttp;
var strUrl = '';

function prepareXmlHttpRequest() {
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
}

function makeRequestPOST(strUrl, strFunc) {
    prepareXmlHttpRequest();

    xmlHttp.onreadystatechange = strFunc;
    xmlHttp.open("POST", mainUrl, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(strUrl);
}

function makeRequestGET(strUrl, strFunc) {
    prepareXmlHttpRequest();

    strUrl += "&gettime="+new Date().getTime();
    //mainUrl += "?"+strUrl;
    xmlHttp.onreadystatechange = strFunc;    
    xmlHttp.open("GET", mainUrl+"?"+strUrl, true);
    xmlHttp.send(null);
}

function addElementToStrUrl(element) {
    var element_value = document.getElementById(element).value;
    strUrl += "&"+element+"="+element_value;
}

function showDiv(name) {
    var element = document.getElementById(name);
    element.setAttribute("style", "display: block");
    element.style["display"] = "block";
}

function closeDiv(name) {
    var div = document.getElementById(name);
    div.setAttribute("style", "display: none");
    div.style.display = "none";
}

function redirect(obj, url) {
    if (obj == null) {
        window.location = url;
    }
}

function clearElement(obj) {
    while (obj.hasChildNodes()) {
        obj.removeChild(obj.lastChild);
    }
}

function makeButton(id, value, onclick, title) {
    var e;

    if (document.all && !window.opera) {
        e = document.createElement('<input id="'+id+'" type="button"  value="'+value+'" onclick="'+onclick+'" title="'+title+'" class="submit-btn" style="font-weight:normal" >');
    }
    else { //ostatni
        e = document.createElement('input');
        e.setAttribute('id', id);
        e.setAttribute('type', 'button');
        e.setAttribute('value', value);
        e.setAttribute('onclick', onclick);
		e.setAttribute('class', 'submit-btn');
		e.setAttribute('style', 'font-weight:normal');
    }

    return e;
}

//<input id="'+id+'" type="button"  value="'+value+'" onclick="'+onclick+'" title="'+title+'" class="delete-btn" >

function makeDeleteButton(id, value, onclick, title) {
    var e;

    if (document.all && !window.opera) {
        e = document.createElement('<input id="'+id+'" type="button"  value="'+value+'" onclick="'+onclick+'" title="'+title+'" class="delete-btn" >');
    }
    else { //ostatni
        e = document.createElement('input');
        e.setAttribute('id', id);
        e.setAttribute('type', 'button');
        e.setAttribute('value', value);
        e.setAttribute('onclick', onclick);
		e.setAttribute('class', 'delete-btn');
    }

    return e;
}

function openUploaderWindow(status, ordinal) {
    if (status == null) {
        status = "image";
    }
    if (ordinal == null) {
        ordinal = 1;
    }

    openUploader(document.getElementById("cmod_id").value, document.getElementById("id").value, status, ordinal);
}

function makeLink(href, title, onclick) {
    var e;
    var ee;
    if (document.all && !window.opera) {
        e = document.createElement('<a href="'+href+'" onclick="'+onclick+'" >');
    }
    else { //ostatni
        e = document.createElement('a');
        e.setAttribute('href', href);
        e.setAttribute('onclick', onclick);
        ee = document.createElement('a');
    }
    e.appendChild(document.createTextNode(title));

    return e;
}

