﻿function addListenerToEvent(element, evnt, listener, bubbl)
{
    if (element.addEventListener)
        element.addEventListener(evnt, listener, bubbl)
    else if (this.attachEvent)
        element.attachEvent('on' + evnt, listener);
}

function removeListenerFromEvent(element, evnt, listener, bubbl)
{
    if (element.removeEventListener)
        element.removeEventListener(evnt, listener, bubbl);
    else
        element.detachEvent('on' + evnt, listener);
}

function openWin(url, w, h, name, noError, rszbl)
{
    var checkPop;
    if(rszbl != undefined && rszbl != '')
        checkPop = window.open ( url, name, 'resizable=' + rszbl + ',scrollbars=yes,menubar=0,toolbar=0,status=0,location=0,width='+w+',height='+h+',left=' + 50 + ',top=' + 50);
    else
        checkPop = window.open ( url, name, 'resizable=0,scrollbars=yes,menubar=0,toolbar=0,status=0,location=0,width='+w+',height='+h+',left=' + 50 + ',top=' + 50);
    if (noError != undefined && !noError && !checkPop)
	    window.location = '/Error/PopUpBlocked.htm';
}


function ChangeRowBGColorOnMouseOutLast(value)
{
    value.style.backgroundColor = '#609BB7';
    
    var images= value.getElementsByTagName('img');
    images[0].src = '/Images/CV/cv_menu_bottom_left.gif';
    images[1].src = '/Images/CV/cv_menu_bottom_right.gif';
}

function ChangeRowBGColorOnMouseOverLast(value)
{  
    value.style.backgroundColor = '#8EB7CA';
    
    var images= value.getElementsByTagName('img');

    images[0].src = '/Images/CV/cv_menu_bottom_left_selected.gif';
    images[1].src = '/Images/CV/cv_menu_bottom_right_selected.gif';
}

var _divCBError;
var _msgCBError;

function createMsgDivCBError()
{
    _divCBError = document.createElement('div'); _divCBError.id = '_msgContainerCBError_';
    _divCBError.className = 'msgDivCBError'; _divCBError.style.visibility = 'hidden';
    _divCBError.innerHTML = '<span id=\'_msgCBError_\' class=\'msgSpanCBError\'></span>';
    _msgCBError = _divCBError.getElementsByTagName('span')[0]; document.forms[0].appendChild(_divCBError);
    removeListenerFromEvent(window, 'load', createMsgDivCBError, false)
}

function showMsgDivCBError(evnt, sender)
{
    var y;
    var x;
    var msg = '';
    var txt;
    if (evnt != undefined && evnt != null)
    {
        if (evnt.target)
            txt = evnt.target;
        else
            txt = evnt.srcElement;
    }
    else
        txt = sender;
        
    if(txt.attributes['title'])
        msg = txt.attributes['title'].value;

    if (msg != '')
    {
        y = txt.offsetTop;
        x = txt.offsetLeft;
        var parentO = txt.offsetParent;
        while (parentO != null)
        {
            y += parentO.offsetTop;
            x += parentO.offsetLeft;
            parentO = parentO.offsetParent;
        }
        _msgCBError.innerHTML = msg;
        _divCBError.style.opacity = 0;
        _divCBError.style.visibility = 'visible';
        
        if(y <= (_divCBError.clientHeight + 4))
            y += (txt.clientHeight + 4)
        else
            y -= (_divCBError.clientHeight + 3);
        _divCBError.style.visibility = 'hidden';
        _divCBError.style.opacity = 1;
        
        _divCBError.style.posLeft = x;
        _divCBError.style.posTop = y;
        _divCBError.style.left = x + 'px';
        _divCBError.style.top = y + 'px';
        _divCBError.style.visibility = 'visible';
    }
}

function hideMsgDivCBError()
{
    if(_divCBError)
        _divCBError.style.visibility = 'hidden';
}

function getCheckResult(ckResult)
{
    var txt = document.getElementById(txtId);
    txtId = null;
    if (ckResult == '1')
    {
        txt.style.color = 'red';
        txt.setAttribute('title', ttl);
        addListenerToEvent(txt, 'mouseover', showMsgDivCBError, false);
        addListenerToEvent(txt, 'mouseout', hideMsgDivCBError, false);
        showMsgDivCBError(null, txt);
    }
    else
    {
        txt.style.color = 'black';
        txt.setAttribute('title', '');
        removeListenerFromEvent(txt, 'mouseover', showMsgDivCBError, false)
        removeListenerFromEvent(txt, 'mouseout', hideMsgDivCBError, false)
        hideMsgDivCBError();
    }
}

