﻿function validate_required_text(field)
{
	with (field)
	{
		if (value == null || value == "")
			return false;
		else 
			return true;
	}
}
function validate_required_checkbox(field)
{
	with (field)
	{
		if (checked)
			return true;
		else 
			return false;
	}
}
	function AddToNotes(id, showinfo)
	{
		var array_of_id = Get_Cookie('Notes');
		if (array_of_id == null)
			array_of_id = '';
		if  (array_of_id.indexOf(id) == -1)
		{
			if (array_of_id != '')
				array_of_id += ',';
			array_of_id += '"' + id + '"';
			Set_Cookie( 'Notes', array_of_id, '100', '/', '', '' );
			if (showinfo== 'true')
				alert ('Oferta została dodana do notesu');
		}
		else
		{
				alert ('Oferta znajduje się już w notesie');
		}
	}
	function RemoveFromNotes(id)
	{
		var array_of_id = Get_Cookie('Notes');
		if (array_of_id == null)
			array_of_id = '';
		if  (array_of_id.indexOf(id) != -1)
		{
			var _Ids = array_of_id.split(',');
			array_of_id = '';
			for (var i = 0; i < _Ids.length; i++)
			{
				if (_Ids[i] != '"' + id + '"')
				{
					if (array_of_id != '')
						array_of_id += ',';
					array_of_id += _Ids[i];
				}
			}
			Set_Cookie( 'Notes', array_of_id, '100', '/', '', '' );
			window.location.reload();
		}
	}
	function ClearNotes()
	{
		Set_Cookie( 'Notes', '', '100', '/', '', '' );
	}
	function Selected()
	{
		var _checkboxes = document.getElementsByName('ID OFERTY');
  		for (var i = 0; i < _checkboxes.length; i++) 
  		{
  			if (_checkboxes[i].checked)
  			{
  				alert (_checkboxes[i].value);
  			}
  		}
	}
	function PrintSelected()
	{
		var _checkboxes = document.getElementsByName('ID OFERTY');
  		for (var i = 0; i < _checkboxes.length; i++) 
  		{
  			if (_checkboxes[i].checked)
  			{
  				window.open('http://www.perfekthouse.pl/Firms/Perfekthouse/Pages/Print.aspx?id=' + _checkboxes[i].value);
  			}
  		}
	}	
	function DelSelected()
	{
		var _checkboxes = document.getElementsByName('ID OFERTY');
  		for (var i = 0; i < _checkboxes.length; i++) 
  		{
  			if (_checkboxes[i].checked)
  			{
  				RemoveFromNotes(_checkboxes[i].value);
  			}
  		}
	}
	function AddSelected()
	{
		var _checkboxes = document.getElementsByName('ID OFERTY');
		var showinfo = false;
  		for (var i = 0; i < _checkboxes.length; i++) 
  		{
  			if (_checkboxes[i].checked)
  			{
  				AddToNotes(_checkboxes[i].value, 'false');
  				showinfo = true;
  			}
  		}
		if(showinfo)
			alert ('Zaznaczone oferty zostały dodane do notesu');
	}

	function showExtraDiv(id)
	{
		document.getElementById('divContactForm').style.display = 'none';
		document.getElementById(id).style.display = 'block';
	}
	function Calculator(id)
	{
		var szer=530;
		var wys=600;
		var wys2=wys+8;
		var szer2=szer+8;
		var Xpos=((screen.width/2)-(szer2/2));
		var Ypos=((screen.height/2)-(wys2/2));
		Okno=window.open('http://www.perfekthouse.pl/Firms/PerfektHouse/Pages/Calculator.aspx?id=' + id,'mapa','toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,status=no,directories=no,resizable=no,width='+szer2+',height='+wys2+',left='+Xpos+',top='+Ypos);
		Okno.focus();
	}



