﻿function _void(){
    void 3;
}
function OpenSizedPopup(url, key, width, height){
    void window.open(url,key,'width=' + width + 'px,height='+ height +'px, scrollbars=1');
}
function OpenSmallPopUp(url)
{
    var popup = window.open(url,"SmallPopUp",'width=200px, scrollbars=1');
    return false;
}
function ScrollTop()
{
    window.scroll(0,0);
}
function ScrollBottom()
{
    window.scrollTo(0,1000);
}

function MakeAjaxCall(url, dataObject)
{
   // alert(dataObject);
    $.ajax(
    {
        type    : "POST",
        url     : url,
        data    : dataObject,
        async   : false,
        cache   : false,
        success : function(data) 
        {
            // do something..
        }
    });
}
/****************************************************************
 *********** Cross browser get srcElement ***********************
 ****************************************************************/ 
function GetTargetElement(e)
{
    var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
    return targ;
}

/****************************************************************
 ** Find Ancestor for which a function returns true *************
 ****************************************************************/ 
function FindAncestor(el, comparisonFunc)
{
    if (comparisonFunc(el) == true) return el;
    else if (el.parentNode) {
        return arguments.callee(el.parentNode, comparisonFunc);
    }
    else return false;  
}


/****************************************************************
 ** Handle open\close for the RightNavBar - must pass event *****
 ****************************************************************/ 
function OpenRightNavBar()
{
    Hide(document.getElementById('RightNavBarClosed'));
    Show(document.getElementById('RightNavBarContainer'));
}
function CloseRightNavBar()
{
    Show(document.getElementById('RightNavBarClosed'));
    Hide(document.getElementById('RightNavBarContainer'));
}

function Show(el)
{
    if (el && el.style) {
        el.style["display"] = "";
    }
}
function Hide(el)
{
    if (el && el.style) {
        el.style["display"] = "none";
    }
}

// set/get session params

function getSessionParam(key)
{
//    var miscPath = "http://" + location.host;
//    if (location.pathname.length>5 && location.pathname.toLowerCase().substring(0,5)=="/site") miscPath+="/Site";
    var r = GetSynchronousJSONResponse( "~/common/misc/GetSessionParam.aspx?key="+key ,null);
    return r;
}

function setSessionParam(key,value)
{
//    var miscPath = "http://" + location.host;
 //   if (location.pathname.length>5 && location.pathname.toLowerCase().substring(0,5)=="/site") miscPath+="/Site";
    var r = GetSynchronousJSONResponse("~/common/misc/SetSessionParam.aspx?key="+key+"&value="+value ,null);
    return r;
}

function GetSynchronousJSONResponse(url, postData) {
    var xmlhttp = null;
    if (window.XMLHttpRequest)
        xmlhttp = new XMLHttpRequest();
    else if (window.ActiveXObject) {
        if (new ActiveXObject("Microsoft.XMLHTTP"))
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        else
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
        // to be ensure non-cached version of response
    url = url + "&rnd=" + Math.random(); 
    
    xmlhttp.open("GET", url, false);//false means synchronous
    xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    xmlhttp.send(postData);
    var responseText = xmlhttp.responseText;
    return responseText;
}

function enableDescendants(objId, is_enable) {
      	var obj = document.getElementById(objId);
        if (obj == null) return;
        var children = obj.childNodes;
        for (var i = 0; i < children.length; i++) {
		if (children[i].nodeType == 1) { // IE only allows elements
                	children[i].disabled = !is_enable;
		}
                enableDescendants(children[i], is_enable);
        }
}

function ButtonBoldSelection(textBoxId)
{
  var textComponent = document.getElementById(textBoxId);
  var selectedText;
  // IE version
  if (document.selection != undefined)
  {
    textComponent.focus();
    var sel = document.selection.createRange();
    selectedText = sel.text;
  }
  // Mozilla version
  else if (textComponent.selectionStart != undefined)
  {
    var startPos = textComponent.selectionStart;
    var endPos = textComponent.selectionEnd;
    selectedText = textComponent.value.substring(startPos, endPos)
  }
  //alert("You selected: " + selectedText);
  textComponent.value = textComponent.value.replace(selectedText,'<b>'+selectedText+'</b>');
  $get('divPreviewBoldTextbox').innerHTML = textComponent.value.replace('\r\n','<br />').replace('\n','<br />');
}
