var kolorramki = '#FF0000';
var kolortla = '#FFFFFF';
var kolorczcionki = '#FF0000';
var kolorramkioryg = '#FF9900';
var kolortlaoryg = '#FFFF66';
var kolorczcionkioryg = '#000000';
var globalfocus = '';
var testimg = '0';
spe=500;
swi = 1;

function ustawfocusglobal(elemt) {
globalfocus = elemt;
}

function wyczyscrok() {
	var elrok = document.getElementById("year");
	if (elrok.value == 'Year')
	   {
			elrok.value = '';
	   }

}


function button(color)
{
    var elsteep23 = document.getElementById("przycisk");
	elsteep23.style.backgroundColor=color;
} // end func

function steep2() {
	var elsteep23 = document.getElementById("notice");
	elsteep23.style.color='white';

}

function steep3() {
	var elsteep2 = document.getElementById("table3");
	elsteep2.style.display='block';
}

function steep4() {
	
	var elsteep3 = document.getElementById("table4");
	
	if (document.getElementById("year").value.length > 3)
	   {
			elsteep3.style.display='block';
	   }
}


function zmien(nazwaelemntu) {
	
	document.getElementById(nazwaelemntu).style.borderColor=kolorramki;
	document.getElementById(nazwaelemntu).style.backgroundColor=kolortla;
	document.getElementById(nazwaelemntu).style.color=kolorczcionki;

	
}

function zamrugaj(nazwaelemntu) {
	return false;
}


function zmienoryg(nazwaelemntu) {
	
	if (nazwaelemntu != globalfocus)
	   {
			document.getElementById(nazwaelemntu).style.borderColor=kolorramkioryg;
			document.getElementById(nazwaelemntu).style.backgroundColor=kolortlaoryg;
			document.getElementById(nazwaelemntu).style.color=kolorczcionkioryg;
			if (document.getElementById('year').value == '' && document.getElementById('page').value == '1')
			   {
					document.getElementById('year').value = 'Year';
			   }

	   }
	
}


function blinkExecute(target,color){
  document.getElementById(target).style.backgroundColor = color;
}

function blinkBlink (target){
  color1 = "#FF0000"; // blinking color
  color2 = "#ffffff"; // background color
  setTimeout('blinkExecute("'+target+'","'+color1+'")',0);
  setTimeout('blinkExecute("'+target+'","'+color2+'")',180);
  setTimeout('blinkExecute("'+target+'","'+color1+'")',360);
  setTimeout('blinkExecute("'+target+'","'+color2+'")',540);             
  setTimeout('blinkExecute("'+target+'","'+color1+'")',720);
  setTimeout('blinkExecute("'+target+'","'+color2+'")',900);
  //document.getElementById(target).focus();
}

function blinkramka (target){
  color1 = "#FF0000"; // blinking color
  color2 = "#3A0500"; // background color
  setTimeout('blinkExecuteramka("'+target+'","'+color1+'")',0);
  setTimeout('blinkExecuteramka("'+target+'","'+color2+'")',180);
  setTimeout('blinkExecuteramka("'+target+'","'+color1+'")',360);
  setTimeout('blinkExecuteramka("'+target+'","'+color2+'")',540);             
  setTimeout('blinkExecuteramka("'+target+'","'+color1+'")',720);
  setTimeout('blinkExecuteramka("'+target+'","'+color2+'")',900);
  //document.getElementById(target).focus();
}

function blinkExecuteramka(target,color){
  document.getElementById(target).style.borderColor = color;
}


