
var ALERT_BUTTON_TEXT = "Ok";
var ALERT_BUTTON_TEXT_OK = "Ok";
var ALERT_BUTTON_TEXT_CANCEL = "Anuluj";

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
/*
if(document.getElementById) {
	window.alert = function(txt) {
		createCustomAlert(txt);
	}
	
}
*/

function createContent(d, obj, txt){
    msg = obj.appendChild(d.createElement("div"));
    msg.id = 'divAlert';
    d.getElementById('divAlert').innerHTML = txt;
}

function showHideCalendars(dis){
    var newC = d.getElementById("newKalendarz");
	var editC = d.getElementById("editKalendarz");
	var contact = d.getElementById("contactSelect");
	if (newC != null){
	   newC.style.display = dis;
	}
	if (editC != null){
	   editC.style.display = dis;
	}
	if (contact != null){
	   contact.style.display = dis;
	}
}

function okAction(form){
    if (form != "") {
	    document.getElementById(form).submit();
	  }
	  showHideCalendars("block");
	  removeCustomConfirm();
	  return true; 
}
function cancelAction(form){
      if (form != "") {
	    document.getElementById(form).submit();
	  } 
	  showHideCalendars("block");
	  removeCustomConfirm();
	  return false;
}

function customConfirm(formOk, formCancel, txt, okB, cancelB, w, h) {
    d = document;
	if(d.getElementById("modalContainer1")) return;
	
	showHideCalendars("none");
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer1";
	mObj.style.height = document.documentElement.scrollHeight + "px";
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "confirmBox";
	alertObj.style.height = h;
    alertObj.style.width = w;
    if (h == "auto") h = 100;
    if (w == "auto") w = 400;
    var top = ((findHeight()-h)/2) + "px";     
    var left = ((findWidth()-w)/2) + "px";  
    alertObj.style.top = top;
    alertObj.style.left = left;
    
	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(CONFIRM_TITLE));

	createContent(d, alertObj, txt);
	
//	buttons = alertObj.appendChild(d.createElement("div"));
 //   buttons.id = 'buttons';
    var table = "<br /><br /><center><table><tr><td><input type='button' id='okBtn' onclick='okAction(\"" + formOk + "\");' value='" + okB + "' />";
    table += "</td><td><input type='button' id='cancelBtn' onclick='cancelAction(\"" + formCancel + "\");' value='" + cancelB + "' />";
    table += "</td></tr></table></center>";
    d.getElementById('divAlert').innerHTML += table;
	
/*	table = alertObj.appendChild(d.createElement("table"));
	tblBody = d.createElement("tbody");
    row = d.createElement("tr");
    cell1 = d.createElement("td");
	btn1 = cell1.appendChild(d.createElement("a"));
	btn1.id = "okBtn";
	btn1.appendChild(d.createTextNode(okB));
	btn1.href = "#";
	btn1.onclick = function() { 
	  if (formOk != "") {
	    document.getElementById(formOk).submit();
	  }
	  showHideCalendars("block");
	  removeCustomConfirm();
	  return true; 
	}
	row.appendChild(cell1);
	cell2 = d.createElement("td");
	btn2 = cell2.appendChild(d.createElement("a"));
	btn2.id = "cancelBtn";
	btn2.appendChild(d.createTextNode(cancelB));
	btn2.href = "#";
	btn2.onclick = function() { 
	  if (formCancel != "") {
	   // doWait(document.getElementById(formCancel));
	    document.getElementById(formCancel).submit();
	  } 
	  showHideCalendars("block");
	  removeCustomConfirm();
	  return false; }
	row.appendChild(cell2);
	tblBody.appendChild(row);
	table.appendChild(tblBody);
	cell1.setAttribute("align", "center");
	cell2.setAttribute("align", "center");
	btn1.setAttribute("style", "width:80px");
	btn2.setAttribute("style", "width:80px");*/
}


function findHeight(){
   var myHeight = 0;
   if( typeof( window.innerWidth ) == 'number' ) {    //Non-IE     
          myHeight = window.innerHeight;  
   } else if( document.documentElement &&      
           ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {    //IE 6+ in 'standards compliant mode'       
          myHeight = document.documentElement.clientHeight;  
   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {    //IE 4 compatible       
          myHeight = document.body.clientHeight;  
   }
   return myHeight;
}

function findWidth(){
   var myWidth = 0;
   if( typeof( window.innerWidth ) == 'number' ) {    //Non-IE    
          myWidth = window.innerWidth;    
   } else if( document.documentElement &&      
           ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {    //IE 6+ in 'standards compliant mode'    
          myWidth = document.documentElement.clientWidth;    
   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {    //IE 4 compatible    
          myWidth = document.body.clientWidth;    
   }
   return myWidth;
}

function createCustomAlert(txt, w, h) {
   createCustomAlert(txt, false, w, h);
}

function createCustomAlert(txt, form, w, h) {
    d = document;
	if(d.getElementById("modalContainer")) return;
	showHideCalendars("none");
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	mObj.style.height = document.documentElement.scrollHeight + "px";
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	alertObj.style.height = h;
    alertObj.style.width = w;
    if (h == "auto") h = 100;
    if (w == "auto") w = 400;
    var top = ((findHeight()-h)/2) + "px";     
    var left = ((findWidth()-w)/2) + "px";  
    alertObj.style.top = top;
    alertObj.style.left = left;
    
	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	createContent(d, alertObj, txt);

	// create an anchor element to use as the confirmation button.
	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "#";
	// set up the onclick event to remove the alert when the anchor is clicked
	btn.onclick = function() { if (form) document.getElementById('okForm').submit();showHideCalendars("block");removeCustomAlert();return false; }
}

function createHelpAlert(txt, w, h) {
    d = document;
	if(d.getElementById("modalContainer3")) return;
	showHideCalendars("none");
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer3";
	mObj.style.height = document.documentElement.scrollHeight + "px";
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "helpBox";
    alertObj.style.height = h;
    alertObj.style.width = w;
    if (h == "auto") h = 100;
    if (w == "auto") w = 400;
    var top = ((findHeight()-h)/2) + "px";     
    var left = ((findWidth()-w)/2) + "px"; 
    alertObj.style.top = top;
    alertObj.style.left = left;
    
	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode("Pomoc"));

	createContent(d, alertObj, txt);

	// create an anchor element to use as the confirmation button.
	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "#";
	// set up the onclick event to remove the alert when the anchor is clicked
	btn.onclick = function() {removeCustomAlert3();showHideCalendars("block");return false; }
}

function removeCustomAlert3() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer3"));
}

function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}

function removeCustomConfirm() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer1"));
}

function removeCustomConfirm1() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer2"));
}
