var d = document;

function validate( objForm )
{
	sErrorMessage = "The following fields are mandatory and not filled correctly:\n";	
	ResetErrors(5);
	if ( objForm.sName.value == "" )
	{
		sErrorMessage += " - Full name\n";
		DisplayError('0');
	}
	if ( objForm.sCompany.value == "" )
	{
		sErrorMessage += " - Company\n";
		DisplayError('1');
	}
	if ( !isEmail(objForm.sEmail.value) )
	{
		sErrorMessage += " - E-mail\n";
		DisplayError('2');
	}
	if ( objForm.sPhone.value == "" )
	{
		sErrorMessage += " - Phone number\n";
		DisplayError('3');
	}
	if ( objForm.sURL.value == "" )
	{
		sErrorMessage += " - URL to your website\n";
		DisplayError('4');
	}
	if ( sErrorMessage != "The following fields are mandatory and not filled correctly:\n" )
	{
		alert(sErrorMessage);
		return false;		
	}
	return true;
}

function isEmail ( sEmailAddress )
{
	var at 			= sEmailAddress.indexOf( "@" );
	var lastAt 		= sEmailAddress.lastIndexOf( "@" );
	var dot 		= sEmailAddress.lastIndexOf( "."  );
	var suffix  	= sEmailAddress.length - dot;

	if ( ( at < 1 ) || ( at != lastAt ) || ( dot < at ) || ( suffix > 5 ) || ( suffix == 1 ) )
	{
		return false;
	}
	return true;
}

function ResetErrors ( iNumberOfErrors )
{
	for ( i = 0; i < iNumberOfErrors; i++ )
	{
		document.getElementById("Error" + i).style.color = "#6A6A6A";
	}
}

function DisplayError ( sErrorId )
{
	document.getElementById("Error" + sErrorId).style.color = "#CC0000";
}

function printPage()
{
	var pr = (window.print) ? 1 : 0;
	
	if(!pr)
	{
		window.status = "No print";
		return;
	}
	
	var printArea = document.getElementById("TdMainField");
	if(printArea == null)
	{
		window.status = "No print";
		return;
	}
	
	if(printArea) 
	{
		var sStart = "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"/inc/css/global.css\">";
		sStart += "</head><body style=\"background-color: #FFF; margin: 10px 10px 10px 10px;\"><div align=\"left\">";
		sStop = "</div></body></html>";

		var w = window.open('about:blank','printWin','width=650,height=600,scrollbars=yes');
		wdoc = w.document;
		wdoc.open();
		wdoc.write( sStart + TdMainField.innerHTML + sStop ) ;
		wdoc.close();
		w.print();
	}
}