function mrugaj(elemntid) {

if (swi == 1) {
sho="#FF0000";
swi=0;
}
else {
sho="#FF9900";
swi=1;
}

for(i=0;i<20;i++) {
document.getElementById(nazwaelemntu).style.borderColor=sho;
}

setTimeout("bringBackBlinky()", spe);
}
function valid2() {
	

	var t = document.formik;
	//alert ("jestem w valid2");


	 if(!/^[a-z][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/i.test(t.femail1.value) && t.femail1.lenght > 0){
		  alert('Enter correct email address first friend\'s email!');
		  t.femail1.focus();
		  blinkBlink('femail1');
		  return false;
		}

	 if(t.femail1.lenght > 0 && t.fname1.lenght){
		  alert('Enter first friens\'s name!');
		  t.fname1.focus();
		  blinkBlink('fname1');
		  return false;
		}

	 if(!/^[a-z][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/i.test(t.femail2.value) && t.femail2.lenght > 0){
		  alert('Enter correct email address second friend\'s email!');
		  t.femail2.focus();
		  blinkBlink('femail2');
		  return false;
		}

	 if(t.femail2.lenght > 0 && t.fname2.lenght){
		  alert('Enter second friens\'s name!');
		  t.fname2.focus();
		  blinkBlink('fname2');
		  return false;
		}

	rstatusidx = document.getElementById("rstatus").selectedIndex;
	rstatusvalue = document.getElementById("rstatus").options[rstatusidx].value;
	if (rstatusvalue == 0)
	{
			alert('Please select your residental status.');
			t.rstatus.focus();
			blinkramka('rstatus');
			return false;
	}
	
	estatusidx = document.getElementById("estatus").selectedIndex;
	estatusvalue = document.getElementById("estatus").options[estatusidx].value;
	if (estatusvalue == 0)
	{
			alert('Please select your employment status.');
			t.estatus.focus();
			blinkramka('estatus');
			return false;
	}
	
	aincomeidx = document.getElementById("aincome").selectedIndex;
	aincomevalue = document.getElementById("aincome").options[aincomeidx].value;
	if (aincomevalue == 0)
	{
			alert('Please select your annual household income.');
			t.aincome.focus();
			blinkramka('aincome');
			return false;
	}
	maritalidx = document.getElementById("marital").selectedIndex;
	maritalvalue = document.getElementById("marital").options[maritalidx].value;
	if (maritalvalue == 0)
	{
			alert('Please select your marital status.');
			t.aincome.focus();
			blinkramka('marital');
			return false;
	}
	nchildrenidx = document.getElementById("nchildren").selectedIndex;
	nchildrenvalue = document.getElementById("nchildren").options[nchildrenidx].value;
	if (nchildrenvalue == 0)
	{
			alert('Please select number of children.');
			t.nchildren.focus();
			blinkramka('nchildren');
			return false;
	}

	if(t.femail1.value.length > 0 && !/^[a-z][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/i.test(t.femail1.value))
		{
			alert("Enter correct first friend's email address!");
			t.femail1.focus();
			blinkramka('femail1');
			return false;
		}

	if(t.femail12.value.length > 0 && !/^[a-z][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/i.test(t.femail2.value))
		{
			alert("Enter correct second friend's email address!");
			t.femail2.focus();
			blinkramka('femail2');
			return false;
		}



}
function valid() {
	
	var t = document.formik;
	if(t.elements['what'][0].checked==false && t.elements['what'][1].checked==false)
		{
		alert("Please select your prize!");
		blinkramka('firsttable');
		return false;
		}

	if(t.fname.value=="") {
	alert("Please enter your name!");
	t.fname.focus();
	blinkBlink('fname');
	return false;
	}
	
	if(t.lname.value=="") {
	alert("Please enter your last name!");
	t.lname.focus();
	blinkBlink('lname');
	return false;
	}
	
	if(t.address.value=="") {
	alert("Please enter your address!");
	t.address.focus();
	blinkBlink('address');
	return false;
	}

	if(t.zip.value=="") {
	alert("Please enter your post code!");
	t.zip.focus();
	blinkBlink('zip');
	return false;
	}

	if(t.city.value=="") {
	alert("Please enter your city!");
	t.city.focus();
	blinkBlink('city');
	return false;
	}
	
	if(t.day.value==0) {
	alert("Please select date of birth!");
	t.day.focus();
	blinkBlink('day');
	return false;
	}
	
	if(t.month.value==0) {
	alert("Please select date of birth!");
	t.month.focus();
	blinkBlink('month');
	return false;
	}

	if(t.year.value=='Year') {
	alert("Please select date of birth!");
	t.year.focus();
	blinkBlink('year');
	return false;
	}
	
	if(t.gender.value == 0) {
	alert("Please select your gender!");
	t.gender.focus();
	blinkBlink('gender');
	return false;
	}

	 if(!/^[a-z][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/i.test(t.email.value)){
		  alert('Enter correct email address!');
		  t.email.focus();
		  blinkBlink('email');
		  return false;
		}

	if(t.email.value != t.email2.value) {
	alert("Your email does not match!");
	t.email.focus();
	blinkBlink('email2');
	return false;
	}

	if(t.emailindb.value==1) {
	alert("This email address already exists in our database. Please try again with different email address.");
	t.email.focus();
	return false;
	}

	if(t.quest1.checked==false) {
	alert("Please agree to Prize Draw Rules and Privacy Policy!");
	t.quest1.focus();
	return false;
	}

	if(t.quest2.checked==false) {
	alert("Please agree to our partner T&C's. However if you prefer not to agree you can't enter our competition.");
	t.quest2.focus();
	return false;
	}

	if(t.konkurs.checked==false) 
	{
	alert("Please agree to our partner T&C's. However if you prefer not to agree you can't enter our competition.");
	t.konkurs.focus();
	return false;
	}

}
function liczby(x){ 
x.value=x.value.replace(/\D/g,'') 
}

function pokaz(elementID)
{
var t = document.formik;
var el = document.getElementById(elementID);
//alert("testimg:" + testimg);
if (testimg == '0')
   {
				el.style.display='block';
				testimg = '1';
   }
if((t.email.value == t.email2.value) && (t.email.value != ''))
	{
		el.src="images/tick-yes.gif";

	} 
else 
	{
		el.src="images/tick-no.gif";
	}
}


function calculatedateofbirth() 
{
month = document.getElementById("month").selectedIndex;
month = document.getElementById("month").options[month].value;
day = document.getElementById("day").value;
year = document.getElementById("year").value;
//alert ("test: " + day + " " + month + " " + year );

var monthname = new Array(12);
monthname[1]="January";
monthname[2]="February";
monthname[3]="March";
monthname[4]="April";
monthname[5]="May";
monthname[6]="June";
monthname[7]="July";
monthname[8]="August";
monthname[9]="September";
monthname[10]="October";
monthname[11]="November";
monthname[12]="December";


if (month > 0 && day > 0 && document.getElementById("year").value.length == 4)
   {
				month = monthname[month];
				var oyear=year
				var dob = " "+ year +", "+month + ",  "+day;
				var thenx = new Date(dob);
				var year=thenx.getYear();
				if (year<100) year="19" + thenx.getYear();
				else year=thenx.getYear();
				if (year > 1969) wyear=year;
				else {
				if (oyear<1900) {
				if (oyear>1800) {
				wrelyear= (eval(oyear)-1801)%(28);
				wyear = wrelyear+1981;
				}
				else wyear = 1970 
				}
				else
				if (oyear>1900) {wrelyear= (eval(oyear)-1901)%(28); 
				wyear= wrelyear+1985
				}
				else 
				if (oyear==1900) {wyear= 1990;
				   }              
				}
				var dob = " "+ wyear +", "+month + ",  "+day;
				var thenx = new Date(dob);

				var theday = thenx.getDay()+1;
				var date=thenx.getDate();

				var weekday = new Array(6);
				weekday[1]="Sunday";
				weekday[2]="Monday";
				weekday[3]="Tuesday";
				weekday[4]="Wednesday";
				weekday[5]="Thursday";
				weekday[6]="Friday";
				weekday[7]="Saturday";
				if (day != date){
					//alert("Sorry!  That appears to be an invalid date!"+day+" ..."+date+"::"+oyear+"..."+year+" "+dob+"=="+wyear+".-.-"+thenx+" "+day+" "+month);
				}
				else {
				dayborn = weekday[theday];
				//dob = dayborn;
				//alert("You were born on " + dayborn);

				var strborn = "You were born on " + dayborn;
				document.getElementById('dataurodzin').innerHTML = strborn;
				document.getElementById('dataurodzin').style.display = 'block';

			}
	   }

}


