
function getid(str)
{
	return document.getElementById(str)
}
function isAlpha(src)
{
	var noalpha=/^[A-Za-z ]*$/;
	return noalpha.test(src)
}
function isEmail(address)
{var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;return reg.test(address)}

function getminimum(len,str,value)
{
 	if(value<len)
	{
		alert(str)
		return false;
	}else return true;
}
function captcha()
{	
	document.getElementById('loader_cap').style.display='block';
	document.getElementById('img_captcha').src=base_url+'front/captcha_load/'+Math.random();		
	//getID('IFrameName').src=getID('IFrameName').src;
	document.getElementById('loader_cap').style.display='none';
}
 jQuery(document).ready(function()
								 {
	$('#qname').blur(function() 
	{
 	 if($('#qname').val()=='')
  		{
   			$('#qname').val('Enter Your Name');
		

  		}
});
	$('#qemail').blur(function() {
  if($('#qemail').val()=='')
  {
  $('#qemail').val('Enter Your Email Address');
 
  }
});
	$('#qcomments').blur(function() {
  if($('#qcomments').val()=='')
  {
   $('#qcomments').val('Enter Your Message');
  }
});
			
$('#qname').focus(function() {
  if($('#qname').val()=='Enter Your Name')
  {
   $('#qname').val('');
  }
});
$('#qemail').focus(function() {
  if($('#qemail').val()=='Enter Your Email Address')
  {
  $('#qemail').val('');
  }
});
$('#qcomments').focus(function() {
  if($('#qcomments').val()=='Enter Your Message')
  {
   $('#qcomments').val('');
  }
});
 });
