
function popup(url, name, properties)
{
    //eg properties='width=400,height=200,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no'
    var w = window.open(url, name, properties);
    w.focus();
}
function open_birdseye(url) // bird's eye view map window
{
    document.getElementById('frameBirdsEye').src = url;
    display('divBirdsEye');
    //popup(url, 'BirdsEyeMap', 
      //      'width=550,height=530,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no');
}
function open_detail(url) // listing detail window
{
    popup(url, 'ListingDetail', 
            'width=820,height=750,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}

function open_save(url) // listing detail window
{
    popup(url, 'SaveSearch', 
            'width=620,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function open_other(url) // listing detail window
{
    popup(url, 'SaveSearch', 
            'width=650,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function open_report(url) 
{
    popup(url, 'Report', 
            'width=820,height=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function open_small(url) // listing detail window
{
    popup(url, 'SaveSearch', 
            'width=650,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
}
function close_birdseye()
{
    hide('divBirdsEye');
    document.getElementById('frameBirdsEye').src = "";
}
function IsNumeric(sText)
{
    var ValidChars = "0123456789.,$ ";
    var IsNumber=true;
    var Char;
    
    for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
            IsNumber = false;
         }
      }
    return IsNumber;
}
function display(divName)
{
    if ( document.getElementById(divName))
        document.getElementById(divName).style.display = '';
}
function hide(divName)
{
    if ( document.getElementById(divName))
        document.getElementById(divName).style.display = 'none';
}
function GetTxtValue(id)
{
    if (document.getElementById(id))
        return document.getElementById(id).value;
    else
        return '';
}
function SetTxtValue(id, val)
{
    if (document.getElementById(id))
        document.getElementById(id).value = val;
}
function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
    amount = n; 
	
	amount = minus + amount;
	return amount;
}
function getAlphabet(num)
{
    var alphabets = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W", "X","Y","Z");
    return alphabets[num];
}
function SetCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function GetCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function ClearCookie(name) 
{
	SetCookie(name,"",-1);
}
function FieldHelpText(field, w)
{
    if (field.defaultValue == field.value) 
    {
        field.value = '';
        if (w == "1")
            field.className = "inputW";
        else
            field.className = "txt_blk";
    }
    else if (field.value == '') 
    {
        field.value = field.defaultValue;
        if (w == "1")
            field.className = "inputW_gray";
        else
            field.className = "txt_gray";
    }
}

function toggleById(divName)
{
    if ( document.getElementById(divName))
    {        
        if ( document.getElementById(divName).style.display == '')
            document.getElementById(divName).style.display = 'none';
        else
            document.getElementById(divName).style.display = '';
    }   
}
function isHidden(divName)
{
    if ( document.getElementById(divName))
    {
        if (document.getElementById(divName).style.display == 'none')
            return true;
        else
            return false;
    }
    else
        return true; // not there
}
function addOption(obj, opt)
{
    try 
    {
        obj.add(opt, null); // standards compliant; doesn't work in IE
    }
    catch(ex) 
    {
        obj.add(opt); // IE only
    }
}

function showToolTip(e,text){
	if(document.all)e = event;
	
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	obj2.innerHTML = text;
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX - 100;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
}	

function hideToolTip()
{
	document.getElementById('bubble_tooltip').style.display = 'none';
	
}



// From prototype.js
function $A(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) return iterable.toArray();
  var length = iterable.length || 0, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}

Function.prototype.bind = function() {
    if (arguments.length < 2 && typeof arguments[0] == "undefined")
        return this;
    var __method = this, args = $A(arguments), object = args.shift();
    return function() {
      return __method.apply(object, args.concat($A(arguments)));
    }
}

Function.prototype.bindAsEventListener = function() {
    var __method = this, args = $A(arguments), object = args.shift();
    return function(event) {
        return __method.apply(object, [event || window.event].concat(args));
    }
}


function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++) {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripCharsNotInBag(s, bag) {
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++) {
        // caracterul nu este spatiu
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) {
            // remove everything after decimal point
            if (c == ".") {
                break;
            }
            else {
                returnString += c;
            }
        }
    }
    return returnString;
}

function checkInt(val) {
    return (!isNaN(val));
}

function checkIntMaxValue(val) {
    val = stripCharsNotInBag(val, '1234567890.');
    if (val > 2147483647) {
        return 2147483647;
    }
    return val;
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

String.prototype.ltrim = function() {
    return this.replace(/^\s+/, "");
}

String.prototype.rtrim = function() {
    return this.replace(/\s+$/, "");
}


function resizeIFrame(iframe, plusHeight) {
    try {
        if (iframe) {


            if (iframe.contentDocument) // firefox
            {
                var height = iframe.contentDocument.body.scrollHeight;
                if (plusHeight != undefined)
                    height = height + plusHeight;
                iframe.height = height;
            }
            else // IE
            {
                var height = iframe.contentWindow.document.body.scrollHeight;
                if (plusHeight != undefined)
                    height = height + plusHeight;
                iframe.style.height = height;
            }

        }
    }
    catch (e) { }

}
function resizeIFrameH(iframe, height) {
    try {
        if (iframe) {


            if (iframe.contentDocument) // firefox
            {
                iframe.height = height;
            }
            else // IE
            {
                iframe.style.height = height;
            }

        }
    }
    catch (e) { }

}
function resizeIFrameW(iframe, width) {
    try {
        if (iframe) {
            if (iframe.contentDocument) // firefox 
            {
                iframe.height = iframe.contentDocument.body.scrollHeight;
                iframe.width = width;
            }
            else // IE 
            {
                iframe.style.height = iframe.contentWindow.document.body.scrollHeight;
                iframe.style.width = width;
            }

        }
    }
    catch (e) { }
}

function resizeIFrameWH(iframe, width, height) {
    try {
        if (iframe) {
            if (iframe.contentDocument) // firefox 
            {
                iframe.height = height;
                if (width > 750)
                    iframe.width = width;
            }
            else // IE 
            {
                iframe.style.height = height;
                if (width > 750)
                    iframe.style.width = width;
            }

        }
    }
    catch (e) { }
} 

