// utils -----------
function closeMe(obj) {
  $(obj).hide();
}

function isParent(parent,node) {
  if (node == null) {
    return false;
  }
  else if (node == parent) {
    return true;
  }
  return isParent(parent, node.parentNode);
}

function getPositionX(obj) {
  var currentX = 0;
  if (obj.offsetParent) {
    do {
      currentX += obj.offsetLeft;
      obj = obj.offsetParent;
    } while (obj)
  } else if (obj.x) {
    currentX = obj.x;
  }
  return currentX;
}

function getPositionY(obj) {
  var currentY = 0;
  if (obj.offsetParent) {
    do {
      currentY += obj.offsetTop;
      obj = obj.offsetParent;
    } while (obj)
  } else if (obj.y) {
    currentY = obj.y;
  }
  return currentY;
}

function clearInput(obj,text) {
  if(obj.value == text) {
      obj.value = '';
  }
  obj.onblur = function() {
  if(obj.value == '') {
      obj.value = text;
    }
  }
}

// kategoria/hover -
function addBoxHov(obj) {
  $(obj).addClass('hov');
  obj.style.cursor = 'pointer';
}

function remBoxHov(obj) {
  $(obj).removeClass('hov');
  obj.style.cursor = '';
}

function chooseLang(obj) {
	obj.blur();
	if(obj.expanded) {
		obj.expanded = false;
		obj.parentNode.getElementsByTagName('div')[0].style.display = 'none';
	} else {
		obj.expanded = true;
		obj.parentNode.getElementsByTagName('div')[0].style.display = 'block';
	}
	
	return false;
}

// contact

var idContact = "idContact";

function contact(url){
	var page_request = false
	if (window.XMLHttpRequest) { // Mozilla
		page_request = new XMLHttpRequest()
	} else if (window.ActiveXObject){ // if IE
			try {
				page_request = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
				try{
					page_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){}
			}
	} else {
		return false
	}
	page_request.onreadystatechange=function() {
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(idContact).innerHTML=page_request.responseText;
		}
	}
	url+= "?url=" +  window.location.protocol + "//" + window.location.host + window.location.pathname;
	page_request.open('GET', url, true);
	page_request.send(null);
}

function contactClose(url){
	document.getElementById(idContact).innerHTML = "";
}
function submitContact() {
	var message = document.forms["ContactForm"].message.value;
	var email = document.forms["ContactForm"].email.value;
	var phone = document.forms["ContactForm"].phone.value;
	var url = document.forms["ContactForm"].url.value;
	var pageId = document.forms["ContactForm"].pageId.value;
	var checkbox = document.forms["ContactForm"].checkbox.value;
	if (checkbox=='on') {
		checkbox = document.forms["ContactForm"].checkbox.checked;
	}
	url="/do/contact?pageId=" + pageId + "&message="+ message +"&phone="+ phone +"&email="+ email + "&url=" + url + "&checkbox=" + checkbox;	
	var page_request = false
	if (window.XMLHttpRequest) { // Mozilla
		page_request = new XMLHttpRequest()
	} else if (window.ActiveXObject){ // if IE
			try {
				page_request = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
				try{
					page_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){}
			}
	} else {
		return false
	}
	page_request.onreadystatechange=function(){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(idContact).innerHTML=page_request.responseText;
	}

	}
	page_request.open('GET', url, true);
	page_request.send(null);
}

function loadContentMP() {
	$.post("/do/FaqListTabActionMP", { pageId : $("#pageId").val(), 
									   sectionId : $("#sectionId").val(),
									   task: "MainPage", 
									   urlsCount: $("#urlsCount").val(),
									   cmpLabel: $("#cmpLabel").val()} ,
			function(data) {
				$("#faqListTabContentMP").html(data);
			});
}

function loadContentDP() {
	$.post("/do/FaqListTabActionDP", { pageId : $("#pageIdDP").val(), 
									   sectionId : $("#sectionIdDP").val(),
									   task: "DepPage", 
									   urlsCount: $("#urlsCountDP").val(),
									   cmpLabel: $("#cmpLabelDP").val(),
									   faqListUrl: $("#faqListUrlDP").val()} ,
			function(data) {
				$("#faqListTabContentDP").html(data);
			});
}


function loadContentNP(taskName, selectedCategory) {
	var page = $("#pageId").val();
	var section = $("#sectionId").val();
	$("#newsListTabContent").html("<img src=\"/static/img/ajax-loader.gif\" alt=\"\" id=\"loadingImageNP\" style=\"display: block; margin: 80px 0 0 160px\" />");
	$.post("/do/NewsListTabAction", 
		{ pageId : page, 
		  sectionId : section,
		  task: taskName, 
		  selectedCategory: selectedCategory} ,
		function(data) {
			$("#newsListTabContent").html(data);
	});
}

function loadContentABNP(taskName) {
	var page = $("#pageId").val();
	var section = $("#sectionId").val();
	var selectedCat = $("#selectedCategory").val();
	$("#aboutBankNewsContent").html("<img src=\"/static/img/ajax-loader.gif\" alt=\"\" id=\"loadingImageNP\" style=\"display: block; margin: 80px 0 0 160px\" />");
	$.post("/do/AboutBankNewsAction", 
		{ pageId : page, 
		  sectionId : section,
		  task: taskName, 
		  selectedCategory: selectedCat} ,
		function(data) {
			$("#aboutBankNewsContent").html(data);
	});
}


function submitCategory() {
	$.post("/do/NewsListTabAction", { pageId : $("#pageId").val(), 
									   sectionId : $("#sectionId").val(),
									   task: 'EDIT_CATEGORY', 
									   selectedCategory: $("#catSelect").val()
									   } ,
			function(data) {
				$("#newsListTabContent").html(data);
			});
}

//----------
//bankowosc
//----------

function addCanalHov(obj) {
  addBoxHov(obj);
  /*if (x = $(obj).up().previous(".panel").down(".canal"))
    x.addClassName("noBorder");*/
}

function remCanalHov(obj) {
  remBoxHov(obj);
  /*if (x = $(obj).up().previous(".panel").down(".canal"))
    x.removeClassName("noBorder");*/
}

// ----------
// main menu
// ----------

function cleanMainMenuSeparators() {
  $$(".mmNode").each(function(x) {
      if (x.hasClassName("act") && x.next()) {
        x.next().addClassName('sibling');
      }
  });
  
  if ($$(".menu4")) {
    $$(".menu4 li").each(function(x) {
      if (x.hasClassName("act") && x.previous()) {
        x.previous().addClassName('noBorder');
      }
    });
  }
}

function replaceAll(text, strA, strB)
{
    return text.replace( new RegExp(strA,"g"), strB );    
}