var txtId;
var ttl;
function onTxtLost(sender, swc, ttlT)
{
    txtId = sender.id;
    ttl = ttlT;
    checkExists(sender.value + swc,'');
}

function setWin(w, h)
{
    if(window.opener==null)
        self.resizeTo(w,h);
}

function closePupWin(post)
{
    if(post == 1)
    {
        if(window.opener != null)
        {
            var hid = window.opener.document.getElementsByName('ctl01$c1$posVar');
            if (hid != undefined && hid != null && hid.length > 0)
            {
                hid[0].value = 'pos__$';
                window.opener.document.forms[0].submit();
            }
        }
    }
    self.close();
}

function openModalWin(url, w, h, max)
{
    if(max)
    {
        h = screen.height;
        w = screen.width;
    }
    var returnValue = window.showModalDialog(url,'#1','dialogHeight: '+h+'px; dialogWidth: '+w+'px;dialogTop: 0px; dialogLeft: 0px; edge: Raised; center: Yes;help: No; resizable: No; status: No;');
    if(returnValue == 'doPost')
        document.forms[0].submit();
}

function sendToTest(url)
{
    if(window.opener == null)
        window.location = url;
    else
    {
        window.opener.location = url;
        self.close();
    }
}

function changeBG(cnt, url)
{
    cnt.src = url;
}

function testHegiht(cnt)
{
    var c = document.getElementById(cnt);
    self.resizeTo(c.scrollWidth, c.scrollHeight + 38);
    alert(c.scrollHeight);
}

function redirectToLocation(url)
{
    if (self.opener && self.opener != undefined && self.opener != null)
        {
            self.opener.location = url;
            self.close();
        }
    else
        document.location = url;
}

function checkList(cnt, maxS)
{
    var selCount = 0;
    var opts = cnt.getElementsByTagName('OPTION')
    
    if (opts && opts.length > 0)
    {
        for(var i = 0; i < opts.length ; i++)
        {
            var opt = opts[i];
            if (opt.value == '-1')
                opt.selected = false;
            else
            {
                if (selCount >= maxS)
                    opt.selected = false;
                else if (opt.selected)
                    selCount++;
            }
        }
    }

    return true;
}

if (!String.prototype.startsWith)
{
    String.prototype.startsWith = function(value)
    {
        if (!value)
            return false;
        else
            return (this.indexOf(value) === 0);
    }
}

if (!String.prototype.endsWith)
{
    String.prototype.endsWith = function(value)
    {
        if (!value)
            return false;
        else
        {
            var startPos = this.length - value.length;
            if (startPos < 0)
              return false;
            return (this.lastIndexOf(value, startPos) == startPos);
        }
    }
}

if (!String.prototype.contains)
{
    String.prototype.contains = function(value)
    {
        if (!value)
            return false;
        else
        {
            if (!value)
                return false;
            else
                return (this.indexOf(value) > -1);
        }
    }
}

function checkSelections(sender, grd, name)
{
    sender.hideFocus = true;
    var grid = document.getElementById(grd);
    if (grid)
    {
        var inpts = grid.getElementsByTagName('INPUT')
        if (inpts)
        {
            var checked = sender.checked;
            var obj;
	        for (var i = 0; i < inpts.length; i++)
	        {
	            obj = inpts[i];
		        if (obj.type == 'checkbox' && obj.id.endsWith(name) && !obj.disabled)
			        obj.checked = checked;
	        }
        }
    }
}

function checkOtherSelections(sender, grd, name)
{
    sender.hideFocus = true;
    var grid = document.getElementById(grd);
    if (grd)
    {
        var inpts = grid.getElementsByTagName('INPUT');
        if (inpts)
        {
            var topChk;
            var allChecked = true;
            var obj;
            for (var i = 0; i < inpts.length; i++)
            {
                obj = inpts[i];
                if (obj.type == 'checkbox' && obj.id.endsWith(name))
                    topChk = obj;
                else if (obj.type == 'checkbox' && !obj.checked && allChecked)
                {
                    allChecked = false;
                    break;
                }
            }
            
            if (!topChk.disabled)
                topChk.checked = allChecked;
        }
    }
}

function noSelection(grd, name, msg, tx, ck, cMsg)
{
    var grid = document.getElementById(grd);
    var ok = false;
    var rMsg;
    if(grid)
    {
        var inpts = grid.getElementsByTagName('INPUT')
        if (inpts)
        {
            var obj;
            for (var i = 0; i < inpts.length; i++)
            {
                obj = inpts[i];
                if (obj.type == 'checkbox' && obj.id.endsWith(name) && obj.checked)
                { ok = true; break; }
            }
        }
    }
    
    if(ck)
    {
        if (ok)
        {
            var txt = document.getElementById(tx);
            var chk = document.getElementById(ck);
            if (txt && chk && chk.checked && txt.value == '')
            { ok = confirm(cMsg); if (!ok) txt.focus(); }
        }
        else
            alert(msg);
    }
    else if (!ok)
        alert(msg);
    return !ok;
}