function Contact()
{
	var email=document.getElementById('email');
	//$('#flash').css({ width:'200px','top':'-454px','left':'-103px'});
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(document.getElementById('name').value=='')
	{
		
		document.getElementById('name').focus();
		document.getElementById('span_name').innerHTML='Name should not be empty';
		document.getElementById('span_email').innerHTML='';
		document.getElementById('span_comments').innerHTML='';
		document.getElementById('span_captcha').innerHTML='';
		document.getElementById('span_phone').innerHTML='';
		return false;
	}
	if(email.value=='')
	{
		document.getElementById('span_email').innerHTML='Please enter your E-mail Address';
		document.getElementById('span_name').innerHTML='';
		document.getElementById('span_comments').innerHTML='';
		document.getElementById('span_captcha').innerHTML='';
		document.getElementById('span_phone').innerHTML='';
		email.focus();
		return false;
	}
	else if(!reg.test(email.value)){
		document.getElementById('span_email').innerHTML='Please enter a valid E-mail Address';
		email.focus();
		document.getElementById('span_name').innerHTML='';
		document.getElementById('span_comments').innerHTML='';
		document.getElementById('span_captcha').innerHTML='';
		document.getElementById('span_phone').innerHTML='';
		return false;
	}

	var cap=document.getElementById('captcha_txt').value;
	if(cap==''){ document.getElementById('span_captcha').innerHTML='Please enter your Verification code';
	document.getElementById('span_name').innerHTML='';
		document.getElementById('span_email').innerHTML='';
		document.getElementById('span_comments').innerHTML='';
		document.getElementById('span_phone').innerHTML='';
		document.getElementById('captcha_txt').focus();
		return false;	 }
	
	document.getElementById('loader').style.display='block';
	$.post(base_url+"front/contact_us", {name:document.getElementById('name').value,phone:document.getElementById('phone').value, email:email.value,captcha:cap,comments:document.getElementById('comments').value,sub_hid:'submit' },
				   function(data){	
				   document.getElementById('span_name').innerHTML='';
		document.getElementById('span_comments').innerHTML='';
		document.getElementById('span_captcha').innerHTML='';
		document.getElementById('span_phone').innerHTML='';
		document.getElementById('span_email').innerHTML='';
				   document.getElementById('loader').style.display='none';
				
				   	if(data==0){document.getElementById('sererror').innerHTML='Sorry, Your request could not process. Please Try again';}
					else if(data==2){ document.getElementById('sererror').innerHTML='Invalid Verification code';}
					else{ 
					document.getElementById('sererror').innerHTML='Your request has been sent successfully. We will contact you soon';
					email.value='';
					document.getElementById('comments').value='';document.getElementById('name').value='';document.getElementById('phone').value='';
					document.getElementById('img_captcha').src=base_url+'front/captcha_load/'+Math.random();	
					document.getElementById('captcha_txt').value='';
					
					}
				   });
	return false;
}
function quickcontact()
{
	var email=document.getElementById('qemail');
	//$('#flash').css({ width:'200px','top':'-454px','left':'-103px'});
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(document.getElementById('qname').value=='')
	{
	    var fl= $('#valfooter').position();
		var flTOP=parseInt(fl.top)-10;
	    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qname').focus();
		jQuery.flash.error('', 'Please enter your  Name')
		return false;
	}
	if(document.getElementById('qname').value=='Enter Your Name')
	{
		
	    var fl= $('#valfooter').position();
		var flTOP=parseInt(fl.top)-10;
	    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qname').focus();
		jQuery.flash.error('', 'Please enter your  Name')
		return false;
	}
	
	if(email.value=='')
	{
	
		var fl= $('#valfooter').position();
		var flTOP=parseInt(fl.top)-10;
	    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qemail').focus();
		jQuery.flash.error('', 'Please enter Your E-mail Address');
		return false;
	}
	if(email.value=='Enter Your Email Address')
	{
	
		var fl= $('#valfooter').position();
		var flTOP=parseInt(fl.top)-10;
	    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qemail').focus();
		jQuery.flash.error('', 'Please enter Your E-mail Address');
		return false;
	}
	else if(!reg.test(email.value)){
		
		var fl= $('#valfooter').position();
		var flTOP=parseInt(fl.top)-10;
	    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qemail').focus();
		jQuery.flash.error('', 'Please enter a valid E-mail Address');
		return false;
	}
	if(document.getElementById('qcomments').value=='Enter Your Message')
	{
var fl= $('#valfooter').position();
		var flTOP=parseInt(fl.top)-10;
	    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qcomments').focus();
		jQuery.flash.error('', 'Please enter your comments');
		return false;
	}
	if(document.getElementById('qcomments').value=='')
	{
		
		var fl= $('#valfooter').position();
		var flTOP=parseInt(fl.top)-10;
	    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qcomments').focus();
		jQuery.flash.error('', 'Please enter your comments');
		return false;
	}
	$.post(base_url+"front/quickContact", {name:document.getElementById('qname').value,email:email.value,comments:document.getElementById('qcomments').value,sub_qhid:'submit' },
				   function(data){	
				  
				   	if(data==0)
					{
						document.getElementById('qcomments').value='';document.getElementById('qname').value='';document.getElementById('qemail').value='';
						var fl= $('#valfooter').position();
		                var flTOP=parseInt(fl.top)-10;
	                    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qemail').focus();
		jQuery.flash.error('', 'Your Request has been sent');
					}
					else
					{ 
						var fl= $('#valfooter').position();
		                var flTOP=parseInt(fl.top)-10;
	                    var flLeft=parseInt(fl.left)-9;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'209px',height:'24px'});
	    document.getElementById('qemail').focus();
		jQuery.flash.error('', 'Your Request has been sent');
						document.getElementById('qcomments').value='';document.getElementById('qname').value='';document.getElementById('qemail').value='';
					}
				   });
	return false;
}
var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "<br /><h1>Please select a Valid Credit Card Type<\/h1>";
ccErrors [1] = "<br /><h1>Please enter a Credit Card Number<\/h1>";
ccErrors [2] = "<br /><h1>Please enter a Valid Credit Card Number<\/h1>";
ccErrors [3] = "<br /><h1>Please select a Valid Credit Card Type<\/h1>";
ccErrors [4] = "<br /><h1>Credit card number has an inappropriate number of digits<\/h1>";
function checkCreditCard(cardnumber, cardname) {
     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "V", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "M", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};

  cards [2] = {name: "D", 
               length: "16", 
               prefixes: "6011,622,64,65",
               checkdigit: true};
 
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardnumber = cardnumber.replace (/\s/g, "");
  
  // Check that the number is numeric
  var cardNo = cardnumber
  var cardexp = /^[0-9]{13,19}$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {

    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  
	{
    ccErrorNo = 2;
	
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  


  // The credit card is in the required format.
  return true;
}

function validatedonation()
{
	//document.donationform.submit();
	var expdate= new Date(document.getElementById('ex_year').value,document.getElementById('ex_month').value);
    var today = new Date(year,month);
	var expdate= new Date(document.getElementById('ex_year').value,document.getElementById('ex_month').value);
    $('#span_donorwhom').html('');
	/*$('#span_type').html('');*/
	$('#span_amount').html('');
	$('#span_firstname').html('');
	$('#span_lastname').html('');
	$('#span_addressone').html('');
	$('#span_city').html('');
	$('#span_zipcode').html('');
	$('#span_phone').html('');
	$('#span_email').html('');
	$('#span_expdate').html('');
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if($('#donatewhom').val()=='')
	{
		scrollcontent('donatewhom');
		$('#donatewhom').focus();
		$('#span_donorwhom').css('display','block');
		$('#span_donorwhom').html($('#donationtype :selected').text()+' should not be empty');
		
        return false;
	}
	/*if ($("input[@name='ctype']:checked").val())
    {
	  
     }
  else
  {
	     scrollcontent('amount');
		$('#ctype').focus();
		$('#span_type').css('display','block');
		$('#span_type').html('Contribution Type should not be empty');
		
        return false;
  }*/
	if($('#amount').val()=='')
	{
		scrollcontent('amount');
		$('#amount').focus();
		$('#span_amount').css('display','block');
		$('#span_amount').html('Amount should not be empty');
		
        return false;
	}
	if($('#firstname').val()=='')
	{
		scrollcontent('firstname');
		$('#firstname').focus();
		$('#span_firstname').css('display','block')
		$('#span_firstname').html('Donor First Name should not be empty');
        return false;
	}
	if($('#lastname').val()=='')
	{
		$('#lastname').focus();
		$('#span_lastname').css('display','block');
		$('#span_lastname').html('Donor Last Name should not be empty');
        return false;
	}
	if($('#addressone').val()=='')
	{

		$('#addressone').focus();
		$('#span_addressone').css('display','block');
		$('#span_addressone').html('Address One should not be empty');
        return false;
	}
	if($('#city').val()=='')
	{
		
		$('#city').focus();
		$('#span_city').css('display','block');
		$('#span_city').html('Please Enter your city');
        return false;
	}
	if($('#zipcode').val()=='')
	{
	    //scrollcontent('zipcode');
		$('#zipcode').focus();
		$('#span_zipcode').css('display','block');
		$('#span_zipcode').html('Please enter a ZIP Code');
        return false;
	}
	if($('#phone').val()=='')
	{
	    //scrollcontent('phone');
		$('#phone').focus();
		$('#span_phone').css('display','block');
		$('#span_phone').html('Please enter your phone number');
        return false;
	}
	if($('#email').val()=='')
	{
	    //scrollcontent('email');
		$('#email').focus();
		$('#span_email').css('display','block');
		$('#span_email').html('Please enter your Email Address');
        return false;
	}
	else if(!reg.test($('#email').val()))
	{
	   // scrollcontent('email');
		$('#email').focus();
		$('#span_email').css('display','block');
		$('#span_email').html('Please enter a valid Email Address');
        return false;
	}
	if($('#cardholdername').val()=='')
	{
	    //scrollcontent('email');
		$('#cardholdername').focus();
		$('#span_cardholdername').css('display','block');
		$('#span_cardholdername').html('Please enter Card Holder Name');
        return false;
	}
	
	if($('#cardumber').val()=='')
	{
	    //scrollcontent('email');
		$('#cardumber').focus();
		$('#span_cardumber').css('display','block');
		$('#span_cardumber').html('Please enter Card Number');
        return false;
	}
	if(expdate<today)
	{
		$('#ex_month').focus();
		$('#span_expdate').css('display','block');
		$('#span_expdate').html('Please enter a Valid Expiration Date');
       
	 	return false;
	}
	if($('#securitycode').val()=='')
	{
	$('#securitycode').focus();
		$('#span_security').css('display','block');
		$('#span_security').html('Please enter Security Code');
        return false;
	}
	//if($('#cardtype').val()!='')
//	{
//	if(checkCreditCard($('#cardumber').val(),$('#cardtype').val())) 
//	{
//	//return true;
//	} 
//	else 
//	{
//		$('#span_cardtype').html('Please enter valid card no');
//        return false;
//	
//	}
//	}
	
	document.donationform.submit();
}
function ftestf(varid)
{
   $("#"+varid).slideToggle('slow');
   
}
function scrollcontent(varid)
{
$('html, body').animate({
scrollTop: $("#"+varid).offset().top-40
}, 1000);
}
$(function() {
		$(".newsticker-jcarousellite").jCarouselLite({
		btnPrev: ".prev",
        btnNext: ".next",
        btnGo: null,
        mouseWheel: false,
        auto: null,
        hoverPause: false,

        speed: 500,
        easing: null,

        vertical: true,
        visible: 2,
        start: 0,
        scroll: 1,

        beforeStart: null,
        afterEnd: null
	});				
});

function checkItallowctrl(e)
{var key;var status;if(window.event)key=event.keyCode;else key=e.which;
if((key>47&&key<59)||(key==40)||(key==41)||(key==8)||((key==0)) || ((key==46)))
{status="";return true;}
else
{status="Enter Numeric Value";return false;}}


function testimonial()
{
	  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	  $('#spantest_name').html('');
	  $('#spantest_email').html('');
	  $('#spantest_comments').html('');
	  $('#spantest_comments').html('');
	   $('#spantest_captcha').html('');
			if($('#test_name').val()=='')
			{
			  $('#test_name').focus();
			  $('#spantest_name').html('Name should not be empty');
			  return false;
			}
			if($('#test_email').val()=='')
			{
			  $('#test_email').focus();
			  $('#spantest_email').html('Please enter your E-mail Address');
			  return false;
			}
			else if(!reg.test($('#test_email').val()))
			{
				$('#test_email').focus();
				$('#spantest_email').html('Please enter a valid Email Address');
				return false;
			}
			if($('#test_comments').val()=='' || $('#test_comments').val()=='Please enter Your Message')
			{
			  $('#test_comments').focus();
			  $('#spantest_comments').html('Please enter Your Message');
			  return false;
			}
			if($('#test_captcha').val()=='')
			{
			   $('#test_captcha').focus();
			   $('#spantest_captcha').html('Please enter your Verification code');
			   return false;

			}
			document.getElementById('loader').style.display='block';
 $.post(base_url+"front/inserttestimonials", {name:document.getElementById('test_name').value,email:document.getElementById('test_email').value,phone_number:document.getElementById('test_phone').value,comments:document.getElementById('test_comments').value,captcha_code:document.getElementById('test_captcha').value,sub_qhid:'submit' },
				   function(data){
					   
				   	if(data==1)
					{   
					    $('#test_name').val('');
						$('#test_email').val('');
						$('#test_comments').val('');
						$('#test_captcha').val('');
					    document.getElementById('loader').style.display='none';
						document.getElementById('sererror').innerHTML='Your comments has been posted successfully.';
					}
					else
					{
					  document.getElementById('loader').style.display='none';
					  document.getElementById('sererror').innerHTML='Invalid Verification code';
					}
				   });
 return false;
}

