// JavaScript Document

var imgOld;
var imgName;

function winStatus(msgStr) { window.status=msgStr; }

function imgOn(name,filename){
	imgOld = document.images[name].src;
	imgName = name;
	document.images[name].src = filename;
}

function imgOff(){
	document.images[imgName].src = imgOld;
}
function imgOff2(imgName2,imgOld2){
	document.images[imgName2].src = imgOld2;
}

function hover_img(href, name, filename, ending, w, h, status_info){	
	document.write("<a href=\""+ href +"\" alt=\"\"");
	document.write(" onMouseOver=\"imgOn('"+ name +"','"+ filename +"_f2."+ ending +"'); window.status='"+ status_info +"'; return true;\"");
	document.write(" onMouseOut=\"imgOff(); window.status=''; return true;\"");
	document.write("><img src=\""+ filename +"."+ ending +"\" name=\""+ name +"\" width=\""+ w +"\" height=\""+ h +"\" border=\"0\" alt=\""+ status_info +"\"></a>");
}

function hover_imgT(href, name, filename, ending, w, h, status_info){	
	x = "";
	x += "<a href=\""+ href +"\" alt=\"\"";
	x += " onMouseOver=\"imgOn('"+ name +"','"+ filename +"_f2."+ ending +"'); window.status='"+ status_info +"'; return true;\"";
	x += " onMouseOut=\"imgOff();\"";
	x += "><img src=\""+ filename +"."+ ending +"\" name=\""+ name +"\" width=\""+ w +"\" height=\""+ h +"\" border=\"0\" alt=\""+ status_info +"\"></a>";
	return x;
}

function hover_img2(href, name, filename, filename2, w, h, status_info){	
	document.write("<a href=\""+ href +"\" alt=\"\"");
	document.write(" onMouseOver=\"imgOn('"+ name +"','"+ filename2 +"'); window.status='"+ status_info +"'; return true;\"");
	document.write(" onMouseOut=\"imgOff();\"");
	document.write("><img src=\""+ filename +"\" name=\""+ name +"\" width=\""+ w +"\" height=\""+ h +"\" border=\"0\" alt=\""+ status_info +"\"></a>");
}

var faq = 0;
var q = "";
var a = "";

function genFAQ(){
	document.writeln('<table border="0" cellspacing="0" cellpadding="0" width="552">');
	document.writeln(q);
	document.writeln('</table><br>&nbsp;<br>');
	
	document.writeln('<table border="0" cellspacing="0" cellpadding="0" width="552">');
	document.writeln(a);
	document.writeln('</table>');
}

function faqQA(question, answer){
	faq++;
	
	a += '<tr valign="top">'; 
	
	a += '	<td width="20" align="right"><a name="faqa_'+ faq +'"></a><b>'+ faq +'.</b></td>';
	a += '	<td width="5"><img src="img/pix.gif" alt="" width="5" height="1"></td>';
	a += '	<td width="510"><b>'+ question +'</b></td>';
	a += '	<td valign ="bottom" width="17">'+ hover_imgT("#top","faqatop_"+faq,"img/top","gif",17,18,"Pocz±tek strony...") +'</td>';
	
	a += '</tr><tr>';
	a += '	<td colspan="4"><img src="img/pix.gif" alt="" width="1" height="5"></td>';
	a += '</tr><tr>';
	
	a += '<td width="20"><img src="img/pix.gif" alt="" width="20" height="1"></td>';
	a += '<td colspan="3" class="lineGreen"><img src="img/pix.gif" alt="" width="20" height="1"></td>';
	a += '</tr><tr><td colspan="4"><img src="img/pix.gif" alt="" width="1" height="5"></td></tr>';
	a += '<tr valign="top">';
	
	a += '<td width="20" align="right"><img src="img/pix.gif" alt="" width="20" height="1"></td>';
	a += '<td width="5"><img src="img/pix.gif" alt="" width="5" height="1"></td>';
	a += '<td width="527" colspan="2">'+ answer +'</td>';
	
	a += '</tr><tr><td colspan="4"><img src="img/pix.gif" alt="" width="1" height="20"></td></tr>';
	
	
	
	q += '<tr valign="top">'; 
	
	q += '	<td width="20" align="right"><a name="faq_'+ faq +'"></a><b>'+ faq +'.</b></td>';
	q += '	<td width="5"><img src="img/pix.gif" alt="" width="5" height="1"></td>';
	q += '	<td width="510"><a href="#faqa_'+ faq +'" style="text-decoration: none;">'+ question +'</a></td>';
	q += '	<td valign ="bottom" width="17">'+ hover_imgT("#faqa_"+ faq,"faqqtop_"+faq,"img/next","gif",17,17,"Pocz±tek strony...") +'</td>';
	
	q += '</tr><tr>';
	q += '	<td colspan="4"><img src="img/pix.gif" alt="" width="1" height="5"></td>';
	q += '</tr><tr>';
	
	q += '<td width="20"><img src="img/pix.gif" alt="" width="20" height="1"></td>';
	q += '<td colspan="3" class="lineGreen"><img src="img/pix.gif" alt="" width="20" height="1"></td>';
	q += '</tr><tr><td colspan="4"><img src="img/pix.gif" alt="" width="1" height="20"></td></tr>';

	
}
		