function noQName(tx, ck, cMsg)
{
    var txt = document.getElementById(tx);
    var chk = document.getElementById(ck);
    
    if(chk && txt && chk.checked && txt.value == '')
    {
        var ok = confirm(cMsg);
        if (!ok)
            txt.focus();
        return !ok;
    }
    else
        return false;
}

function unselectO(sender, grd)
{
    if (sender.checked)
    {
        var grid = document.getElementById(grd);
        if (grid)
        {
            var inpts = grid.getElementsByTagName('INPUT');
            if (inpts)
                for (var i = 0; i < inpts.length; i++)
                    if (inpts[i].type == 'checkbox' && inpts[i].id != sender.id)
                        inpts[i].checked = false;
        }
    }
}

function changePage(sender, actionUrl)
{
    var opts = sender.getElementsByTagName('OPTION');
    if (opts)
    {
        var ind = -1;
        for (var i = 0; i < opts.length; i++)
        {
            if (opts[i].selected)
            {
                ind = i;
                break;
            }
        }
        
        if (ind != -1)
            document.location = actionUrl + opts[i].value;
    }
}

function notSelected(ckls, msg)
{
    var ckLst = document.getElementById(ckls);
    var ok = false;
    var rMsg;
    if(ckLst)
    {
        var inpts = ckLst.getElementsByTagName('INPUT')
        if (inpts && inpts.length > 0)
        {
            var obj;
            for (var i = 0; i < inpts.length; i++)
            {
                obj = inpts[i];
                if (obj.type == 'checkbox' && obj.checked)
                { ok = true; break; }
            }
        }
    }
    
    if (!ok)
        alert(msg);
    return !ok;
}

function setFupStatus(sender, id)
{
    var fUploadImage = document.getElementById(id);
    if (fUploadImage)
        fUploadImage.disabled = sender.checked;
}

function hideModal(bhvrID)
{
    var mpe = $find(bhvrID);
    if (mpe)
        mpe.hide();
}

function resetState()
{
    var args = resetState.arguments;
    if (args.length > 0)
    {
        if (args.length > 1)
        {
            var txt;
            for(var i = 2; i < args.length; i++)
            {
                txt = document.getElementById(args[i]);
                if (txt)
                    txt.value = '';
            }
        }
        
        var divO = document.getElementById(args[0]);
        if (divO)
            divO.style.display = '';
        divO = document.getElementById(args[1]);
        if (divO)
            divO.style.display = 'none';
    }
}

function checkOther(cntOp, cTxt, cTxtO)
{
    var cntTxt = document.getElementById(cTxt);
    var cntTxtO;
    if (cTxtO != undefined && cTxtO != '')
        cntTxtO = document.getElementById(cTxtO);
    var opts = cntOp.getElementsByTagName('option');
    
    if (cntTxtO != undefined)
        cntTxtO.disabled = true;
        
    if  (opts != undefined && opts.length > 0 && cntTxt)
    {
        var opt;
        for (var i = 0; i < opts.length; i++)
        {
            opt = opts[i];
            if (opt.selected)
            {
                var parts = opt.value.split(';');
                if (parts != undefined && parts.length > 1 && parts[1] == '1')
                {
                    cntTxt.disabled = false;
                    return true;
                }
            }
        }
        
        cntTxt.disabled = true;
        return false;
    }
}

