var ajax_loader_img_s = "<img src='/content/images/ajax/ajax-loader_02.gif' align='absmiddle'>";
var ajax_loader_img_b = "<img src='/content/images/ajax/ajax-loader_01.gif' align='absmiddle'>";


function AJAX_getContent(url, DivID) {
 	
	//debugger;
	
	AJAX_waitForData(DivID);

	try {
    	xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (e) {
    	alert("Error: your browser doesn't support ajax.");
	}
 	
	xmlhttp.onreadystatechange = function() {AJAX_handleResponse(DivID)};

	url = url + "&tmp=" + Math.random();
	xmlhttp.open("GET", url, true);
 
	xmlhttp.send(null);
}
 
function AJAX_handleResponse(DivID) {

	//debugger;
	// if the readyState code is 4 (Completed)
	// and http status is 200 (OK) we go ahead and get the responseText
	// other readyState codes:
	// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
	
	//if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {

	if ( xmlhttp.readyState == 4 ) {
    	// xmlhttp.responseText object contains the response.
	    document.getElementById(DivID).innerHTML = xmlhttp.responseText;
		
		try {
			onEndAJAX();
		}
		catch (e) {
		}
	}	
} 



function AJAX_waitForData (div) {
	document.getElementById(div).innerHTML = ajax_loader_img_b + " Loading...";
}








//--- EU COUNRTY
//------------------------------------

function checkIfEUCoutry(country){
	var eu_coutry_array = new Array("AT", "BE", "BG", "CY", "CZ", "DE", "DK", "EE", "EL", "ES", "FI", "FR", "GB", "HU", "IE", "IT", "LT", "LU", "LV", "MT", "NL", "PL", "PT", "RO", "SE", "SI", "SK");
	
	var is_eu = 0;
		
	for (var i = 0; i < eu_coutry_array.length; i++) {
		if (eu_coutry_array[i] == country){
			is_eu = 1;
			break;
		}
	}
	
	return is_eu;
}




function SelectAllOrNone(form_name, chkBoxName, switcher_name) {

	frm =  eval( 'document.' + form_name);
	frm_sw =  eval( 'document.' + form_name + '.' + switcher_name );

	if (frm_sw.checked == true) {
		var elval = true;
	} 

	else {
		var elval = false;
	}
  
	for (var i=0;i<frm.elements.length;i++){

		var e = frm.elements[i];

		if (e.name == chkBoxName) {
			e.checked = elval;
		}
	 }

}


function onButtonClick( form_name, fld, cmd ) {
	
	if(opener){
		//if ( cmd == "" || cmd == "close"){
		if ( cmd == ""){
			close();
			return true;
		}
	}
	
	DisabledForm(form_name);
	
	if( ! fld )  fld = 'cmd';
	fld = eval('document.' + form_name + '.' + fld);
	fld.value = cmd;
	
	frm = eval('document.' + form_name);
	frm.submit();
	
}


function setCMDvar( form_name, fld, val ) {
	try {	
		if( ! fld )  fld = 'cmd_2';
		fld = eval('document.' + form_name + '.' + fld);
		fld.value = val;
	
		frm = eval('document.' + form_name);
	}
	catch(e) {
	}
}


function DisabledForm(form_name){
//	try {

		if (document.forms[form_name]){
			var f = document.forms[form_name];
			var e = f.elements;
			for (i=0;i<e.length;i++){
				if (e[i].type=='button'||e[i].type=='submit'){
					fe = e[i];
					fe.disabled=true;
					fe.enabled=false;
					if (fe.style){
						//fe.style.setAttribute('color','silver',false);
					}
				}
			}
		}

//	catch(e) {
//	}

}


function EnabledForm(form_name){
//	try {

		if (document.forms[form_name]){
			var f = document.forms[form_name];
			var e = f.elements;
			for (i=0;i<e.length;i++){
				if (e[i].type=='button'||e[i].type=='submit'){
					fe = e[i];
					fe.disabled=false;
					fe.enabled=true;
					if (fe.style){
						//fe.style.setAttribute('color','silver',false);
					}
				}
			}
		}

//	catch(e) {
//	}

}




function OpenTestWin (type, form_name, field_1, field_2){
	
	t_url = '';
	
	if (type == 'page'){
		fld = eval('document.' + form_name + '.' + field_2 + '.value');
		t_url = field_1 + fld;
	}
	
	if (type == 'url'){
		fld = eval('document.' + form_name + '.' + field_1 + '.value');
		t_url = fld;
	}

	if (type == 'direct'){
		t_url = field_1;
	}
	
	t_url = t_url.replace(/http:\/\//i, "");
	
	//alert(t_url);
	
	if (t_url != ''){
		t_url = 'http://' + t_url;
		window.open(t_url);
	}

}

function OpenCalcWin (type, form_name, field_1, field_2){
	
	t_url = '';
	
	if (type == 'page'){
		fld = eval('document.' + form_name + '.' + field_2 + '.value');
		t_url = field_1 + fld;
	}
	
	if (type == 'url'){
		fld = eval('document.' + form_name + '.' + field_1 + '.value');
		t_url = fld;
	}

	if (type == 'direct'){
		t_url = field_1;
	}
	
	t_url = t_url.replace(/http:\/\//i, "");
	
	//alert(t_url);
	
	if (t_url != ''){
		t_url = '/content/?page=tex_pub_link_calculator&F_url_target=' + t_url;
		window.open(t_url);
	}

}




function TestContainer (form_name, field, container_id, domain_id){

	url = eval('document.' + form_name + '.' + field + '.value');
		
	var win_width = 500;
	var win_height = 360;
	
	var Screen_Width = screen.availWidth;
	var new_x = (Screen_Width / 2)-(win_width / 2);
	
	//var wndhr = window.open( 'about:blank','win_test_container','top=50,left=' + new_x + ',width=' + win_width + ',height=' + win_height+ ',dependent=yes,hotkeys=no,locationbar=no,menubar=no,resizable=yes,scrollbars=no');
	//wndhr.location.href = '/content/pop_test_container.cfm?container_id=' + container_id + '&domain_id=' + domain_id + '&test_url=' + url;
	location.href = '/content/pop_test_container.cfm?container_id=' + container_id + '&domain_id=' + domain_id + '&test_url=' + url;
	/*
	if ( wndhr.opener == null ){
		wndhr.opener = window;
	}
	wndhr.focus();
	*/
		
	
}


function onLinkButtonClick_plus_rand( href ) {
	window.location.href = href + "&rand__id=" + Math.random();
}

function onLinkButtonClick( href ) {
	window.location.href = href;
}

function openWin(url){
	//window.open('http://hiderefer.com/?' + url);
	window.open('http://anonym.to/?' + url);
}

function openWin__old(url){
	window.open(url);
}



function openWinEscape(url){
	window.open(escape(url));
}


var cc_color_last = '';
function ChangeColor2(dieID, color, on_off){
	
	if ( on_off == 1 ){
		cc_color_last = document.getElementById(dieID).getAttribute("bgcolor","false");
		document.getElementById(dieID).setAttribute("bgcolor", color, "false");
	}
	
	if ( on_off == 0 ){
		document.getElementById(dieID).setAttribute("bgcolor",cc_color_last,"false");
	}
}






function onShowHide( div ) {
	/*
	if( document.getElementById(div).style.display == 'none' ){
		document.getElementById(div).style.setAttribute( 'display', 'inline', false );
	}
	else{
		document.getElementById(div).style.setAttribute( 'display', 'none', false);
		document.getElementById(div).style.display = "none";
	}
	*/
	document.getElementById(div).style.display = "none";
}

function SetShowHide( div, status ) {
	document.getElementById(div).style.display = status;
}



function change_img(img_name,img_src) {
	document[img_name].src=img_src;
}


function INDEX_dissable_all_text(){
	SetShowHide('home_text_trade', 'none');
	SetShowHide('home_text_buy', 'none');
	SetShowHide('home_text_sell', 'none');
}

function INDEX_enable_text(div){
	INDEX_dissable_all_text();
	SetShowHide(div, 'inline');
}


function onAdAction (div_id, id, action){

	var id_stat = 'ad_stat_' + div_id;
	var id_tool = 'ad_tool_' + div_id;
	
	if (action == 'client_ad_del'){
		document.getElementById(id_stat).innerHTML = "Link deleted";
		document.getElementById(id_tool).innerHTML = '';
		document.getElementById("iframe_disable").src = '/content/pop_camp_action.cfm?action=del_ad&who=client&ad_id=' + id + '&temp_id=' + Math.random();
	}
	else if (action == 'client_domain_block'){
		document.getElementById(id_stat).innerHTML = "Domain blocked";
		document.getElementById(id_tool).innerHTML = '';
		document.getElementById("iframe_disable").src = '/content/pop_camp_action.cfm?action=block_domain&who=client&ad_id=' + id + '&temp_id=' + Math.random();
	}
	
	if (action == 'seller_ad_del'){
		document.getElementById(id_stat).innerHTML = "Link deleted";
		document.getElementById(id_tool).innerHTML = '';
		document.getElementById("iframe_disable").src = '/content/pop_camp_action.cfm?action=del_ad&who=seller&ad_id=' + id + '&temp_id=' + Math.random();
	}
	else if (action == 'seller_page_del'){
		document.getElementById(id_stat).innerHTML = "Site deleted";
		document.getElementById(id_tool).innerHTML = '';
		document.getElementById("iframe_disable").src = '/content/pop_camp_action.cfm?action=seller_page_del&who=seller&ad_id=' + id + '&temp_id=' + Math.random();
	}
	else if (action == 'seller_domain_block'){
		document.getElementById(id_stat).innerHTML = "Domain blocked";
		document.getElementById(id_tool).innerHTML = '';
		document.getElementById("iframe_disable").src = '/content/pop_camp_action.cfm?action=block_domain&who=seller&ad_id=' + id + '&temp_id=' + Math.random();
	}

}




var formular = null;
var textfeld = null;
var uebrigFeld = null;
var intv = null;
var maxZeichen = 0;

function Zaehlen ()
{
    var laenge = textfeld.value.length;
    var uebrig = maxZeichen - laenge;

    if (uebrig < 0)
    {
          var inhalt = textfeld.value;
          var neuerInhalt = inhalt.substr(0, maxZeichen);
          textfeld.value = neuerInhalt;
          uebrig = 0;
          //alert('Sie dürfen maximal ' + maxZeichen + ' Zeichen verwenden!');
    }
 
    uebrigFeld.value = uebrig;
}

   
function parseNumberValue(val) {
	
	if (val == '') val = 0;
	
	var str = new String(val);
	var str = parseInt(str.replace(/ /g, ''));
	
	var str = new String(str);
	var arrStr = str.split('');
	var newStr = '';
	var count = 0;
	

	for (var i = (arrStr.length-1); i >= 0; i--) {
		if (count == 3) {
			newStr = ' ' + newStr;
			count = 0;
		}
		newStr = arrStr[i] + newStr;
		count ++;
	}

	return newStr;
}	



function parseFieldInt(field){

	var obj = document.getElementById(field);
	var obj_val = parseInt(obj.value);

	if ( isNaN(obj_val)) 	obj_val=0;

	document.getElementById(field).value = obj_val;
	
}

function parseFieldInt(obj){

	var value = parseInt(obj.value);

	if ( isNaN(value)) 	value=0;

	document.getElementById(obj.id).value = value;
	
}

function campSetAllAdsVal( obj ) {
	var value  = obj.value;
	var inputs = document.getElementsByTagName( 'INPUT' );

	for( var i in inputs ) {
		if ( inputs[i].type == 'text' && inputs[i].id.substr(0, 11) == 'f_camp_ad__') {
			inputs[i].value = value;
		}
	}
}

function campSetPartAdsVal( obj ){
	var index  = obj.selectedIndex
	var valPr = obj.options[index].value
	var inputs = document.getElementsByTagName( 'INPUT' );	
	
	// WERT
	var setVal = document.getElementById('f_camp_set_all_ads').value;
	
	var fieldNamePart = 'f_camp_ad__' + valPr;

	var fieldNameAll = 'f_camp_ad________';
	if ( valPr == (-1) ) fieldNameAll = 'f_camp_ad__';
	
	for( var i in inputs ) {
		if ( inputs[i].type == 'text'){
			if (inputs[i].id.substr(0, 12) == fieldNamePart || inputs[i].id.substr(0, 11) == fieldNameAll) {
				inputs[i].value = setVal;
			}
		}
	}

	//alert(setVal);


}




function get_field_radio_value(obj_name) {
		
	var t_val = null;
	obj = document.getElementsByName(obj_name);
		
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked){
			t_val = obj[i].value;
			break;
		}
	}
		
	return t_val;
}

function get_selected_chkboxes_by_name (ElementName){

	elementList = new Array();
	obj = document.getElementsByName(ElementName);
	
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked){
			t_val = obj[i].value;
			temp = elementList.push(obj[i].value);
		}
	}
	return elementList;
}


