//***************************************************************************************
function SendEmailContact(PageDetail, PageImage, users_id)
{
	
	var MessageTrimmed = getobject('message').value.replace(/^\s+|\s+$/g, '');
	var OkToSend=true;
	var alertmessage='';
	var ViewPortData=''+
			'<table width="100%" height="100%">'+
				'<tr>'+
					'<td align="center" valign="middle">'+
						'<img src="/images/sending_your_email.gif">'+
					'</td>'+
				'</tr>'+
			'</table>';
	
	ShowChangingDataScreen(PageDetail,PageImage,'320px','250px',ViewPortData,false);
	
	
	//Check Name Field "yourname":
	if (getobject('yourname').value=='')
	{
		OkToSend=false;
		getobject('yourname_title').innerHTML='Name<img src="/images/red_error.gif">';
		getobject('yourname').style.backgroundColor='RED';
		if (alertmessage=='')
		{
			alertmessage='You Must Enter a Name\n';
		}
		else
		{
			alertmessage+='You Must Enter a Name\n';
		}
	}
	
	
	// Check Email Field for Valid Email
	if (getobject('cemail').value=='' || !ValidateEmailSyntax(getobject('cemail').id))
	{
		OkToSend=false;
		getobject('cemail_title').innerHTML='Email<img src="/images/red_error.gif">';
		getobject('cemail').style.backgroundColor='RED';
		if (alertmessage=='')
		{
			alertmessage='You Must Enter a Valid Email \n';
		}
		else
		{
			alertmessage+='You Must Enter a Valid Email \n';
		}
	}

	
	//Check for Valid Phone
	if(!ValidatePhoneSyntax('cphone'))
	{
		OkToSend=false;
		getobject('cphone_title').innerHTML='Telephone<img src="/images/red_error.gif">';
		getobject('cphone').style.backgroundColor='RED';
		if (alertmessage=='')
		{
			alertmessage='You Must Enter a Valid Phone \n';
		}
		else
		{
			alertmessage+='You Must Enter a Valid Phone \n';
		}
	}

	if(MessageTrimmed=='')
	{
		OkToSend=false;
		getobject('message_title').innerHTML='Message<img src="/images/red_error.gif">';
		getobject('message').style.backgroundColor='RED';
		if (alertmessage=='')
		{
			alertmessage='You Must Enter a Valid Message \n';
		}
		else
		{
			alertmessage+='You Must Enter a Valid Message \n';
		}
	}

	
	if(!OkToSend)
	{
		alert(alertmessage);
		HideChangingDataScreen('Detailpage','Detailimage');
	}
	else
	{
			if (users_id!=undefined)
			{
				var VarableList=''+
					'dummy='+new Date().getTime()+
					'&name='+getobject('yourname').value+
					'&email='+getobject('cemail').value+
					'&tel='+getobject('cphone').value+
					'&msg='+MessageTrimmed+
					'&sectry='+getobject('security_try').value+
					'&users_id='+users_id;
			}
			else
			{
				var VarableList=''+
					'dummy='+new Date().getTime()+
					'&name='+getobject('yourname').value+
					'&email='+getobject('cemail').value+
					'&tel='+getobject('cphone').value+
					'&msg='+MessageTrimmed+
					'&sectry='+getobject('security_try').value;
			}
	
			var RemoteScriptLocation=HTTP_server+'/RemoteScripts/'
			var HttpAddress=RemoteScriptLocation+'SendEmail.php';
			http.open('POST', HttpAddress, false);
			
			//Send the proper header information along with the request
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", VarableList.length);
			http.setRequestHeader("Connection", "close");
			http.send(VarableList);

			var response = http.responseText;
			if (response=='The Security Code is Incorrect - Please Try Again')
			{
				alert(response);
				getobject('security_try').style.backgroundColor='RED';
				HideChangingDataScreen(PageDetail,PageImage);
			}
			else
			{
				alert(response);
				ClearDetailsEmailArea();
				HideChangingDataScreen(PageDetail,PageImage);
			}
	}

}
//***************************************************************************************
function Collect_Website_Leads(Users_ID,Main,Image)
{
	var iframe='../iframes/website_clickthrough_leads.php?users_id='+Users_ID;
	
	var SavingDataImage=''+
		'<table border=0 bgcolor="#F1EDE2" width="100%" height="100%">'+
			'<tr>'+
				'<td>'+
					'<iframe frameborder="0" src="'+iframe+'" '+
					'align="center" width="100%" height="100%" marginheight="0" marginwidth="0" scrolling="no">'+
					'</iframe>'+
				'</td>'+
			'</tr>'+
		'</table>';

		ShowChangingDataScreen('Detailpage','Detailimage','365px','350px',SavingDataImage,false);
	
}


//***************************************************************************************
// This can be deleted now that we use CollectWebsiteClickThroughs to get the Stats
//   as of 5-20-08  
function UpdateStats(users_id)
{
	var VarableList=''+
			'dummy='+new Date().getTime()+
			'&users_id='+users_id;
	
	var RemoteScriptLocation=HTTP_server+'/RemoteScripts/'
	var HttpAddress=RemoteScriptLocation+'UpdateStats.php';
	http.open('POST', HttpAddress, false);
			
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", VarableList.length);
	http.setRequestHeader("Connection", "close");
	http.send(VarableList);
}

//***************************************************************************************
function ClearDetailsEmailArea()
{
	getobject('yourname').value='';
	getobject('cemail').value='';
	getobject('cphone').value='';
	getobject('security_try').value='';
	getobject('message').value='';
	getobject('securityimage').src='';
	getobject('securityimage').src='/iframes/scripts/generatesecurityimage.php?dummy='+new Date().getTime();
}
//***************************************************************************************
function CollectWebsiteClickThroughs(ValidateFields)
{
	//If !ValidateFields then We're just wanting to update the stats
	
	if(ValidateFields=='true')
	{
		var OkToContinue=true;
		var ErrorMessage='';
			
		if(getobject('name').value=='')
		{
			OkToContinue=false;
			ErrorMessage='You Must Enter a Valid Name\n';
			getobject('name').style.backgroundColor='Red'
		}
			
		if(!ValidateEmailSyntax('email'))
		{
			OkToContinue=false;
			ErrorMessage+='You Must Enter a Valid Email Address\n'
			getobject('email').style.backgroundColor='Red'
		};
	}
				
	if(OkToContinue || ValidateFields=='false')
	{
		
		var VarableList=''+
			'name='+getobject('name').value+
			'&email='+getobject('email').value+
			'&phone='+getobject('phone').value+
			'&users_id='+getobject('users_id').value+
			'&Validated='+ValidateFields+
			'&dummy='+new Date().getTime();
		
		var RemoteScriptLocation=HTTP_server+'/RemoteScripts/'
		var HttpAddress=RemoteScriptLocation+'Save_Website_ClickThrough_Stats.php';
			http.open('POST', HttpAddress);
	
		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", VarableList.length);
		http.setRequestHeader("Connection", "close");
		http.onreadystatechange =
		function () 
		{
			if (http.readyState == 4) 
			{
				if (http.status == 200) 
				{
					var response = http.responseText;
					parent.HideChangingDataScreen('Detailpage','Detailimage');
					}
				}
			}
		http.send(VarableList);				
		return true;
	}
	else
	{
	 	alert(ErrorMessage);
		return false;
	}
}
//***************************************************************************************		