function goPreview(lst, url, winName, w, h)
{
    var cmb = document.getElementById(lst);
    if (cmb)
    {
        var opts = cmb.getElementsByTagName('OPTION');
        var opt;
        if (opts && opts.length > 0)
        {
            for(var i = 0; i < opts.length; i++)
            {
                opt = opts[i];
                if (opt.selected)
                {
                    if (opt.value != '-1')
                    {
                        url = url.replace('{0}', opt.value);
                        openWin(url, w, h, winName);
                    }
                    
                    return false;
                }
            }
        }
    }
}

 var maxTextLength = 500;
 var messageText = 'Bu alan icin ayrilmis karakter limitine (500) ulastiniz. Daha fazla giris yapamazsiniz.';

 function isAlphaNumericKey(keyCode)
 {
      if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91))
          return true;
      
      return false;
 }
 function limitCharacters(editor)
 {
     editor.AttachEventHandler ('onkeydown', function (e)
     {
         e = (e == null)? window.event : e;
         if (isAlphaNumericKey(e.keyCode))
         {
             textLength = editor.GetText().length;
             if (textLength >= maxTextLength)
             {
                  alert(messageText);
                  e.returnValue = false;
                  return false;
             }
         }
      });
     editor.AttachEventHandler ('onpaste', function (e)
     {
         var textLength = calculateLength (editor);
         if (textLength >= maxTextLength)
         {
             alert(messageText);
             e.returnValue = false;
             e.cancelBubble = true;
             return false;
         }
     });
}
function calculateLength(editor)
{
     var textLength = editor.GetText().length; 
     var clipboardLength = window.clipboardData.getData('Text').length;
     textLength += clipboardLength;
     return textLength;
}
function onClientCommandExecuting(editor, commandName, oTool)
{
    if (commandName == 'PasteFromWord'
        || commandName == 'PasteFromWordNoFontsNoSizes'
        || commandName == 'PastePlainText'
        || commandName == 'PasteAsHtml'
        || commandName == 'Paste' )
    { 
        if (document.all)
        {
            var textLength = calculateLength (editor);
            if (textLength >= maxTextLength)
            {
              alert(messageText);
              return false;
            }
        }
    }
 }

function DateControlContainer()
{
    this.Controls = new Array();
}
DateControlContainer.prototype._containsControl = function(id)
{
    if (this.Controls.length > 0)
        for (var i = 0; i < this.Controls.length; i++)
            if (this.Controls[i].ControlID == id)
                return true;

    return false;
}
DateControlContainer.prototype.AddDateControl = function(c, d, m, y, dms, rqf, cmp)
{
    if (!this._containsControl(c))
    {
        var o = new Object();
        o.ControlID = c;
        o.DayID = d;
        o.MonthID = m;
        o.YearID = y;
        o.DateMustSelected = dms;
        o.CustRQFID = rqf;
        o.CustCMPID = cmp;
        this.Controls[this.Controls.length] = o;
    }
}
DateControlContainer.prototype._getForRequiredVal = function(id)
{
    if (this.Controls.length > 0)
        for (var i = 0; i < this.Controls.length; i++)
            if (this.Controls[i].CustRQFID == id)
                return this.Controls[i];

    return null;
}
DateControlContainer.prototype._getForCompareVal = function(id)
{
    if (this.Controls.length > 0)
        for (var i = 0; i < this.Controls.length; i++)
            if (this.Controls[i].CustCMPID == id)
                return this.Controls[i];

    return null;
}
DateControlContainer.prototype._getFullYear = function(year)
{
    var twoDigitCutoffYear = 2069 % 100;
    var cutoffYearCentury = 2069 - twoDigitCutoffYear;
    return ((year > twoDigitCutoffYear) ? (cutoffYearCentury - 100 + year) : (cutoffYearCentury + year));
}
DateControlContainer.prototype._allSelected = function(ddlD, ddlM, ddlY, selectedOrNot)
{
    if (selectedOrNot)
        return (ddlD.value != "-1" && ddlM.value != "-1" && ddlY.value != "-1");
    else
        return (ddlD.value == "-1" && ddlM.value == "-1" && ddlY.value == "-1");
}
DateControlContainer.prototype._validateDate = function(ddlD, ddlM, ddlY)
{
    if (ddlD.value != '-1!' && ddlM.value != '-1!' && ddlY.value != '-1!')
    {
        var d = ddlD.value + '.' + ddlM.value + '.' + ddlY.value;
        var day, month, year;            
        var yearRegxB = new RegExp("^\\s*(\\d{1,2})([-/]|\\. ?)(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$");
        var m = d.match(yearRegxB);
        if (m != null)
        {
            day = m[1];
            month = m[3];
            year = (m[5].length == 4) ? m[5] : this._getFullYear(parseInt(m[6], 10))
            
            month -= 1;
            var date = new Date(year, month, day);
            if (year < 100) { date.setFullYear(year); }
            
            return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate());
        }
    }
    
    return false;
}
DateControlContainer.prototype.CheckRequiring = function(source, args)
{
    var o = this._getForRequiredVal(source.id);
    if (o != null)
    {
        var ddlD = document.getElementById(o.DayID);
        var ddlM = document.getElementById(o.MonthID);
        var ddlY = document.getElementById(o.YearID);
        
        if (ddlD && ddlM && ddlY)
        {
            if (o.DateMustSelected)
                args.IsValid = this._allSelected(ddlD, ddlM, ddlY, true);
            else
                args.IsValid = true;
        }
        else
            args.IsValid = false;
    }
    else
        args.IsValid = true;
}
DateControlContainer.prototype.CheckDate = function(source, args)
{
    var o = this._getForCompareVal(source.id);
    if (o != null)
    {
        var ddlD = document.getElementById(o.DayID);
        var ddlM = document.getElementById(o.MonthID);
        var ddlY = document.getElementById(o.YearID);
        
        if (ddlD && ddlM && ddlY)
        {
            if (o.DateMustSelected)
            {
                if (!this._allSelected(ddlD, ddlM, ddlY, true))
                {
                    args.IsValid = true;
                    return;
                }
            }
            else
            {
                if (this._allSelected(ddlD, ddlM, ddlY, false))
                {
                    args.IsValid = true;
                    return;
                }
            }
            
            args.IsValid = this._validateDate(ddlD, ddlM, ddlY);
        }
        else
            args.IsValid = false;
    }
    else
        args.IsValid = true;
}
var dateControlContainer = new DateControlContainer();

