//====================================================	
// @ 2006 DAG

//=====================================================================
// show an alert message and focus on a field in a form
function fieldValidation(control, message)
{
	alert(message)
	control.focus();
	return;
}

//=====================================================================
// email address validation
function validateEmail(email) 
{
	result = false;

	str = new String(email);
	index = str.indexOf("@");
	if( index > 0 ) 
	{
		pindex = str.indexOf(".",index);
		if( ( pindex > index + 1 ) && ( str.length > pindex+1 ) )
			result = true;
	}
	return result;
}

//=====================================================================
// this function verify superior and inferior limit of a string
function validateString(string, limita_inf, limita_sup)
{
	str = new String(string);

	// no limitations	
	if( ( limita_inf == 0 ) & ( limita_sup == 0 ) )
	{
		return true;
	}
	// no minimum characters, just maximum characters limitation
	else if( limita_inf == 0 )
	{
		if( str.length > limita_sup ) return false;
	}
	// no maximum characters, just minimum characters limitation
	else if( limita_sup == 0 )
	{
		if( str.length < limita_inf ) return false;
	}
	// maximum and minimum characters limitation
	else
	{
		if( ( str.length < limita_inf ) | ( str.length > limita_sup ) ) return false;
	}

	// string is in limits
	return true;
}

//=====================================================================
// the function isInteger take a string as a parameter and return true if the string is an integer number and false otherwise
// parameter StringType = 0 : only positive numbers are accepted; = 1 : positive and negative numbers are accepted
function isInteger(StringToCheck, StringType) 
{
	// null string
	//if( StringToCheck == "" ) return false;

	i = 0;
	// minus character from the begining of the string
	if( StringToCheck.charAt(0) == "-" )
	{
		if( StringType == 0 ) return false;
		else if( pozitiv == 1 ) i = 1;
	}		

	// only digits allowed
	for(; i < StringToCheck.length ; i++) 
	{
		if( ( StringToCheck.charAt(i) < '0' ) || ( StringToCheck.charAt(i) > '9' ) ) 
			return false;
	}

	return true;
}


//=====================================================================
// contact form
function contactValidation(form, langText)
{
	var patternPhone = /^[0-9_.,;:\/\\]+$/;

	control = form.ct_fullname;
	if( !validateString(control.value, 2, 0) )
	{
		//control.value = "";
		fieldValidation(control, langText[0])
		return false;
	}

	/*
	control = form.ct_phone;
	if( patternPhone.test(document.getElementById("ct_phone").value) == false )
	{
		//control.value = "";
		fieldValidation(control, langText[1])
		return false;
	}
	*/

	control = form.ct_phone;
	if( !validateString(control.value, 2, 0) )
	{
		//control.value = "";
		fieldValidation(control, langText[1])
		return false;
	}

	control = form.ct_email;
	if( !validateEmail(control.value) )
	{
		//control.value = "";
		fieldValidation(control, langText[2])
		return false;
	}

	control = form.ct_details;
	if( !validateString(control.value, 4, 0) )
	{
		//control.value = "";
		fieldValidation(control, langText[3])
		return false;
	}

	return true;
}

function contactGo(form, langText)
{
	if( contactValidation(form, langText) )
	{
		return true;
	}
	return false;
}

/*=====================================================================*/
// submit a form depending on browser
function sub_form(myform) 
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) 
	{
			theform = myform;
	}
	else 
	{ 
		theform = myform; 
	}
	theform.submit();
}