var ns4 = (navigator.appName.indexOf("Netscape")!=-1 && navigator.appVersion.substring(0,1) < "5")? true:false
var ns6 = (navigator.appName.indexOf("Netscape")!=-1 && navigator.appVersion.substring(0,1) >= "5")? true:false
var ie  = (navigator.appName.indexOf("Microsoft Internet Explorer")!=-1)? true:false
	
function show_id(id_name) {		
   if(ie) {
		document.all[id_name].style.display = "block";	
	}	
	else if(ns4) {
	   document.layers[id_name].style.display = "block";
	}	
	else {
		document.getElementById(id_name).style.display = "block";
	}
}

function hide_id(id_name) {		
   if(ie) {
		document.all[id_name].style.display = "none";	
	}	
	else if(ns4) {
	   document.layers[id_name].style.display = "none";
	}	
	else {
		document.getElementById(id_name).style.display = "none";
	}
}

function write_id(id_name, str) {		
   if(ie) {
		document.all[id_name].innerHTML = str;	
	}	
	else if(ns4) {
	   document.layers[id_name].innerHTML = str;
	}	
	else {
		document.getElementById(id_name).innerHTML = str;
	}
}

function show_search_attributes() {
   show_id('search_attributes');  
   hide_id('search_attributes_switch_on');
   show_id('search_attributes_switch_off');
}

function hide_search_attributes() {
   hide_id('search_attributes');  
   show_id('search_attributes_switch_on');
   hide_id('search_attributes_switch_off');
}

function navHoverIn(id) {
	id.className = "hover";
}

function navHoverOut(id) {
	id.className = "";
}

function show_image(img, title, id) {
   document.getElementById('main_media_web_url').src = img;
   document.getElementById('main_media_web_url').title = title;
   image_id = id;
}



function show_media_popup(media_id, media_extension) {
	picprev = window.open("/perl/fe/client/estate.pl?todo=show_object_media_popup&media_id=" + media_id + "&media_extension=" + media_extension,"object_media_popup","width=750, height=600, scrollbars=no,status=yes");
}

function show_content_popup(url) {
	cp = window.open(url,"cp","width=750, height=600, scrollbars=yes,status=yes");
}

function show_report_info(url) {
	crozillareport = window.open(url, "CrozillaReport","width=500,height=450,scrollbars,resizable=yes,toolbar=NO");
	crozillareport.focus();
}

function show_info(obj, id) {
	//obj.src ="/img/info_used.gif";
	document.getElementById('infobox').style.top = findPosY(obj)+'px';
	document.getElementById('infobox_content').innerHTML = infos[id];
	document.getElementById('infobox_headline').innerHTML = headlines[id];
	document.getElementById('infobox').className = "";
}
function hide_info(obj) {
	document.getElementById('infobox').className = "hiddenBox";
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	window.status = printstring;
	return curtop;
}

function make_pointer() {
	document.body.style.cursor='pointer';
}
function del_pointer() {
	document.body.style.cursor='auto';
}
function show_payment ( cc, invoice, monthly, duration_month ){
   if (cc == 1) {
      //show_id('payment_cc');
      document.getElementById('cc_price').style.visibility = 'visible';
      document.getElementById('cc_pay').style.visibility = 'visible';
   }
   else {
      //hide_id('payment_cc');
      document.getElementById('cc_price').style.visibility = 'hidden';
      document.getElementById('cc_pay').style.visibility = 'hidden';
      
      document.buy_package.method_of_payment[0].checked = 'true';
   }
   
//   if (invoice == 1) {
//      show_id('payment_invoice');
//   }
//   else {
//      hide_id('payment_invoice');
//   }
   
//   if (duration_month == 1) {
//      hide_id('payment_month_1');
//   }
//   else {
//      show_id('payment_month_1');
//   }
//   
//   if (monthly == 1) {      
//      show_id('payment_pay_complete');
//      show_id('payment_pay_monthly');
//   }
//   else {
//
//      hide_id('payment_pay_complete');
//   }
}



MS_restrict_field = function(formname, id_or_name, chars) {

	var obj = (document.getElementById && document.getElementById(id_or_name) != null)
			  ? document.getElementById(id_or_name) : ((document[formname][id_or_name] != null)
			  ? document[formname][id_or_name] : '');

	if(obj.type == "text" || obj.type == "textarea") {

		obj.timer = "";
		obj.chars = chars;
		obj.onkeypress = obj.onkeydown = function() {
			var self = this;
			controll = function() {
				for(var t='',x=0; x<self.value.length; ++x) {
					if(self.chars.indexOf(self.value.charAt(x))>-1) {
						t += self.value.charAt(x);
					}
				}
				self.value = t;
			};
			this.timer = setTimeout(controll,1);
		};
		obj.onkeyup = function() {
			clearTimeout(this.timer);
		};
	}
};



function refresh_secode() {
    var captcha = document.getElementById("secode_img");
    var url = captcha.src;
    
    // Falls &random= nicht gefunden wird, selbst anhängen
    if (url.substr(url.length - 11, 1) != '?') {
        url += '?';        
    } else {
        url = url.substr(0, url.length - 10);
    }
  
    
    // 10 Random Zeichen erzeugen
    for (var i = 0; i < 10; ++i) {
        var zahl = Math.floor(Math.random() * 9);
        url += zahl.toString()
    }


    captcha.src = url;
    
    
    return false;
}

String.prototype.stripNonNumeric = function() {
    var str = this + '';
    var rgx = /^\d|\.|-$/;
    var out = '';
    for( var i = 0; i < str.length; i++ ) {
        if( rgx.test( str.charAt(i) ) ) {
            if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||
            ( str.charAt(i) == '-' && out.length != 0 ) ) ) {
                out += str.charAt(i);
            }
        }
    }
    return out;
};

function addCommas(nStr)
{
  nStr += '';
  x = nStr.split('.');
  x1=x[0];
  x2=x[1];
  x1=x1.replace(",",".");
  x1=x1.replace(",",".");
  return x1+","+x2;

}

Number.prototype.format = function(format) {
    if (!(typeof format == "string")) {return '';} // sanity check

    var hasComma = -1 < format.indexOf(','),
        psplit = format.stripNonNumeric().split('.'),
        that = this;

    // compute precision
    if (1 < psplit.length) {
        // fix number precision
        that = that.toFixed(psplit[1].length);
    }
    // error: too many periods
    else if (2 < psplit.length) {
        throw('NumberFormatException: invalid format, formats should have no more than 1 period: ' + format);
    }
    // remove precision
    else {
        that = that.toFixed(0);
    }

    // get the string now that precision is correct
    var fnum = that.toString();

    // format has comma, then compute commas
    if (hasComma) {
        // remove precision for computation
        psplit = fnum.split('.');

        var cnum = psplit[0],
            parr = [],
            j = cnum.length,
            m = Math.floor(j / 3),
            n = cnum.length % 3 || 3; // n cannot be ZERO or causes infinite loop

        // break the number into chunks of 3 digits; first chunk may be less than 3
        for (var i = 0; i < j; i += n) {
            if (i != 0) {n = 3;}
            parr[parr.length] = cnum.substr(i, n);
            m -= 1;
        }

        // put chunks back together, separated by comma
        fnum = parr.join(',');

        // add the precision back in
        if (psplit[1]) {fnum += '.' + psplit[1];}
    }

    // replace the number portion of the format with fnum
    return format.replace(/[\d,?\.?]+/, fnum);
};