function trim (value) {
  // Erst führende, dann Abschließende Whitespaces entfernen
  return value.replace (/^\s+/, '').replace (/\s+$/, '');
}



function LoadJavaScript(file_url){

	var script_element=document.createElement("script"); 
	script_element.type="text/javascript"; 
	script_element.src= file_url; 
	var heads=document.getElementsByTagName("head"); 
	heads[0].appendChild(script_element); 
}

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

   
/* ---------------------------------------------------
	ADMIN
----------------------------------------------------*/
var recurs_resize = 0;
var resize_offset = 0;

function onResize( div_name, focus_name, resize_offset ) {
		

	//debugger;


	if( ! resize_offset )  resize_offset = 0;
	if( recurs_resize != 0 ) return;
	recurs_resize = 1;

	area = document.getElementById(div_name);
	
	bla = area;

		if( area ) {
			if( area.style ) {
				body = document.body;
				h = body.clientHeight - area.offsetTop - area.style.border;
				h = h - 25 - resize_offset;
				if( h > 0 )
					area.style.height = h;
			}
		}
		if( focus_name ){
			if( focus_name != '' ) {
				fn = document.all[focus_name];
				if( fn )  fn.focus();
			}
		}
	
	
	try {
		h_dhtml = (h - 0);
		//document.all.DHTMLSafe1.style.setAttribute( 'height', h_dhtml, false );
		area.style.height = h_dhtml;
	}
	catch(e) {
		return;
	}		
	
}

function openHelpbox(box_id, h){ 
	t_url = '/content/pop_helpbox.cfm?infobox_id=' + box_id;
	var wnddoc = window.open(t_url, 'MLS_Helpbpx', 'width=650,height=' + h + ',resizable=yes,scrollbars=yes');

	var new_x = 650;
	var new_y = h;
	
	wnddoc.resizeTo(new_x, new_y);
	wnddoc.focus();
	
}
	
	
	
