function $(id) {
     return document.getElementById(id);
}

function showDiv(id)	{
	
	if(id != '')	{
		
		var d = "div_"+id;
	
		var current = (document.getElementById(d).style.display == 'none') ? 'block' : 'none';		
		document.getElementById(d).style.display = current;
	}
	return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function openWindow(str,features){
        window.name='windowOpener';
        window.open(str,'newWindow',features);
}
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=1,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpWindowNS(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=0,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function changeClientType(id)	{
	if(id == '1')	{
		
		$("client_firm").value = '';
		$("client_firm").disabled = true;
		
		$("client_number_nip").value = '';
		$("client_number_nip").disabled = true;
		
		$('client_invoice').checked = false;
		$("client_invoice").disabled = true;
		
	}	else if(id == '2')	{
		
		$("client_firm").disabled = false;
		$("client_number_nip").disabled = false;
		$("client_invoice").disabled = false;
	}
	
}
function CheckSignInForm() {
	
	var login = $("client_login").value;
	var subdomain = $("client_subdomain").value;
	var zapytanie = "ajax.function.php?oppType=ValidateAddForm&username="+login+"&subdomain="+subdomain;
	
	if($("service_id").value == "")	{
		alert("Prosimy wybrać rodzaj serwera.");
		$("service_id").style.border = '1px solid #FF0000';
		$("service_id").focus();
		return false;
	}	else	{
		$("service_id").style.border = '1px solid #CCCCCC';
	}
	
	if($("payment_id").value == "")	{
		alert("Prosimy wybrać okres abonametu.");
		$("payment_id").style.border = '1px solid #FF0000';
		$("payment_id").focus();
		return false;
	}	else	{
		$("payment_id").style.border = '1px solid #CCCCCC';
	}
	
	if($("client_login").value == "" || $("client_login").value.length < 3 || $("client_login").value.length > 8)	{
		alert("Prosimy podać login. Długość loginu nie powinna być mniejsza niż trzy znaki i większa niż osiem.");
		$("client_login").style.border = '1px solid #FF0000';
		$("client_login").focus();
		return false;
	}	else	{
		$("client_login").style.border = '1px solid #CCCCCC';
	}
	
	var nickRegExp = /^[A-Za-z0-9\-\_]+$/;
	
	if(!nickRegExp.test($("client_login").value))	{
		alert("Twój login nie może zawierać polskich znaków fonetycznych oraz znaków specjalnych.");
		$("client_login").style.border = '1px solid #FF0000';
		$("client_login").focus();
		return false;
	}	else	{
		$("client_login").style.border = '1px solid #CCCCCC';
	}

	if($("client_passwd").value == "" || $("client_passwd").value.length < 5)	{
		alert("Prosimy podać hasło! Długość hasła nie powinna być mniejsza niż pięć znaków.");
		$("client_passwd").style.border = '1px solid #FF0000';
		$("client_passwd").focus();
		return false;
	}	else	{
		$("client_passwd").style.border = '1px solid #CCCCCC';
	}
	
	var passRegExp = /^[A-Za-z0-9\-\_]+$/;
	
	if(!passRegExp.test($("client_passwd").value))	{
		alert("Twoje hasło nie może zawierać polskich znaków fonetycznych oraz znaków specjalnych.");
		$("client_passwd").style.border = '1px solid #FF0000';
		$("client_passwd").focus();		
		return false;
	}	else	{
		$("client_passwd").style.border = '1px solid #CCCCCC';
	}

	if($("client_passwd2").value == "")	{
		alert("Prosimy podać potwierdznie hasła.");
		$("client_passwd2").style.border = '1px solid #FF0000';
		$("client_passwd2").focus();
		return false;
	}	else	{
		$("client_passwd2").style.border = '1px solid #CCCCCC';
	}

	if($("client_passwd").value != $("client_passwd2").value)	{
		alert("Pola hasła i potwierdzenia muszą być takie same!");
		$("client_passwd").style.border = '1px solid #FF0000';
		$("client_passwd2").style.border = '1px solid #FF0000';
		return false;
	}	else	{
		$("client_passwd").style.border = '1px solid #CCCCCC';
		$("client_passwd2").style.border = '1px solid #CCCCCC';
	}
	
	if($("client_subdomain").value == "" || $("client_subdomain").value.length < 3)	{
		alert("Prosimy podać nazwę subdomeny. Długość subdomeny nie powinna być mniejsza niż trzy znaki.");
		$("client_subdomain").style.border = '1px solid #FF0000';
		$("client_subdomain").focus();
		return false;
	}	else	{
		$("client_subdomain").style.border = '1px solid #CCCCCC';
	}
	
	if($("client_firstname").value == "" || $("client_firstname").value.length < 2)	{
		alert("Prosimy podać imię.");
		$("client_firstname").style.border = '1px solid #FF0000';
		$("client_firstname").focus();
		return false;
	}	else	{
		$("client_firstname").style.border = '1px solid #CCCCCC';
	}
	
	if($("client_lastname").value == "" || $("client_lastname").value.length < 2)	{
		alert("Prosimy podać nazwisko.");
		$("client_lastname").style.border = '1px solid #FF0000';
		$("client_lastname").focus();
		return false;
	}	else	{
		$("client_lastname").style.border = '1px solid #CCCCCC';
	}
		
	if($("client_street").value == "" || $("client_street").value.length < 2)	{
		alert("Prosimy podać ulicę i numer.");
		$("client_street").style.border = '1px solid #FF0000';
		$("client_street").focus();
		return false;
	}	else	{
		$("client_street").style.border = '1px solid #CCCCCC';
	}
	
	if($("client_zipcode").value == "" || $("client_zipcode").value.length < 2)	{
		alert("Prosimy podać kod pocztowy.");
		$("client_zipcode").style.border = '1px solid #FF0000';
		$("client_zipcode").focus();
		return false;
	}	else	{
		$("client_zipcode").style.border = '1px solid #CCCCCC';
	}
	
	if($("client_city").value == "" || $("client_city").value.length < 2)	{
		alert("Prosimy podać miejscowość.");
		$("client_city").style.border = '1px solid #FF0000';
		$("client_city").focus();
		return false;
	}	else	{
		$("client_city").style.border = '1px solid #CCCCCC';
	}
	
	/*
	if($("client_phone").value == "" || $("client_phone").value.length < 2)	{
		$("client_phone").focus();
		alert("Prosimy podać nr telefonu.");
		return false;
	}
	
	if($("client_fax").value == "" || $("client_fax").value.length < 2)	{
		$("client_fax").focus();
		alert("Prosimy podać nr faksu.");
		return false;
	}
	*/
	
	var emailRegExp = /^[A-Za-z0-9._\-]+@(([A-Za-z]\.)|([A-Za-z0-9][A-Za-z0-9\-]+\.))+[A-Za-z]+$/;
	
	if (!emailRegExp.test($("client_email").value))	{
		alert("Prosimy podać prawidłowy adres email.");
		$("client_email").style.border = '1px solid #FF0000';
		$("client_email").focus();
		return false;
	}	else	{
		$("client_email").style.border = '1px solid #CCCCCC';
	}
	
	if($('afAgree').checked == false)	{
		alert('Prosimy o wyrażenie zgody na przetwarzanie danych teleadresowych. Bez Państwa zgody realizacja zamówienia będzie niemożliwa.');
		return false;
	}
	
	/*
	if($("client_number_nip").value == "" || $("client_number_nip").value.length < 2)	{
		$("client_number_nip").focus();
		alert("Prosimy podać nr NIP.");
		return false;
	}
	*/
	
	advAJAX.get({
		url : zapytanie,
		onSuccess : function(obj) { 
		  if(obj.responseText == "UserExist") { 
			   alert("Użytkownik o takim loginie jest już w bazie danych! Prosimy wybrać inny login dla swojego konta.");
			   $("client_login").style.border = '1px solid #FF0000';
			   $("client_login").focus();
		  }
		  if(obj.responseText == "SubdomainExist") {
			   alert("Taka subdomana istnieje już w bazie danych!");
			   $("client_subdomain").style.border = '1px solid #FF0000';
			   $("client_subdomain").focus();
		  }
		  if(obj.responseText == "OK") {
			   $("SubmitButton").click();
		  }
		}
	});
	
	return true;
}

function CheckContactForm()	{
	
	
	if($("contact_name").value == "" || $("contact_name").value.length < 3)	{
		alert("Prosimy podać imię.");
		$("contact_name").style.border = '1px solid #FF0000';
		$("contact_name").focus();
		return false;
	}	else	{
		$("contact_name").style.border = '1px solid #CCCCCC';
	}
	
	var emailRegExp = /^[A-Za-z0-9._\-]+@(([A-Za-z]\.)|([A-Za-z0-9][A-Za-z0-9\-]+\.))+[A-Za-z]+$/;
	
	if (!emailRegExp.test($("contact_email").value))	{
		alert("Prosimy podać prawidłowy adres email.");
		$("contact_email").style.border = '1px solid #FF0000';
		$("contact_email").focus();
		return false;
	}	else	{
		$("contact_email").style.border = '1px solid #CCCCCC';
	}
	
	if($("contact_content").value == "" || $("contact_content").value.length < 3)	{
		alert("Prosimy podać treść wiadomości.");
		$("contact_content").style.border = '1px solid #FF0000';
		$("contact_content").focus();
		return false;
	}	else	{
		$("contact_content").style.border = '1px solid #CCCCCC';
	}
	
	return true;
}


function CheckHelpForm()	{
	
	
	if($("help_name").value == "" || $("help_name").value.length < 3)	{
		alert("Prosimy podać imię.");
		$("help_name").style.border = '1px solid #FF0000';
		$("help_name").focus();
		return false;
	}	else	{
		$("help_name").style.border = '1px solid #CCCCCC';
	}
	
	var emailRegExp = /^[A-Za-z0-9._\-]+@(([A-Za-z]\.)|([A-Za-z0-9][A-Za-z0-9\-]+\.))+[A-Za-z]+$/;
	
	if (!emailRegExp.test($("help_email").value))	{
		alert("Prosimy podać prawidłowy adres email.");
		$("help_email").style.border = '1px solid #FF0000';
		$("help_email").focus();
		return false;
	}	else	{
		$("help_email").style.border = '1px solid #CCCCCC';
	}
	
	if($("help_to").value == "")	{
		alert("Prosimy podać dział do jakiego kierowana jest wiadomość.");
		$("help_to").style.border = '1px solid #FF0000';
		$("help_to").focus();
		return false;
	}	else	{
		$("help_to").style.border = '1px solid #CCCCCC';
	}
	
	if($("help_subject").value == "" || $("help_subject").value.length < 3)	{
		alert("Prosimy podać temat wiadomości.");
		$("help_subject").style.border = '1px solid #FF0000';
		$("help_subject").focus();
		return false;
	}	else	{
		$("help_subject").style.border = '1px solid #CCCCCC';
	}
	
	if($("help_content").value == "" || $("help_content").value.length < 3)	{
		alert("Prosimy podać treść wiadomości.");
		$("help_content").style.border = '1px solid #FF0000';
		$("help_content").focus();
		return false;
	}	else	{
		$("help_content").style.border = '1px solid #CCCCCC';
	}
	
	return true;
}

function CheckDomainConfirm()	{
	
	if($('reg').checked == false)	{
		alert('Prosimy o potwierdzenie poprawności danych i akceptację regulaminu. Bez Państwa potwierdzenia realizacja zamówienia będzie niemożliwa.');
		return false;
	}
	return true;
}
