﻿// *******************************
// Base Library
// 1.0.0
// (C) 2008 DG2
// *******************************
// *******************************
// $request
// *******************************
var isRequest = 0;
function $requestrunning() {
    if (isRequest == 1) { return true } else  { return false }
}

function $request(strPh, strURL, strData, blnIsLoading) {
    isRequest = 1;
    
    if (blnIsLoading) {
        $get('NonVisibleWaitingMessage').style.display = 'block';
    }
    
    $(document).ready(function() {
        $.ajax({
            type: "POST",
            url: strURL,
            data: strData,
            success: function(data) {
                if (strPh == 'DoAlert') { alert(data); } else { $get(strPh).innerHTML = data; }
                $get('NonVisibleWaitingMessage').style.display = 'none';
                isRequest = 0;
            }
        }); 
    });
}

// *******************************
// $get
// *******************************
function $get(str) {
    return document.getElementById(str);
}

// *******************************
// $navigate
// *******************************
function $navigate(value) {
    location.href = value
}

// *******************************
// $confirm
// *******************************
function $confirm(strmsg) {
    var answer = confirm(strmsg);
	if (answer) {
	    return true;
	}
	
	else { 
        return false
	}
}

// *******************************
// $hover
// *******************************
var objLastHover;
function $hover(obj, blnLastHover) {
    if (blnLastHover) { objLastHover = obj; }
    if ($right(obj.className, 5) == 'Hover') {
        obj.className = obj.className.replace('Hover','')
    }
    else { obj.className+='Hover' }
}

// *******************************
// $pophover
// *******************************
function $hoverpop(obj, txt) {
    var popObj = $get('mPop');
    if (popObj.style.display == 'none') {
        $cover(obj, popObj, 1);
        popObj.style.marginTop = '0px';
        popObj.style.marginLeft = '0px';
        popObj.className = 'mPop';
        popObj.style.display = 'block';
        popObj.innerHTML = txt
    }
    
    else {
        popObj.style.display = 'none';
    }
}

// *******************************
// $pophoverm
// *******************************
function $hoverpopm(obj, txt) {
    var popObj = $get('mPopM');
    if (popObj.style.display == 'none') {
        $cover(obj, popObj, 1);
        popObj.style.marginTop = '0px';
        popObj.style.marginLeft = '0px';
        popObj.className = 'mPop';
        popObj.style.display = 'block';
        popObj.innerHTML = txt
    }
    
    else {
        popObj.style.display = 'none';
    }
}

// *******************************
// $cover
// *******************************
function $cover(bottom, top) {
    var position = $(bottom).position();
    top.style.position = 'absolute';
    top.style.top = (position.top + bottom.offsetHeight)-1 + 'px';
    top.style.left = position.left + 'px';
}

// *******************************
// $covertop
// *******************************
function $covertop(bottom, top) {  
    var position = $(bottom).position();
    top.style.display = 'block';
    top.style.position = 'absolute';
    top.style.top = (position.top - top.offsetHeight)-1 + 'px';
    top.style.left = position.left + 'px';
}


// *******************************
// $checkselect
// *******************************
function $checkselect() {
    count = document.aspnetForm.elements.length;

    for (i=0; i < count; i++) {
        if(document.aspnetForm.elements[i].checked == 1)
    	    {document.aspnetForm.elements[i].checked = 0;}
        else {document.aspnetForm.elements[i].checked = 1;}
	}
}

// *******************************
// $flip
// *******************************
function $flip(id) {
    var box = document.getElementById(id);
    
    if (box.style.display == 'none') {
        box.style.display = 'block';
    }
    else {
        box.style.display = 'none';
    }
}

// *******************************
// $fckappend
// *******************************
function $fckappend(fckObj, str) {
    str = HtmlDecode(str);
    var oEditor = FCKeditorAPI.GetInstance(fckObj);
    oEditor.Focus();
    oEditor.InsertHtml(str)
}

// *******************************
// $fckimageappend
// *******************************
function $fckimageappend(fckObj, strImg) {
    strImg = '<img border="0" src="'+strImg+'" />'
    var oEditor = FCKeditorAPI.GetInstance(fckObj);
    oEditor.Focus();
    oEditor.InsertHtml(strImg)
}

// *******************************
// $left
// *******************************
function $left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

// *******************************
// $right
// *******************************
function $right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// *******************************
// $limittext
// *******************************
function $limittext(textid, limit) { 
    var text = $('#'+textid).val();
    var textlength = text.length;
    
    if(textlength > limit) { 
        $('#'+textid).val(text.substr(0,limit)); 
        return false; 
    }
}

// *******************************
// $hide
// *******************************
function $hideform() {
    if ($get('mSearch')) {
        if ($get('mSearch').className != 'InputTextGray') { 
            return false;
        }
    }
    
    document.aspnetForm.style.display = 'none';
    $get('NonVisibleWaitingMessage').style.display = 'block';
}

// *******************************
// $markupsetfield
// *******************************
var MarkUpFieldObj;
function $markupsetfield(obj) {
    MarkUpFieldObj = obj
}

// *******************************
// $markup
// *******************************
function $markup(field, tagbefore, tagafter) {

    if (field == null) {
        field = MarkUpFieldObj;
    }
    
    var clientPC = navigator.userAgent.toLowerCase();
    var clientVer = parseInt(navigator.appVersion);       
    var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
    var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1) && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1) && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
    var is_moz = 0;
    var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
    var is_mac = (clientPC.indexOf("mac")!=-1);  
    
  	field.focus();
  	var sel;
  
  	if ((clientVer >= 4) && is_ie && is_win) {
  		sel = document.selection.createRange().text; 
  
  		if (sel) {
  			document.selection.createRange().text = tagbefore + sel + tagafter;
  			field.focus();
  			sel = '';
  			return;
  		}
  	}
  	
  	else if (field.selectionEnd && (field.selectionEnd - field.selectionStart > 0)) {
  		var selLength = field.textLength;
    	var selStart = field.selectionStart;
    	var selEnd = field.selectionEnd;
    	if (selEnd == 1 || selEnd == 2)
    		selEnd = selLength;                    		
  		
    	var s1 = (field.value).substring(0,selStart);
    	var s2 = (field.value).substring(selStart, selEnd)
    	var s3 = (field.value).substring(selEnd, selLength);
    	field.value = s1 + tagbefore + s2 + tagafter + s3;
  		
  		return;
  	}
  
  	field.value += tagbefore;
  	field.value += tagafter;
  	field.focus();
  	return;
}


