function showexperts(id){
	$$('ul.expertsubmenu').each(Element.hide);
	$('expert' + id).show();
}
function hideexperts(){
	$$('ul.expertsubmenu').each(Element.hide);
}

function parseXMLData(object) {
  if(object[0].childNodes[0] != null)
    return object[0].childNodes[0].data;
  else
    return "";
}

function getObject(name) {
	if (document.getElementById) {
    	obj=document.getElementById(name);
   	} else if (document.layers) {
     	obj=document.layers[name];
	} else if (document.all) {
	   obj=document.all[name];
	} else {
	   obj=false;
	}
	return obj;
}


function cfShowObject(item){
	item.style.display = "block";
	return true;
}

function cfHideObject(item){
	item.style.display = "none";
	return true;
}

function catClick(obj){
	try { 
		getObject("isPremium").value=0;
		getObject("isPremiumExtra").value=0;
	} catch(e){
	}
	catChange(obj);
}

function setTypePayment(obj){
	dvFormCreditCard = getObject("divFormCreditCard");
	dvFormChceck = getObject("divFormChceck");
	
	if(obj.value == 1){
		cfShowObject(dvFormCreditCard);
		cfHideObject(dvFormChceck);
	}
	else{
		cfHideObject(dvFormCreditCard);
		cfShowObject(dvFormChceck);
	}
}


function subChange(obj){
	try { 
		dvTypePromotion = getObject("divTypePromotion");
		dvSubCategory = getObject("divSubCategory");
		subPath = getObject("subPath");
		catPath = getObject("catPath");
		mainPath = getObject("mainPath");
	}
	catch(e){}
	
		
	if(obj.options[obj.selectedIndex].value != 0) {
		cfShowObject(catPath);
		cfShowObject(dvTypePromotion);
		subPath.value = obj.options[obj.selectedIndex].text;
		makePath(catPath);
	}
	else {
		cfHideObject(dvTypePromotion);
		subPath.value = null;
		makePath(catPath);
	}
	
}

function makePath(objPath){
		try {
			mainPath = getObject("mainPath");
			subPath = getObject("subPath");
			objPath.innerHTML = '<span style="font-size:11px;">wybrano:</span> <b><A href="#">'+mainPath.value+'</A></b>';
		
			if(subPath.value != "")
				objPath.innerHTML += ' / <b>'+subPath.value+'</b>';
		}
		catch(e){}
}



function catChange(obj){
	
	try { 
		var dvTypePromotion = getObject("divTypePromotion");
		var dvSubCategory = getObject("divSubCategory");
		var dvFormVarious = getObject("divFormVarious");
		var dvFormRealEstate = getObject("divFormRealEstate");
		var dvFormMoto = getObject("divFormMoto");
		var selSubCategory = getObject("subCategory");
		var catPath = getObject("catPath");
		var mainPath = getObject("mainPath");
		var subPath = getObject("subPath");
		
	}
	catch(e){}
	
	
	if( obj.options[obj.selectedIndex].value != 0 && (obj.options[obj.selectedIndex].value != 27) && (obj.options[obj.selectedIndex].value != 10) ) {
		cfHideObject(dvFormMoto);
		cfHideObject(dvFormRealEstate);
		cfHideObject(dvTypePromotion);
		
		
		mainPath.value = obj.options[obj.selectedIndex].text;
		subPath.value = '';
		makePath(catPath);
		
		cfShowObject(catPath);
		cfShowObject(dvSubCategory);
		cfShowObject(dvFormVarious);	
	
		selSubCategory.selectedIndex = 0;
	
	}
	else if (obj.options[obj.selectedIndex].value == 27) {
		cfHideObject(dvFormVarious);
		cfHideObject(dvFormRealEstate);
		cfHideObject(dvTypePromotion);

		mainPath.value = obj.options[obj.selectedIndex].text;
		subPath.value = '';
		makePath(catPath);
		
		cfShowObject(catPath);
		cfShowObject(dvSubCategory);
		cfShowObject(dvFormMoto);
		
		selSubCategory.selectedIndex = 0;
	}
	
	else if (obj.options[obj.selectedIndex].value == 10) {
		cfHideObject(dvFormVarious);
		cfHideObject(dvFormMoto);
		cfHideObject(dvTypePromotion);

		mainPath.value = obj.options[obj.selectedIndex].text;
		subPath.value = '';
		makePath(catPath);
		
		cfShowObject(catPath);
		cfShowObject(dvSubCategory);
		cfShowObject(dvFormRealEstate);
		
		selSubCategory.selectedIndex = 0;
	}
	
	else {
		mainPath.value = '';
		subPath.value = '';
		makePath(catPath);
			
		cfHideObject(catPath);
		cfHideObject(dvTypePromotion);
		cfHideObject(dvSubCategory);
		cfHideObject(dvFormVarious);
		cfHideObject(dvFormMoto);
		cfHideObject(dvFormRealEstate);
		selSubCategory.selectedIndex = 0;
	}
	
	
	
	//sel.blur();
	
	
	/*
	AjaxRequest.get(
  	{
    	'url' : '/?username=test',
		'onSuccess' : function(req) {
				getObject("ogtypeLink").innerHTML = req.responseText
	 	}
	}
	);
	*/
	
	
	//return false;
}