function showHideContent(cnt, im, clps, exp)
{
    var dv = document.getElementById(cnt);
    var img = document.getElementById(im);
    
    if (dv && dv.tagName == 'DIV')
    {
        dv.style.display = dv.style.display == '' ? 'none' : '';
        
        if (img)
            img.src = dv.style.display == '' ? clps : exp;
    }
}

function showRequested(url)
{
    document.location = url;
}

function PopManager()
{
    this.hdnFId = '';
    this.hdn = null;
}
PopManager.prototype.post = function(ex)
{
    if (ex)
        document.forms[0].submit();
}
PopManager.prototype.prepare = function()
{
    if (this.hdnFId != '')
    {
        var hdn = document.getElementById(this.hdnFId);
        if (hdn)
            this.hdn = hdn;
    }
}
PopManager.prototype.setValue = function(value)
{
    if (this.hdn != null)
        this.hdn.value = value;
}
PopManager.prototype.refreshOwner = function()
{
    document.forms[0].submit();
}
var popManager = new PopManager();

function removeFocus(sender)
{
    var menu = sender;
    for (var i=0; i<menu.AllItems.length; i++)
        if (menu.AllItems[i].LinkElement)
            menu.AllItems[i].LinkElement.hideFocus = true;
}

function PostManager()
{
    this.awailableCount = 0;
    this.requiredCount = 0;
    this.abortMsg = '';
    this.confirmMsg = '';
    this.eliminatedMsg = '';
    this.messageSpanId = '';
    this.ptfMsg = '';
    this.noPTFAlertMsg = '';
    this.ptfMsgSpanId = '';
    this.ptfHdnId = '';
    this.ptfId = -1;
    this.ptfName = '';
    this.showConfirmation = false;
    this.tokenValues = new Array();
    this.messageSpan = null;
    this.relatedSelectId = '';
    this.relatedSelect = null;
    this.relatedSelectMsg = '';
    this.checkAgainstForRelated = '-1';
    this.controlIds = new Array();
    this.hChecks = new Array();
    this.chkAll = null;
    this.chkAllId = '';
    this.confirmForMixCont = false;
    this.MixContMsg = '';
}
PostManager.prototype.selectedCount = function()
{
    var sCount = 0;
    if (this.tokenValues.length > 0)
        for (var i = 0; i < this.tokenValues.length; i++)
            if (this.tokenValues[i].control.checked)
                sCount++;
    
    return sCount;
}
PostManager.prototype.add_hChecks = function()
{
    var args = this.add_hChecks.arguments;
    if (args.length > 0)
        for (var i = 0; i < args.length; i++)
            this.hChecks[this.hChecks.length] = args[i];
}
PostManager.prototype.containsCheck = function(check)
{
    if (this.hChecks.length > 0)
        for (var i = 0; i < this.hChecks.length; i++)
            if (this.hChecks[i] == check)
                return true;
    
    return false;
}
PostManager.prototype.getPanel = function()
{
    if (this.messageSpanId != null && this.messageSpan == null)
    {
        var spn = document.getElementById(this.messageSpanId);
        if (spn)
            this.messageSpan = spn;
    }
}
PostManager.prototype.containsID = function (ckId)
{
    if (this.tokenValues.length > 0)
        for (var i = 0; i < this.tokenValues.length; i++)
            if (this.tokenValues[i].control.id == ckId)
                return true;
    
    return false;
}
PostManager.prototype.getValue = function (ckId)
{
    if (this.tokenValues.length > 0)
        for (var i = 0; i < this.tokenValues.length; i++)
            if (this.tokenValues[i].control.id == ckId)
                return this.tokenValues[i];
    
    return null;
}
PostManager.prototype.containsControlId = function(cId)
{
    if (this.controlIds.length > 0)
        for (var i = 0; i < this.controlIds.length; i++)
            if (this.controlIds[i] == cId)
                return true;
            
    return false;
}
PostManager.prototype.indexOfControlId = function(cId)
{
    if (this.controlIds.length > 0)
        for (var i = 0; i < this.controlIds.length; i++)
            if (this.controlIds[i] == cId)
                return i;
            
    return -1;
}
PostManager.prototype.isRemoveRequired = function(cId)
{
    if (this.tokenValues.length > 0)
        for (var i = 0; i < this.tokenValues.length; i++)
            if (this.tokenValues[i].controlId == cId && this.tokenValues[i].control.checked)
                return false;
    
    return true;
}
PostManager.prototype.calculate = function (sender)
{
    this.getPanel();
    this.requiredCount = 0;
    this.controlIds.length = 0;
    for (var i = 0; i < this.tokenValues.length; i++)
        this._calculate(this.tokenValues[i]);
}
PostManager.prototype.calculateAll = function (sender)
{
    this.getPanel();
    if (sender.checked)
    {
        if (this.tokenValues.length > 0)
        {
            this.requiredCount = 0;
            this.controlIds.length = 0;
            for (var i = 0; i < this.tokenValues.length; i++)
                this.calculate(this.tokenValues[i].control);
        }
    }
    else
    {
        this.requiredCount = 0;
        this.controlIds.length = 0;
        if(this.messageSpan != null)
            this.messageSpan.innerHTML = '0';
    }
}
PostManager.prototype._calculate = function (tokenValue)
{
    this.getPanel();
    if(tokenValue)
    {
        if (tokenValue.control.checked && !this.containsControlId(tokenValue.controlId))
        {
            this.requiredCount += tokenValue.count;
            this.controlIds[this.controlIds.length] = tokenValue.controlId;
        }
        
        if (this.messageSpan != null)
            this.messageSpan.innerHTML = this.requiredCount;
    }
}
PostManager.prototype.prepareValues = function()
{
    this.requiredCount = 0;
    this.controlIds.length = 0;
    this.chkAll = document.getElementById(this.chkAllId);
    for (var i = 0; i < this.tokenValues.length; i++)
        this._calculate(this.tokenValues[i]);
    if (this.relatedSelectId != '')
        this.relatedSelect = document.getElementById(this.relatedSelectId);
}
PostManager.prototype.isContMixd = function()
{
    var result = false;
    if (this.tokenValues.length != 0)
    {
        var addId = -999;
        for (var i = 0; i < this.tokenValues.length; i++)
        {
            if (addId == -999)
            {
                if (this.tokenValues[i].control.checked)
                    addId = this.tokenValues[i].addId;
            }
            else if (this.tokenValues[i].control.checked && this.tokenValues[i].addId != addId)
            {
                result = true;
                break;
            }
        }
    }
    
    return result;
}
PostManager.prototype.addTokenValue = function ()
{
    var args = this.addTokenValue.arguments;
    if (args && args.length > 0)
    {
        var chk = document.getElementById(args[0]);
        if (chk)
        {
            var tokenValue = new Object();
            tokenValue. control = chk;
            tokenValue. count = args[1];
            tokenValue. controlId = args[2];
            tokenValue. lCheck = args[3];
            tokenValue. cCheck = args[4];
            tokenValue. mCheck = args[5];
            tokenValue. tCheck = args[6];
            if (args.length >= 8)
                tokenValue. addId = args[7];
            else
                tokenValue. addId = null;
            this.tokenValues[this.tokenValues.length] = tokenValue;
        }
    }
}
PostManager.prototype.addSingleTokenValue = function ()
{
    var args = this.addSingleTokenValue.arguments;
    
    if (args && args.length > 0)
    {
            var tokenValue = new Object();
            tokenValue. count = args[0];
            tokenValue. lCheck = args[1];
            tokenValue. cCheck = args[2];
            tokenValue. mCheck = args[3];
            tokenValue. tCheck = args[4];
            this.tokenValues[this.tokenValues.length] = tokenValue;
            this.requiredCount = tokenValue.count;
    }
}
PostManager.prototype._removeSelection = function(tokenValue)
{
    if (tokenValue)
    {
        tokenValue.control.checked = false;
        if (this.isRemoveRequired(tokenValue.controlId) && this.containsControlId(tokenValue.controlId))
        {
            var index = this.indexOfControlId(tokenValue.controlId);
            this.requiredCount -= tokenValue.count;
            if (index != -1)
                this.controlIds.splice(index, 1);
            if (this.requiredCount < 0)
                this.requiredCount = 0;
            if (this.messageSpan != null)
                this.messageSpan.innerHTML = this.requiredCount;
        }
    }
}
PostManager.prototype.checkPost = function(tp, dntCk)
{
    if (dntCk != undefined && dntCk)
        return true;
        
    if (this.confirmForMixCont && this.isContMixd() && !confirm(this.MixContMsg))
        return false;

    var tokenValue;
    var alertForRemove = false;
    for (var i = 0; i < this.tokenValues.length; i++)
    {
        var removeCheck = false;
        tokenValue = this.tokenValues[i];
        if (tokenValue.control.checked)
        {
            switch(tp)
            {
                case 'tCheck':
                    if (!this.containsCheck(tokenValue.tCheck))
                        removeCheck = true;
                    break;
                case 'lCheck':
                    if (!this.containsCheck(tokenValue.lCheck))
                        removeCheck = true;
                    break;
                case 'cCheck':
                    if (!this.containsCheck(tokenValue.cCheck))
                        removeCheck = true;
                    break;
                case 'mCheck':
                    if (!this.containsCheck(tokenValue.mCheck))
                        removeCheck = true;
                    break;
                default:
                    break;
            }
            
            if (removeCheck)
            {
                this._removeSelection(tokenValue);
                alertForRemove = true;
            }
        }
    }
    
    if (alertForRemove)
    {
        alert(this.eliminatedMsg);
        if (this.selectedCount() == 0)
        {
            this.chkAll.checked = false;
            return false;
        }
    }
    
    if (tp != 'tCheck' && this.showConfirmation)
    {
        if (this.requiredCount != 0)
        {
            if (this.requiredCount <= this.awailableCount)
            {
                if (confirm(this.confirmMsg.replace('{0}', this.requiredCount.toString())))
                    return true;
                else
                    return false;
            }
            else
            {
                alert(this.abortMsg);
                return false;
            }
        }
        else
            return true;
    }
    else
        return true;
}
PostManager.prototype.checkSinglePost = function(tp, dntCk)
{
    if (dntCk != undefined && dntCk)
        return true;
        
    if (tp != 'tCheck' && this.showConfirmation)
    {
        if (this.requiredCount != 0)
        {
            if (this.requiredCount <= this.awailableCount)
            {
                if (confirm(this.confirmMsg.replace('{0}', this.requiredCount.toString())))
                    return true;
                else
                    return false;
            }
            else
            {
                alert(this.abortMsg);
                return false;
            }
        }
        else
            return true;
    }
    else
        return true;
}
PostManager.prototype.checkPostForTest = function(tp)
{
    if (this.relatedSelect != null)
    {
        var canPost = this.checkPost(tp);
        if (canPost)
        {
            if (this.relatedSelect.selectedIndex == -1)
            {
                alert(this.relatedSelectMsg);
                canPost = false;
            }
            else
            {
                for (var i = 0; i < this.relatedSelect.length; i++)
                {
                    if (this.relatedSelect[i].selected && this.relatedSelect[i].value == this.checkAgainstForRelated)
                    {
                        alert(this.relatedSelectMsg);
                        canPost = false;
                    }
                }
            }
        }
        
        return canPost;
    }
    else
        return true;
}
PostManager.prototype.setPTF = function (id, name)
{
    var spn = document.getElementById(this.ptfMsgSpanId);
    if (spn)
    {
        this.ptfId = id;
        this.ptfName = name;
        spn.innerHTML = this.ptfMsg.replace('{0}', name);
    }
}
PostManager.prototype.checkPostForPTF = function ()
{
    if (this.ptfId == -1)
    {
        alert(this.noPTFAlertMsg);
        return false;
    }
    else
    {
        var hdn = document.getElementById(this.ptfHdnId);
        if (hdn)
        {
            hdn.value = this.ptfId;
            return true;
        }
        else
        {
            alert('Post yapilamaz !!!');
            return false;
        }
    }
}
PostManager.prototype.preparePTF = function ()
{
    var spn = document.getElementById(this.ptfMsgSpanId);
    var hdn = document.getElementById(this.ptfHdnId);
    if (spn && hdn)
    {
        if (this.ptfId == -1 || this.ptfName == '')
        {
            spn.innerHTML = '';
            hdn.value = '';
        }
        else
        {
            spn.innerKTML = this.ptfMsg.replace('{0}', this.ptfName);
            hdn.value = this.ptfId;
        }
    }
}