function checkVar(field){
	if(field==''){
		return false
	}
	
	return true;
}

function isNumberInt(inputString)
{
  return (!isNaN(parseInt(inputString))) ? true : false;
}


function onlyCharacters(inputString)
{
  var searchForNumbers = /[^a-zA-Z0-9±¶żĽęćńłóˇ¦Ż¬ĘĆŃŁÓ\-\+\.\ \,\;\"\'\/\\\(\)]+/
  return (searchForNumbers.test(inputString)) ? false : true; 
}

function validateAddress(inputString)
{
  var searchForNumbers = /[^a-zA-Z0-9±¶żĽęćńłóˇ¦Ż¬ĘĆŃŁÓ\-\+\.\ \,\;\"\'\/\\\(\)]+/
  return (searchForNumbers.test(inputString)) ? false : true; 
}

function validatePhone(inputString)
{
  var searchForNumbers = /[^0-9\-\+\ \(\)]+/
  return (searchForNumbers.test(inputString)) ? false : true; 
}

function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
var objRegExp = /(^[a-z]([a-z0-9_\.]*)@([a-z0-9_\.]*)([.][a-z]+)$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}


function testForm(){
	kom = "Podaj ";
	temp = document.forms[0].elements['surename'].value;
	if(!(temp.length>3 && onlyCharacters(temp))){ alert(kom + 'prawidłowe imię i nazwisko.'); return false; }
	
	temp = document.forms[0].elements['city'].value;
	if(!(checkVar(temp)  && temp.length>2 && onlyCharacters(temp))){ alert(kom + 'prawidłow± miejscowo¶ć.'); return false; }
	
	temp = document.forms[0].elements['code'].value;
	if(temp!=''){
			test = 1;
			if(!isNumberInt(temp.charAt(0))) test = 0;
			if(!isNumberInt(temp.charAt(1))) test = 0;
			
			if(temp.charAt(2)!='-') test = 0;
			
			if(!isNumberInt(temp.charAt(3))) test = 0;
			if(!isNumberInt(temp.charAt(4))) test = 0;
			if(!isNumberInt(temp.charAt(5))) test = 0;
			
			if(temp.length!=6) test = 0;
			
			if(test==0){ alert(kom + 'prawidłowy kod (xx-xxx).'); return false; }
	}
	
	temp = document.forms[0].elements['address'].value;
	if(temp!=''){
			test = 1;
			
			if(temp.length<4 || !validateAddress(temp)) test = 0;
			
			if(test==0){ alert(kom + 'prawidłowy adres.'); return false; }
	}
	
	temp1 = document.forms[0].elements['telephone'].value;
	temp2 = document.forms[0].elements['mail'].value;
	
	if(temp1=='' && temp2==''){
		alert(kom + 'telefon lub e-mail.');
		return false;
	} else {
		test = 1;

		if(temp1!='' && !validatePhone(temp1)) test = 0;
		if(temp2!='' && !validateEmail(temp2)) test = 0;
		
		if(test==0){ alert(kom + 'prawidłowy telefon lub e-mail.'); return false; }
	}

}
