var myPromoTick;

function pokaz(ref) {
	if (ref) document.getElementById(ref).style.display = 'block';	
}

function ukryj(ref) {
	if (ref) document.getElementById(ref).style.display = 'none';	
}

function nS(user,domain) {
         locationstring = "mailto:" + user + "@" + domain;
         window.location = locationstring;
} 


 if(typeof HTMLElement!='undefined'&&!HTMLElement.prototype.click)
    HTMLElement.prototype.click=function()
    {
        var evt = this.ownerDocument.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
        this.dispatchEvent(evt);
    }

    
function klik(id) {
		
	  document.getElementById(id).click();
	  
}

function runCom(id) {
	  	  
	  setTimeout("document.getElementById('"+id+"').click()", 500);
	  
}
    
function closeRokbox() {
    window.parent.window.klik('rokbox-overlay');
}

function addStyle(el, s){
  if(typeof(el) == 'string'){el = document.getElementById(el);}
  var st = s.split(';');
  for(var i=0; i<st.length; i++){
    var stl = st[i].split(':');
    if(stl.length == 2){
      stl[0] = stl[0].replace(/^\s*|\s*$/g,"");
      stl[1] = stl[1].replace(/^\s*|\s*$/g,"");
      stl[1] = stl[1].replace(/'/g, "\"");
      tmpStl = stl[0].split('-');
      stl[0] = tmpStl[0];
      for(var j=1; j < tmpStl.length; j++){
        stl[0] += tmpStl[j].charAt(0).toUpperCase() + tmpStl[j].substr(1).toLowerCase();
      }
      delete tmpStl;
      if(stl[0].length > 3){eval('el.style.' + stl[0] + ' = \'' + stl[1] + '\';');}
    }
  }
  return false;
}

function getH(divID) {

				var docH = document.getElementById(divID).clientHeight;			
				return(docH);
}

function getmail() {
   
   	var alertMessage = '';
   
    if (!document.getElementById("title").value) { alertMessage = alertMessage + 'Proszę podać tytuł wiadomości. '; }
    if (!document.getElementById("message").value) { alertMessage = alertMessage + 'Proszę podać źródło informacji o naszej firmie. '; }  
    if (!document.getElementById("from").value) { alertMessage = alertMessage + 'Proszę podać imię i nazwisko. '; } 
    if (!document.getElementById("email").value) { alertMessage = alertMessage + 'Proszę podać adres e-mail. '; } 
   
   	if (alertMessage == '') {
   						get(document.getElementById('contactForm'));
						pokaz('contactPrelo'); 
						ukryj('contactForm');
	}
	else alert(alertMessage);
   }
   
function switchPromo (n, nazwa, foto, url) {

	var myID = 'promoSwitch';
	
	styl = 'background-color: #CF0000;';
	reset = 'background: none;';	
	
	clearTimeout(myPromoTick); 
	
	for (v = 1; v <= 20; v++) {
		if (document.getElementById('sw'+v)) 
		addStyle('sw'+v, reset);	
	}
	
	addStyle('sw'+n, styl);	
		
	cnt = '<div class="inPromo" style="background-image: url(\''+foto+'\');" title="'+nazwa+'" onclick="goto(\''+url+'\');"><h2><a href="'+url+'" title="'+nazwa+'">'+nazwa+'</a></h2></div>';
    document.getElementById(myID).innerHTML = cnt;
    
} 
  
function goto(url) {
	window.location=url;	
}

function tickPromos(n) {

	ask = 'promo'+n;
	styl = 'background-color: #CF0000;';
	reset = 'background: none;';

	if (document.getElementById(ask)) {
	klik('sw'+n);	
		
	}
	else {
	
	n = 1;
	klik('sw'+n);	
	
	}
	
	for (v = 1; v <= 20; v++) {
		if (document.getElementById('sw'+v)) 
		addStyle('sw'+v, reset);	
	}
	
	addStyle('sw'+n, styl);
	
	n++;	

 	myPromoTick = setTimeout("tickPromos("+n+")", 5000);
}

function unTickPromos() {
	clearTimeout(myPromoTick); 		
}

function preloadNews() {
	ukryj('newsSubs');
	pokaz('newsPrelo');
}


function mark(myID, myVal) {

	var sondaID = 'sonda'+myID;
	
	ukryj('sondaContent'+myID);
	pokaz('prelo'+myID);
	
	ajaxpage('ajax/vote.php?'+myID+','+myVal, sondaID);

}

function setDate(pole, wartosc, tresc) {

	window.parent.window.document.getElementById(pole).value = wartosc;
	window.parent.window.document.getElementById(pole+'Label').innerHTML = tresc;
	closeRokbox();	
}

function debug(data) {
	
	if (document.getElementById('debug')) {
		pokaz('debug');
		document.getElementById('debug').innerHTML=data;
	}
}

function ai(id, fraza) {

	if (document.getElementById(id).value == fraza)
	document.getElementById(id).value = '';
	
	document.getElementById(id).style.color='#37353d';
}

function di(id, fraza) {
	if (document.getElementById(id).value == '') {
	document.getElementById(id).value = fraza;
	document.getElementById(id).style.color='#6d6d6d';
	}
}

function validateClientLoginForm() {
	
	if (document.getElementById('username').value == '' || 
		document.getElementById('password').value == '' ||
		document.getElementById('username').value == 'wpisz login') {
		
		klik('correctLoginForm');
		return false;
	}
		
		else   {
	
		return true
		}
		
}

function setEmot(insertForm, emot) {
	
	insertAtCursor(window.parent.window.document[insertForm].tresc, ' '+emot+' ');
	
	closeRokbox();
	
}

function insertAtCursor(myField, myValue) {

	//IE support

	if (document.selection) {

		myField.focus();

		sel = document.selection.createRange();

		sel.text = myValue;

	}

	//MOZILLA/NETSCAPE support

	else if (myField.selectionStart || myField.selectionStart == '0') {

		var startPos = myField.selectionStart;

		var endPos = myField.selectionEnd;

		myField.value = myField.value.substring(0, startPos)

		+ myValue + myField.value.substring(endPos, myField.value.length);

	} else {

		myField.value += myValue;

	}

}