String.prototype.addClass = function(theClass) {
	if (this != "") {
		if (!this.classExists(theClass)) {
			return this + " " + theClass;
		}
	}
	else {
		return theClass;
	}
	return this;
}

String.prototype.classExists = function(theClass) {
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	if (regExpression.test(this)) {
		return true;
	}
	return false;
}

String.prototype.removeClass = function(theClass){
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	return this.replace(regExpression, "");
}

var gridReload = 0;
function makeGetRequest(url, divname){
		AjaxRequest.get(
		{
			'url' : url,
			'onLoading' : function(req){
				if(gridReload == 1)
						getObject(divname).innerHTML = '<p style="text-align:center;vertical-align:middle;margin:0px;"><img src="/img/preloader.gif" style="width:19px;height:21px;"/></p>';		
						},
			'onComplete' : function(req){
				var url = req.getResponseHeader('location');
				if(url){
					location.href = url;
				}
     	},
	
			'onSuccess' : function(req){
				try { onMySuccess(req); } catch (e) { alert(e)}
				//alert(req.responseText);
				return true;
			}
		}
		);
	}



function openNormalImage(url, width, height){
  var okno = window.open(url,"DisplayWindow","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=no,width=" + (width+40) + ", height="+(height+40));
  okno.moveTo((screen.availWidth/2)-(width/2),(screen.availHeight/2)-(height/2));
  okno.focus();

}


function openPrint(url, width, height){
	window.status='Print article';
  var okno = window.open(url,"DisplayWindow","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=no,width=" + width + ", height="+height);
  okno.moveTo((screen.availWidth/2)-(width/2),(screen.availHeight/2)-(height/2));
  okno.focus();

}

/** Web Dynamit */
function GetRequest(url, fref_name, loader_div){
		AjaxRequest.get(
		{
			'url' : url,
			'onLoading' : function(req){
				try{
						showDiv(loader_div);	
						getObject(loader_div).innerHTML = '<p style="text-align:center;vertical-align:middle;margin:0px;padding:5px;"><img src="/img/loading.gif" />&nbsp;Loading ... </p>';		
					}catch(e){}		
						},
			'onComplete' : function(req){
				try{
					hideDiv(loader_div);
					var url = req.getResponseHeader('location');
					if(url){
						location.href = url;
					}
				}	catch(e){}
     	},
	
			'onSuccess' : function(req){
				try {
					eval('onMySuccess'+ fref_name + '(req)');
				} catch (e) {  }
				return true;
			}
		}
		);
}

function evalJson(data){
	return eval("(" + data + ")");
}

function dbgArr(arr){
	for(i in arr)
		alert(i+'->'+arr[i]);
}

function showDivRowInTable(name){
	var divObj = getObject(name);
	showRow = (navigator.appName.indexOf("Internet Explorer") != -1) ? "block" : "table-row";
	divObj.style.display = showRow;
}
