// JavaScript Document

// Changint the font Color
function changeFontColorTo(spanId, color)
	{
		document.getElementById(spanId).style.color=color;
	}
//// Showing a title
function shotitle(titleContent, placeHolder)
	{
		document.getElementById(placeHolder).innerHTML=	titleContent;
	}
// Sending contact-us mail ///
function sendContactMail(alanee_key, server, method, placeHolder, formId)
	{		
		var formObj = document.getElementById(formId);
		// Setting Error nos 0
		var failures=0;
		// Detting the first error field ...
		var firstErrorField = 'none';
		
		var name = formObj.name.value;
		var phone = formObj.phone.value;
		var mail = formObj.mail.value;
		var subject = formObj.subject.value;
		var message = formObj.message.value;
		/////////////    Validations  /////////////
		if(isWhitespace(name) == true)
			{
				failures++;
				if(firstErrorField == "none")
				firstErrorField = formObj.name;
				changeFontColorTo('name_comment', '#FF0000');
			}
		else
			{
				changeFontColorTo('name_comment', '#204357');
			}
			
		if(isWhitespace(phone) == true)
			{
				failures++;
				if(firstErrorField == "none")
				firstErrorField = formObj.phone;
				changeFontColorTo('phone_comment', '#FF0000');				
			}
		else
			{
				changeFontColorTo('phone_comment', '#204357');
			}
		if(isWhitespace(mail) == true || checkEmailFormat(mail) == false)
			{
				failures++;
				if(firstErrorField == "none")
				firstErrorField = formObj.mail;
				changeFontColorTo('mail_comment', '#FF0000');				
			}
		else
			{
				changeFontColorTo('mail_comment', '#204357');
			}
		if(isWhitespace(subject) == true)
			{
				failures++;
				if(firstErrorField == "none")
				firstErrorField = formObj.subject;
				changeFontColorTo('subject_comment', '#FF0000');				
			}
		else
			{
				changeFontColorTo('subject_comment', '#204357');
			}
		if(isWhitespace(message) == true)
			{
				failures++;
				if(firstErrorField == "none")
				firstErrorField = formObj.message;
				changeFontColorTo('message_comment', '#FF0000');				
			}
		else
			{
				changeFontColorTo('message_comment', '#204357');
			}	
		if(failures == 0) //// Send details ..... if there is no failures ..
			{
				var POSTDATA="action=sendContactMail&alanee_key="+escape(alanee_key)+"&name=" + escape(name) + "&phone=" + escape(phone) + "&mail=" + escape(mail) + "&subject=" + escape(subject) + "&message=" + escape(message);
				var myRequest = new ajaxObject(server, sendContactMail_status);
				myRequest.update(placeHolder, POSTDATA, method);
				
			}
		else
			{
				var text1 = failures>1 ? 'errors' : 'error';
				var text2 = failures>1 ? 'are' : 'is';
			 	document.getElementById('common_addComment').innerHTML='<font color="#FF0000">There '+text2+' <strong>'+failures+'</strong> input '+text1+', while processing the form. Please proceed and fix it, which are red colored.</font>';
				if(firstErrorField != 'none')
					firstErrorField.focus();				
			}
				
	}
	function sendContactMail_status(responseText, responseStatus, responseXML, divid)
		{
			if (responseStatus == 200) 
				{
					document.getElementById(divid).innerHTML=responseText;
				} 
			else 
				{
					alert(responseStatus);
				}
		}
