﻿/* DWSWin DWSAjax 1.0
 * Copyright © 2008 Tiga Bilişim Hizmetleri Limited Şirketi - Her hakkı saklıdır
 * Adres: http://www.tiga.com.tr
 */
//Belirtilen url'deki içeriği container elementinin içine doldurur. İşlemin başLangıç ve bitişinde raiseEvent fonksiyonuyla durum bildirir.
var ROOT_URL = 'http://localhost//';

//DOM elemente event ekler
function xaddEvent(obj, type, fn, j) {

    if (obj != null) {

        if (obj.addEventListener) {
            //Firefox & Chrome
//            alert("Firefox & Chrome");
            if (type == 'change') {
                obj.addEventListener(type, function() { fn(obj.value, j); }, false);
            }
            else if (type == 'click') {
                obj.addEventListener(type, function() { fn(j); }, false);
            }

        }
        else if (obj.attachEvent) {
            //IE Explorer
//            alert("Internet Explorer");
            obj["e" + type + fn] = fn;

            if (type == 'change') {
                obj[type + fn] = function() { obj["e" + type + fn](obj.value, j); }
            }
            else if (type == 'click') {
                obj[type + fn] = function() { obj["e" + type + fn](j); }

            }
            obj.attachEvent("on" + type, obj[type + fn]);

        }
        else alert("None");
        
    }

}

function clearOptionList(id, name) {
    var str = "";
    str += "<select name=\"" + name + "\" id=\"" + name + "\">";
    str += "<option value=\"0\"> Lütfen seçiniz... </option>";
    str += "</select>";
    document.getElementById(id).innerHTML = str;
}

function getContent(container, url, blurid, fn, id, params, rand, method) {
    
rand = (rand == null) ? true : rand;
method = isEmpty(method) ? "GET" : method;

var xmlHttp = newRequest();

xmlHttp.onreadystatechange = function() {
	if (xmlHttp.readyState == 4) {
		var cnt = document.getElementById(container);
		if (isEmpty(cnt))
			cnt = parent.document.getElementById(container);
		if (!isEmpty(cnt))
			cnt.innerHTML = xmlHttp.responseText;
		
		 raiseEvent(container, 'f', blurid, params);
		 if (fn != null && id != null) { fn(id); }
		 if (typeof (datePickerController) != 'undefined')
		   datePickerController.create();
	}
}

function isDefined(variable) {
    return (!(!(variable || false)))
}


raiseEvent(container,'s',blurid);

xmlHttp.open(method,url,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(((method == "GET") ? null : params.substring(1)));

}

function doJob(action,params,rand,method){
    params = (params == null) ? '' : params;
	getContent(null,"pages/Do.html?proccessAction="+action,params,rand,method);
}

function loadC(container,cPath,params,rand,method){
   
    params = (params == null) ? '' : params;
	getContent(container,"pages/getContent.aspx?action=loadcontent&cPath="+cPath,params,rand,method);
	
}

//Herhangi bir içerik getirilirken başLangıç ve bitiş durumunda tetiklenir.
function raiseEvent(container,state,blurid,params){

//switch(container)
//{
    //	case 'content':
    
        if (state == 's') {
            document.body.style.cursor = 'progress';
            mLS(blurid);
        }
        else {
            document.body.style.cursor = 'default';
            mLF(blurid);
        }
    	        
//	break;

//}
return;
}

function mLS(blurid) {
    
    if (blurid == null) blurid = 'main';
    
    var div = document.createElement('div');
    div.id = 'mloading';
    //setClass(div, 'loading');

    var content = document.getElementById(blurid);
    
    setClass(content, 'blur');

    document.getElementById(blurid).appendChild(div);
    
}

function mLF(blurid) {
    //alert(blurid);
    if (blurid == null) blurid = 'main';
    var content = document.getElementById(blurid);

    setClass(content, '');
    
//    content.removeChild($('mloading'));
  //  setClass($('mloading'), '');
    //hide($('mloading'));
}



//Yeni bir XMLHttpRequest oluşturur.
function newRequest(){
var xmlHttp;
try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
	catch (e){
try{xmlHttp=new XMLHttpRequest();}
	catch (e){
try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch (e){
		alert("Kullanmakta oldugunuz browser AJAX desteklemiyor!");
		return false;}}}
return xmlHttp;
}


function addPartialContent(container, divItemName, url,id,fn) {
    createDiv(container, divItemName + id);
    
    getContent(divItemName + id, url + '/' + id, container, fn, id);
    
}

function createDiv(container, newItem) {
    eDIV = document.createElement("div");
    eDIV.setAttribute("id", newItem);
//    eDIV.setAttribute("style", "background-color:#F7FFD5");
    document.getElementById(container).appendChild(eDIV);
}

