/****************************************************************************

 *  webfunctions.js                                                         *

 *  Author: Rafał Dyktorowski                                               *

 * Contact: 508 436 437                                                     *

 * **************************************************************************/  



function gotourl(link)

{ 

  window.location = link;

}



function confirmandgo(msg, URL)

{

  if (confirm(msg))

  {

    gotourl(URL);

  }

}



function informacja(msg)

{

  alert(msg);

}



function show_combo(ObjId) 

{ 

  if (document.getElementById(ObjId).style.visibility=="visible") return;

  document.getElementById(ObjId).style.visibility = "visible";

}



function hide_combo(ObjId)

{

  document.getElementById(ObjId).style.visibility = "hidden";

}



function help(name){

	var newWin= window.open('help/'+name+'.html', 'Pomoc', "menubar=no,location=no,resizable=yes,scrollbars=no,status=no,width=500,height=250");

}



function $(name){

	return document.getElementById(name);

}



function getSize(rodzaj) {

  var myWidth = 0, myHeight = 0;

  if( typeof( window.innerWidth ) == 'number' ) {

    //Non-IE

    myWidth = window.innerWidth;

    myHeight = window.innerHeight;

  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    //IE 6+ in 'standards compliant mode'

    myWidth = document.documentElement.clientWidth;

    myHeight = document.documentElement.clientHeight;

  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    //IE 4 compatible

    myWidth = document.body.clientWidth;

    myHeight = document.body.clientHeight;

  }

  if(rodzaj){return myWidth;} else {return myHeight;}; 

}

function showLoginForm(){

	var doc = $('GastronaLoginForm');

	var myTop = 400;

	var myLeft = (getSize(true) / 2) + 200;

	doc.style.display = "block";

	doc.style.position = "absolute";

	doc.style.top = myTop+"px";

	doc.style.left = myLeft+"px"; 

	

}



function hideLoginForm(){

	$('GastronaLoginForm').style.display = "none";

}



function objToAlert(obj){

	var t = '';

	for(var i in obj){

		t += i+' = '+obj[i]+"\t";

	}

	alert(t);

}



function LogMe(){

	login = $('form_log').value;

	haslo = $('form_pass').value;

	advAJAX.post({

		url : "api/HPLogin.php",

		parameters : {

				"haslo": haslo,

				"login": login

		},

				

		onSuccess : FillForm,

    onError : loginError,

    onInitialization: disableForm

			});

}



function FillForm(obj){

	var xml = obj.responseXML;

	var oNode = xml.firstChild;

	var User = new Array();

 	XMLtoArr(oNode, User);

 	if(User['loged'] == 1){

 		$('GastronaLoginForm').innerHTML = '';

	} else {

		alert('Logowanie nie powiodło się. Proszę spróbować za chwilę.');

		alert(obj.responseText);

		$('logMe').value = ' Zaloguj ';

		$('logMe').disabled = false;

	}

}



function loginError(obj){

	$('logMe').disabled = false;

	$('logMe').value = ' Zaloguj ';

}



function disableForm(){

	$('logMe').disabled = true;

	$('logMe').value = 'Logowanie...';

} 



function XMLtoArr(oNode, aList, sNodeName){

 

	if(oNode == null) return;

	if(oNode.nodeType == 3){

  		aList[sNodeName] = oNode.nodeValue;

 	} else if(oNode.nodeType == 1){

  	XMLtoArr(oNode.firstChild, aList, oNode.nodeName);

 	}

 	

 	if(oNode.nextSibling != null){

  	XMLtoArr(oNode.nextSibling, aList, oNode.nodeName);

 	}

}

function galleryPopUp(URL, w, h){
   var win = window.open(URL,'Galeria','width='+w+',height='+h+',resizeable=no,scrollbars=no,toolbar=no,status=no');
}

function openPrint(URL){
	//'width='+w+',height='+h+',
	var win = window.open(URL,'Drukuj','toolbar=no,status=no,resizeable=yes,scrollbars=yes');
}

