/**
 * 
 */

var menuChanged = "";

function createAjaxDivs() 
{ 
    var _body = document.getElementsByTagName('body') [0];
    var _div = document.createElement('div');
    _div.setAttribute('id','formContainer');
    _div.setAttribute('name','formContainer');
    _div.style.zIndex = '10000';
    _body.appendChild(_div);
}

function loadDiv(divId, url, token, endFunc, endFuncParamsArr,inttimeout,noHistorySet) {
    	
    if(divId != 'cover'&&divId=='pgMainDiv'){
        $.history.loadDivCheck = true;
        $.history.load("param1="+divId+"&param2="+url+"&param3="+token);
        section = url.substring(0,url.lastIndexOf('/'));
        if(section.endsWith("calendar"))
            menuChanged = "calendar";
        if(section.endsWith("group"))
            menuChanged = "group";
        if(section.endsWith("sbm"))
            menuChanged = "sbm";
        if(section.endsWith("project"))
            menuChanged = "project";
        if(section.endsWith("statusQue"))
            menuChanged = "statusQue";
        if(section.endsWith("msgBox"))
            menuChanged = "msgBox";
        if(section.endsWith("list"))
            menuChanged = "list";
        if(section.endsWith("prjReport"))
            menuChanged = "prjReport";
        if(section.endsWith("sales"))
            menuChanged = "sales";
    }
	

    if (divId == 'cover') {

        divCoverScreen('cover');
        document.getElementById('cover').style.display = 'block';
        //divAlignCenter('cover');
        document.getElementById('cover').focus();
        document.getElementById('cover').style.zIndex = '400000';//to show on top
    }
    var param = 'JIMET_TOKEN=' + token;

    var pageLoader = new JimetPageLoaderObj();
    if (endFunc)
        pageLoader.setEndFunc(endFunc);
    if (endFuncParamsArr)
        pageLoader.setEndFuncParams(endFuncParamsArr);
    if(inttimeout)
        pageLoader.setTimeout(inttimeout);

    pageLoader.doLoad(divId, url, param);
    
    activeAjaxCalls.push(pageLoader); 
}

function wrapperEscKey(e) {
    keycode = 0;
    eventObj = null;
    if (!e)
        e = window.event;
    if (e.keyCode)
        keycode = (e.keyCode);
    else
        keycode = (e.charCode);
    var targ;
    if (e.target)
        targ = e.target;
    else if (e.srcElement)
        targ = e.srcElement;

    if (keycode == 27) {
        var but = document.getElementById('cancelBtn');
        if (but)
            but.click();
        else if (document.getElementById('wrapper'))
            document.getElementById('wrapper').style.overflowY = 'auto';
        document.getElementById('cover').style.display = 'none';
        document.getElementById('cover').innerHTML = '';

        try {
            tt_HideInit();
        } catch (e) {
        }
    }
}

function divCoverScreen(divId) {
    var pgMainDiv = document.getElementById(divId);
    var height = document.body.clientHeight;
    var width = document.body.clientWidth;

    if (document.getElementById('wrapper')
        && document.getElementById('wrapper').style.display != 'none')
        pgMainDiv.style.top = document.getElementById('wrapper').scrollTop;
    else
        pgMainDiv.style.top = 0 + 'px';

    // pgMainDiv.style.top = 0;
    pgMainDiv.style.left = 0 + 'px';
    pgMainDiv.style.height = height + 'px';
    pgMainDiv.style.width = width + 'px';
}
function hideCover(){

    document.getElementById('cover').style.display = 'none';
    document.getElementById('cover').innerHTML = '';
}

function loadJumpLoaderADM(uploadAction, elementId,reportRefNo,count){
    loadDiv('cover','/common/jumpLoader/jumpLoaderADM.jsp', token+'&uploadAction='+(uploadAction==null?-1:uploadAction)+'&elementId='+(elementId==null?-1:elementId)+'&reportRefNo='+(reportRefNo==null?-1:reportRefNo)+'&count='+(count==null?0:count)+'&type=ADM');
}

function loadJumpLoaderSBM(uploadAction, elementId,reportRefNo,count){
    loadDiv('cover','/common/jumpLoader/jumpLoaderSBM.jsp', token+'&uploadAction='+(uploadAction==null?-1:uploadAction)+'&elementId='+(elementId==null?-1:elementId)+'&reportRefNo='+(reportRefNo==null?-1:reportRefNo)+'&count='+(count==null?0:count)+'&type=SBM');
}

function filterOutletVisitsByDate(parameters){
    var start = document.getElementById('startDate').value;
    var end = document.getElementById('endDate').value;
    if(start != null ? start != '' : false){
        if(end != null ? end != '' : false){
            loadTable('pgMainDiv','/common/tables/admin/sales/outletVisitReportsTable.jsp',parameters+'&startDate='+start+'&endDate='+end);
        }
    }
}
