////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/**********************************************************\

    File concerns the contact form for the site

\**********************************************************/

    Event.observe(window, "load", function (){
		
	    Event.observe('contactButton',
					  'click',
			function(){
					
				var formid = $('conFrom');
				
				//alert(formid.id);
					
			    if(validateContact(formid)){
					
				    // we are successful and we submit the contact info
					var para = formid.serialize();
					
					if($('submitNotify').innerHTML == 'Your information has been emailed to Perfectshare.<br/><Br/>Thank you!'){
						$('submitNotify').innerHTML = "<img src=\"/images/ajax-loader.gif\" alt=\"Sending your information now\" title=\"Submitting your information now\" /><br/>Submitting Data Now";
					}
					$('submitNotify').style.display = 'block';
					
					new Ajax.Request('/contact.php',{
					
					    method:'post',
						parameters:para,
						onSuccess:function(f){
							
							if (f.responseText == '') {
						    setTimeout(function(){
							    
								$('submitNotify').innerHTML = 'Your information has been emailed to Perfectshare.<br/><Br/>Thank you!';
								
							},'1589');
						} else {
							alert(f.responseText);
							$('submitNotify').style.display = 'none';
						}	
							
						}
					
					});
					
				}
						  
			});
		
	});
	
	function validateContact(formid){
		
	    var retVal = true;
		
				//we validate the inputs to this form
		Form.getInputs(formid).each(function(el){
			
			if(el.value==''||el.value==' '||el.value=='This element is empty.  Please enter a value.'){
			    
				el.className='errorInput';
				//el.value = 'This element is empty.  Please enter a value.';
				el.focus();
				retVal = false;
				
			}
			
		});
		
		//we validate the textarea to this form
		if($('ccomments').value==''||$('ccomments').value==' '||$('ccomments').value=='This element is empty.  Please enter a value.'){
		
		    var el = $('ccomments');
			el.className='errorInput';
			//el.value = 'This element is empty.  Please enter a value.';
			el.focus();
			retVal = false;
		
		}
		
		if (!retVal) {
			alert('Please fill in the elements outlined in red');
		}		
		
		return retVal;
		
	}
	
	