var postManager = new PostManager();

var upPrgName='';
function positionUpPrgs()
{
    var cnt = document.getElementById(upPrgName);
    if (cnt && document.documentElement)
    {
        var cntS = cnt.style;
        cntS.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth / 2)) - (cnt.clientWidth / 2) + 'px';
        cntS.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight / 2)) - (cnt.clientHeight / 2) + 'px';
    }
}
function prepareUpPrgs(css)
{
    var cnt = document.getElementById(upPrgName);
    if (cnt)
        cnt.className = css;
}

var pnlVisible = false;
var sizingComplated = false;
var sizing = false;
var firstHeight = -1;
var firstWidth = -1;
var intervalContainer = 0;
var sizingDirection = '';
var sizingSpeed = 50;
var sizingInterval = 35;
var ltr = false;
var utd = true;

function showContent(p)
{
    if ((!ltr && !utd) || (sizing && sizingDirection == 'up'))
        return;
    else if (sizing && sizingDirection == 'down')
        stopSizing();
    
    var div = document.getElementById(p);
    if (div)
    {
        if (firstHeight == -1)
        {
            div.style.display = '';
            firstHeight = div.clientHeight;
            firstWidth = div.clientWidth;
            div.style.display = 'none';
        }
    }
    else
        return;
        
    sizing = true;
    sizingDirection = 'up';
    if (!pnlVisible)
        counter = 0;
    intervalContainer = setInterval("sizePanel('" + p + "')", sizingInterval);
}

