// JavaScript Document

<!--
//to = 1
//from = 0
function jsvars2(){
	if(typeof jsvars2.emailexpand == 'undefined'){
		jsvars2.emailexpand = '0';
		jsvars2.bademailsubmit = '0';
		jsvars2.email_error_response = '';
	}
}
$(document).ready(function(){
	jsvars2();
	$("#emailanchor").click(function () {
		if(jsvars2.emailexpand == '0'){
			$("#emaildiv").css({
				display:'block'
			});
			if(jsvars2.bademailsubmit == '1'){
				$("#emaildiv").animate({
					height: '385',
					queue: false
				}, 700);
			}
			else{
				$("#emaildiv").animate({
					height: '340',
					queue: false
				}, 700);
			}
			jsvars2.emailexpand = '1';
		}
	});
	$("#emailanchor_bottom").click(function () {
		location.href = '#email_inline_anchor';
		if(jsvars2.emailexpand == '0'){
			$("#emaildiv").css({
				display:'block'
			});
			if(jsvars2.bademailsubmit == '1'){
				$("#emaildiv").animate({
					height: '385',
					queue: false
				}, 700);
			}
			else{
				$("#emaildiv").animate({
					height: '340',
					queue: false
				}, 700);
			}
			jsvars2.emailexpand = '1';
		}
	});
})

function echeck(str, to_from_toggle) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		if(to_from_toggle == '1'){
			jsvars2.email_error_response = 'The recipient email address is not a valid email address.';
		}
		else{jsvars2.email_error_response = 'Your email address is not a valid email address.';}
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		if(to_from_toggle == '1'){
			jsvars2.email_error_response = 'The recipient email address is not a valid email address.';
		}
		else{jsvars2.email_error_response = 'Your email address is not a valid email address.';}

	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		if(to_from_toggle == '1'){
			jsvars2.email_error_response = 'The recipient email address is not a valid email address.';
		}
		else{jsvars2.email_error_response = 'Your email address is not a valid email address.';}
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		if(to_from_toggle == '1'){
			jsvars2.email_error_response = 'The recipient email address is not a valid email address.';
		}
		else{jsvars2.email_error_response = 'Your email address is not a valid email address.';}
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		if(to_from_toggle == '1'){
			jsvars2.email_error_response = 'The recipient email address is not a valid email address.';
		}
		else{jsvars2.email_error_response = 'Your email address is not a valid email address.';}
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		if(to_from_toggle == '1'){
			jsvars2.email_error_response = 'The recipient email address is not a valid email address.';
		}
		else{jsvars2.email_error_response = 'Your email address is not a valid email address.';}
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		if(to_from_toggle == '1'){
			jsvars2.email_error_response = 'The recipient email address is not a valid email address.';
		}
		else{jsvars2.email_error_response = 'Your email address is not a valid email address.';}
		return false
	 }

	 return true					
}



function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


	function sendPortableEmail(){
		document.getElementById('captcha_check').value = document.getElementById('captcha_check_portable').value;
		document.getElementById('Email').value = document.getElementById('Email_portable').value;
		document.getElementById('sendEmail').value = document.getElementById('sendEmail_portable').value;
		document.getElementById('comments').value = document.getElementById('comments_portable').value;
		document.getElementById('captcha').value = document.getElementById('captcha_portable').value;			
		echeck(document.getElementById('sendEmail').value , '1');
		echeck(document.getElementById('Email').value, '0');
		
		if(document.getElementById('Email').value == ''){
			document.getElementById('emaildiv_errordiv').style.display = 'block';
			document.getElementById('emaildiv_errordiv').innerHTML = "Please enter your email.";
			if(jsvars2.bademailsubmit == '0'){
				$("#email_submit_div").animate({top:'+=25'}, 500);
				$("#emaildiv").animate({
											height: '385',
											queue: false
										}, 500, function() {				
				});
				jsvars2.bademailsubmit = 1;
				return null
			}
		}
		else if(document.getElementById('sendEmail').value == ''){
			document.getElementById('emaildiv_errordiv').style.display = 'block';
			document.getElementById('emaildiv_errordiv').innerHTML = "Please enter the recipient's email.";
			if(jsvars2.bademailsubmit == '0'){
				$("#email_submit_div").animate({top:'+=25'}, 500);
				$("#emaildiv").animate({
											height: '385',
											queue: false
										}, 500, function() {				
				});
				jsvars2.bademailsubmit = 1;
				return null
			}
		}
		else if(jsvars2.email_error_response != ''){
			document.getElementById('emaildiv_errordiv').style.display = 'block';
			document.getElementById('emaildiv_errordiv').innerHTML = jsvars2.email_error_response;
			if(jsvars2.bademailsubmit == '0'){
				$("#email_submit_div").animate({top:'+=25'}, 500);
				$("#emaildiv").animate({
											height: '385',
											queue: false
										}, 500, function() {				
				});
				jsvars2.bademailsubmit = 1;
				return null
			}
			jsvars2.email_error_response = '';
		}
		else{document.getElementById('emailfriendfrm').submit();}
	}
	function togglephonediv(){
		$('#phonediv').fadeOut('fast', function() {
			// Animation complete.
			document.getElementById('phonediv').style.height = '142';
			document.getElementById('phonediv').innerHTML = jsvars.oldhtml;
		});
	}
	function ajax_rclick(theid) {
		ajax({method:'post',url:'../ajax_linkredir.cfm',postBody:'eid=' + theid});
	}
function cancelemailfade(){
	$('#emaildiv').fadeOut('fast', 
		function() {
			$("#emaildiv").css({height:'0'});
			jsvars2.emailexpand = '0';
		}
	);
}

