// JavaScript Document
// izwikwa se ot /eshop/order.php => /eshop/order_astro_iframe.php
function chechOrderForm ()
{
	FieldsArray = new Array ('name', 'city', 'country');
	if (document.EshopFormOrder)
	{
		string = '';
		for (i = 0; i < document.EshopFormOrder.length; i++)
		{
			if (document.EshopFormOrder[i].name)
			{
				if (document.EshopFormOrder[i].name.indexOf('nohour') == -1)
				{
					document.EshopFormOrder[i].style.border = "1px solid #000000";
				}
				id = document.EshopFormOrder[i].name
				for (x = 0; x < FieldsArray.length; x++)
				{
					if (id.indexOf(FieldsArray[x]) > -1)
					{
						if (document.EshopFormOrder[i].value == '')
						{
							alert ("Παρακαλώ να συμπληρωθεί!");
							document.EshopFormOrder[i].focus();
							document.EshopFormOrder[i].style.border = "1px solid #ff0000";
							return false;
						}
					}
				}
			}
		}
	}
	DisableElement ('subm');
	document.EshopFormOrder.submit();
}

function trim(s) 
{
	while (s.substring(0, 1) == ' ') 
	{
		s = s.substring(1, s.length);
  	}
	while (s.substring(s.length-1, s.length) == ' ') 
	{
		s = s.substring(0, s.length-1);
	}
	return s;
}

// izwikwa se ot file-a /eshop/order02.php
function CheckFormOrder02 ()
{
	if (document.FormOrder02.pay_send)
	{
		statusS = 'off';
		for (i = 0; i < document.FormOrder02.pay_send.length; i++)
		{
			if (document.FormOrder02.pay_send[i].checked == true)
			{
				statusS = 'on';
				email = document.FormOrder02.pay_send[i].value;
			}
		}
	}
	if (statusS == 'off')
	{
		alert ('Επιλέξτε τρόπο πληρωμής και αποστολής')
		return false;
	}
	if (email == 5 || email == 6)
	{
		e_mail = document.FormOrder02.email;
		if (e_mail.value == "")
		{
			alert ("Έχετε επιλέξει αποστολή στο email. Συμπληρώστε το e-mail σας");
			e_mail.style.border = "1px solid #ff0000";
			e_mail.focus();
			return false;
		
		} else
		{
			ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
			for (i = 0; i < e_mail.value.length ;i++)
			{
				if (ok.indexOf (e_mail.value.charAt (i)) < 0)
				{ 
					alert ("Παρακαλώ καταχωρήστε ένα έγκυρο e-mail");
					e_mail.style.border = "1px solid #ff0000";
					e_mail.focus();
					return false;
				}	
			} 
			if (document.layers || document.getElementById || document.all) 
			{
				var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
				if (!filter.test(e_mail.value))
				{
					alert ("Παρακαλώ καταχωρήστε ένα έγκυρο e-mail");
					e_mail.style.border = "1px solid #ff0000";
					e_mail.focus();
					return false;		
				
				} else
				{
					e_mail.style.border = "1px solid #000000";
				} 
			}
		}
	}
	NameFields = new Array ('names', 'family', 'street', 'str_num', 'city', 'pcode', 'phone');
	if (document.FormOrder02)
	{
		for (i = 0; i < NameFields.length; i++)
		{
			if (document.FormOrder02[eval("NameFields[i]")])
			{
				document.FormOrder02[eval("NameFields[i]")].style.border = "1px solid #000000";
				if (document.FormOrder02[eval("NameFields[i]")].value == "")
				{
					alert ("Παρακαλώ να συμπληρωθεί!");
					document.FormOrder02[eval("NameFields[i]")].focus();
					document.FormOrder02[eval("NameFields[i]")].style.border = "1px solid #ff0000";
					return false;
				}
			}
		}
		DisableElement ('sub01');
		DisableElement ('sub02');
		DisableElement ('sub03');
		document.FormOrder02.submit();
	}
}

// izwikwa se ot /eshop/index_form_astro.php
// pokazwa ili skriwa opisanieto na daden analiz
function displayDescription (id)
{
	if (document.all)
	{
		if (document.all('disc_'+id))
		{
			if (document.all('disc_'+id).style.visibility == 'visible')
			{
				document.all('disc_'+id).style.visibility = 'hidden';
				document.all('disc_'+id).style.display = 'none'
			
			} else
			{
				document.all('disc_'+id).style.visibility = 'visible';
				document.all('disc_'+id).style.display = 'block'
			}
		}
	} 
}

function DisableElement (obj)
{
	if (document.all && document.all(obj))
	{
		document.all(obj).disabled = true;
	}
}	

function OpenNew ()
{
	if (!window.newWin)
	{
		w = (screen.availWidth - 10 - 600)/2;
		h = (screen.availHeight - 20 - 400)/2;
		features = "width=600,height=400";
		features += ",scrollbars=1,resizable=0,location=0";
		features += ",menubar=0,toolbar=0,status=0";
		features += ",left="+w+",top="+h+",screenX="+w+",screenY="+h;
		newWin = window.open('payment.php', '', features);
		
	} else
	{
		if (!newWin.closed)
		{
			newWin.focus();
			
		} else
		{
			w = (screen.availWidth - 10 - 600)/2;
			h = (screen.availHeight - 20 - 400)/2;
			features = "width=600,height=400";
			features += ",scrollbars=1,resizable=0,location=0";
			features += ",menubar=0,toolbar=0,status=0";
			features += ",left="+w+",top="+h+",screenX="+w+",screenY="+h;
			newWin = window.open('payment.php', '', features);
		}
	}
}

function CheckEmail ()
{
	str = document.FormOrder02.email.value;
	
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for (i = 0; i < str.length ;i++)
	{
		if (ok.indexOf (str.charAt (i)) < 0)
		{ 
			alert ("Παρακαλώ καταχωρήστε ένα έγκυρο e-mail");
			document.FormOrder02.email.style.border = "1px solid #ff0000";
			document.FormOrder02.email.focus();
			return false;
		}	
	} 
	if (document.layers || document.getElementById || document.all) 
	{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (!filter.test(str))
		{
			alert ("Παρακαλώ καταχωρήστε ένα έγκυρο e-mail");
			document.FormOrder02.email.style.border = "1px solid #ff0000";
			document.FormOrder02.email.focus();
			return false;		
		} 
	}
	return true;
}