function hideContent(p)
{
    if ((!ltr && !utd) || (sizing && sizingDirection == 'down'))
        return;
    else if (sizing && sizingDirection == 'up')
        stopSizing();

    var div = document.getElementById(p);
    if (div)
    {
        if (firstHeight == -1)
        {
            div.style.display = '';
            firstHeight = div.clientHeight;
            firstWidth = div.clientWidth;
            div.style.display = 'none';
        }
    }
    else
        return; 
    
    sizing = true;
    sizingDirection = 'down';
    intervalContainer = setInterval("sizePanel('" + p + "')", sizingInterval);
}

var counter = 0;
function sizePanel(p)
{
    var div = document.getElementById(p);
    if (div)
    {
        var h;
        var w;
        
        if (sizingDirection == 'up')
        {
            if (!sizingComplated)
            {
                if (counter == 0)
                {
                    div.style.display = '';
                    if (utd)
                        div.style.height = '0px';
                    else
                        div.style.height = firstHeight + 'px';
                        
                    if (ltr)
                        div.style.width = '0px';
                    else
                        div.style.width = firstWidth + 'px';
                    pnlVisible = true;
                }
                counter ++;
                
                h = parseInt(div.style.height);
                w = parseInt(div.style.width);
                
                if (utd)
                {
                    if (h < firstHeight)
                    {
                        h += sizingSpeed;
                        if (h > firstHeight)
                            h = firstHeight;
                        
                        div.style.height = h + 'px';
                    }
                }
                
                if (ltr)
                {
                    if (w < firstWidth)
                    {
                        w += sizingSpeed;
                        if (w > firstWidth)
                            w = firstWidth;
                        
                        div.style.width = w + 'px';
                    }
                }
                    
                if (w == firstWidth && h == firstHeight)
                {
                    stopSizing();
                    sizingComplated = true;
                }
            }
            else
                stopSizing();
        }
        else if (sizingDirection == 'down')
        {
            h = parseInt(div.style.height);
            w = parseInt(div.style.width);
            
            if (utd)
            {
                if (h > 0)
                {
                    h -= sizingSpeed;
                    if (h < 0)
                        h = 0;
                    
                    div.style.height = h + 'px';
                    sizingComplated = false;
                }
            }
            
            if (ltr)
            {
                if (w > 0)
                {
                    w -= sizingSpeed;
                    if (w < 0)
                        w = 0;
                    
                    div.style.width = w + 'px';
                    sizingComplated = false;
                }
            }
                
            if((w == 0 && !utd) || (h == 0 && !ltr) || (ltr && utd && w == 0 && h == 0))
                stopAndHide(div);
        }
        else
            stopAndHide(div);
    }
    else
        stopAndHide(div);
}

function stopAndHide(div)
{
    stopSizing();
    div.style.display = 'none';
    pnlVisible = false;
}

function stopSizing()
{
    clearInterval(intervalContainer);
    sizing = false;
}

function setWaterMarkText(cnt, txt)
{
    if (cnt.value == '')
        cnt.value = txt;
}

function unSetWaterMarkText(cnt, txt)
{
    if (cnt.value == txt)
        cnt.value = '';
}

function setWaterMarkOnLoad(cn, txt)
{
    var cnt = document.getElementById(cn);
    if(cnt && cnt.value == '')
        cnt.value = txt;
}

addListenerToEvent(window, 'load', createMsgDivCBError, false);
