function winW() {
   if (window.innerWidth)
      /* NN4 a kompatibilní prohlížeče */
      return window.innerWidth;
   else if
   (document.documentElement &&
   document.documentElement.clientWidth)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerWidth */
      return document.documentElement.clientWidth;
   else if
   (document.body && document.body.clientWidth)
      /* starší MSIE + MSIE6 v quirk režimu */
      return document.body.clientWidth;
   else
      return null;      
}

function winH() {
   if (window.innerHeight)
      /* NN4 a kompatibilní prohlížeče */
      return window.innerHeight;
   else if
   (document.documentElement &&
   document.documentElement.clientHeight)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerWidth */
      return document.documentElement.clientHeight;
   else if
   (document.body && document.body.clientHeight)
      /* starší MSIE + MSIE6 v quirk režimu */
      return document.body.clientHeight;
   else
      return null;      
}

function ContactForm() {
	var contactForm = document.getElementById("contactForm");
	var pageBG = document.getElementById('page');
	var contentBG = document.getElementById('content');
	var footerBG = document.getElementById('footer');
	
	document.getElementById('recommendBG').style.height = pageBG.offsetHeight + contentBG.offsetHeight + footerBG.offsetHeight + 'px';
	document.getElementById('recommendBG').style.display='block';
	
	document.getElementById('contactForm').style.left = (winW()/2)-250 + 'px';
	document.getElementById('contactForm').style.display='block';
	
	window.scrollTo(0, 0);
	
	
	contactForm.innerHTML += '<div id="contactFormHeader"><a href="javascript:void(0)" onclick="closeContactForm()">&nbsp;</a><span>Kontaktní formulář</span></div>'
	contactForm.innerHTML += '<div id="in_contactForm"><iframe width="400" height="250" srolling="no" id="odeslatMail" name="odeslatMail" marginheight="0" marginwidth="0" frameborder="0" src="/zeptat-se/.sendmail?layout=empty"></iframe></div>'
	
	
}

function closeContactForm() {
	var contactForm = document.getElementById("contactForm");
	
	document.getElementById('recommendBG').style.display='none';
	document.getElementById('contactForm').style.display='none';
	
	contactForm.innerHTML = '';
}







var g_RegExpSupported = 0;
if(window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if(tempReg.test(tempStr)) 
	g_RegExpSupported = 1;
}


function validate(id, sendinfo) {
	//sendinfo určuje jestli je kontrola volaná z "Napište nám"
	if (sendinfo==1) {
		var SubmitForm = document.getElementById('contactFormButton')
	} else {
		var SubmitForm = document.getElementById('contactFormButton')
	}
	
	if (id == 1) {
		document.getElementById('validateFirst').className = 'green';
		document.getElementById('validateFirst').innerHTML = '<span class="green"></span>';
		
		var str = document.getElementById('sEmailFormAcceptor').value;
		
		if(!g_RegExpSupported){
			if(!(str.indexOf(".") >= 2) && (str.indexOf("@") > 0))
			{
				document.getElementById('validateFirst').className = 'red';
				document.getElementById('validateFirst').innerHTML = '<span class="red">Zadali jste špatně e-mail!</span>';
			}	
		} else	{	
			var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
			var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5}|[0-9]{1,3})(\\]?)$");
			
			if(!(!r1.test(str) && r2.test(str)))
			{
				document.getElementById('validateFirst').className = 'red';
				document.getElementById('validateFirst').innerHTML = '<span class="red">Zadali jste špatně e-mail!</span>';
			}
		}
		
	} else if (id == 2) {
		document.getElementById('validateSecond').className = 'green';
		document.getElementById('validateSecond').innerHTML = '<span class="green"></span>';
		
		var str = document.getElementById('sEmailForm').value;
		
		if(!g_RegExpSupported){
			if(!(str.indexOf(".") >= 2) && (str.indexOf("@") > 0))
			{
				document.getElementById('validateSecond').className = 'red';
				document.getElementById('validateSecond').innerHTML = '<span class="red">Zadali jste špatně e-mail!</span>';
			}	
		} else	{	
			var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
			var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5}|[0-9]{1,3})(\\]?)$");
			
			if(!(!r1.test(str) && r2.test(str)))
			{
				document.getElementById('validateSecond').className = 'red';
				document.getElementById('validateSecond').innerHTML = '<span class="red">Zadali jste špatně e-mail!</span>';
			}
		}		
	} else if (id == 3) {
		if (document.getElementById('sText').value == '') {
		
		} else {
			
		}
	}
	
	//kontrola když není nic zadané
	if (document.getElementById('sEmailFormAcceptor').value == '') {
		var validateFirstIf = 'red';		
	} else {
		var validateFirstIf = document.getElementById('validateFirst').className;
	}
	
	if (sendinfo==0) {
		if (document.getElementById('sEmailForm').value == '') {
			var validateSecondIf = 'red';		
		} else {
			var validateSecondIf = document.getElementById('validateSecond').className;
		}	
	} else {
		var validateSecondIf = 'green'
	}
	
	var textAreaIf = document.getElementById('sText').value;
	
	if (validateFirstIf == 'red' || validateSecondIf == 'red' || textAreaIf == '') {
		SubmitForm.className = 'disabled';
		SubmitForm.disabled = true;
	} else if (validateFirstIf == 'green' && validateSecondIf == 'green' && textAreaIf != '') {
		SubmitForm.className = '';
		SubmitForm.disabled = false;
	}
	

}
