// JavaScript Document
var ropa
var t_val
var otval
var pre_val 
$(document).ready(function(){
	// Clearfix
	$('<style type="text/css">.clearfix:after {visibility: hidden;display: block;font-size: 0;content: " ";clear: both;height: 0;}* html .clearfix { zoom: 1; }*:first-child+html .clearfix { zoom: 1; }</style>').appendTo("head");
	 ropa =document.getElementById('siteurl_hf').value;
	
	
	function setCollection(){
		var winHeight = $(window).height();
		var winWidth = $(window).width();
		var mainWidth = 980;
		var extraWidth = winWidth-mainWidth;
		var extraHalfWidth = extraWidth / 2;
		var bodyMinHeight = winHeight - 68;
		
		var rightsideH = $('.contHeight').height();
		var sideboxInH = rightsideH - 200;
						
		$("span.redTab").css('width',extraHalfWidth);
		$(".body").css('min-height',bodyMinHeight);
		$(".sideboxIn").css('min-height',sideboxInH);
		
	}
	setCollection();
	$(".teamList ul li:last-child").css('border-bottom','none');
	$(window).resize(setCollection);
      
	  
	 

//$('.team_lst li').last().css('border-bottom', '0');
	var ur = document.location.href;
	//alert( ur.indexOf("?type=gal"));
	//alert( ur.indexOf("/projects/"));
	if((ur.indexOf("/projects/") != -1) && (ur.indexOf("?type=gal") == -1))
	{
		$("#menu-item-1762").addClass("current-page-ancestor");
		
	}
	else if((ur.indexOf("/projects/") != -1) &&( ur.indexOf("?type=gal") != -1))
	{
		$("#menu-item-1406").addClass("current-page-ancestor");
		$("#menu-item-1762").removeClass('current-menu-item');
	}
	
	if(ur.indexOf("/financial/") != -1)
	{
		$("#menu-item-1766").addClass("current-page-ancestor");
	}
   if(ur.indexOf("/testimonial/") != -1)
	{
		$("#menu-item-2049").addClass("current-page-ancestor");
	}
	
   //alert(document.location.href);
	
});

//Feedback contact form validation
function feedback_submit()
{
	var name=document.getElementById('txtname').value;
	var email=document.getElementById('txtemail').value;
	var message=document.getElementById('message').value;
	var country=document.getElementById('selectcountry').value;
	if(name=='' || name=='null')
	{
		alert('Please enter your name');
		document.getElementById('txtname').focus();
		return false;
	}
	else if(name!="")
	{
	//alert("name not null");
	var Alphabet;
	Alphabet = /^[a-zA-Z][a-zA-Z\\s ]+$/;
	var val=name.search(Alphabet);
	//alert(val);
		if (val==-1)
		{
		alert ("Please enter valid Name");
		document.getElementById('txtname').value='';
		document.getElementById('txtname').focus();
		return false;
		} 
	}
		if(email=='' || email=='null')
	{
		alert('Enter your Email Address');
		document.getElementById('txtemail').focus();
		return false;
	}
	else if(email!="")
	{
		var atpos=email.indexOf("@");
		var dotpos=email.lastIndexOf(".");
		if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
		{
		alert("Please enter your valid Email Address");
		document.getElementById('txtemail').focus();
		return false;
		}
	}
	if(message=='' || message=='null')
	{
		alert('Please enter your Message');
		document.getElementById('message').focus();
		return false;
	}
	else
	{
	return true;
	}
}
//fetch current year medai details contents

function currentyr_content(year)
{
	document.forms["media"].submit();
}
//fetch current year financial details contents
function currentyr_content_finance(f_year)
{
	document.forms["finance"].submit();
}


//validation for email from donate page
function donation_submit()
{
	var fname=document.getElementById('txtfname').value;
	var lname=document.getElementById('txtlastname').value;
	var address=document.getElementById('txt_address').value;
	var city=document.getElementById('txtcity').value;
	var state=document.getElementById('txtstate').value;
	var pincode=document.getElementById('txtpincode').value;
	var country=document.getElementById('select_country').value;
	var email=document.getElementById('txtemail').value;
	var phone=document.getElementById('txtphone').value;
	var mobile=document.getElementById('txtmobile').value;
	var passport=document.getElementById('txtpassport').value;
	var amt=document.getElementById('total_price').value;
	
	
	if(amt==0)
	{
		alert('Please select atleast one of the sponsorship amount');
		return false;
	}
	
	if(document.getElementById('others').value != "")
	{
		if (document.getElementById('others_ck').checked == false)
		{
			alert('Please check Others Field.');
			return false;
		}
	}
	if(document.getElementById('others_ck').checked == true)
	{
		if (document.getElementById('others').value == "")
		{
			alert('Please fill Others Field.');
			return false;
		}
	}
	if(fname=='' || fname=='null')
	{
		alert('Please enter your First Name');
		document.getElementById('txtfname').focus();
		return false;
	}
	if(lname=='' || lname=='null')
	{
		alert('Please enter your Last Name');
		document.getElementById('txtlastname').focus();
		return false;
	}

	if(address=='' || address=='null')
	{
		alert('Please enter your Address');
		document.getElementById('txt_address').focus();
		return false;
	}
	if(city=='' || city=='null')
	{
		alert('Please enter your City');
		document.getElementById('txtcity').focus();
		return false;
	}
	if(state=='' || state=='null')
	{
		alert('Please enter your State');
		document.getElementById('txtstate').focus();
		return false;
	}
    if(pincode=='' || pincode=='null')
	{
		alert('Please enter your Pincode');
		document.getElementById('txtpincode').focus();
		return false;
	}
	if(country=='0' || country=='null')
	{
		alert('Please select your Country');
		document.getElementById('select_country').focus();
		return false;
	}
	
	if(email=='' || email=='null')
	{
		alert('Please enter your Email Address');
		document.getElementById('txtemail').focus();
		return false;
	}
	else if(email!="")
	{
		var atpos=email.indexOf("@");
		var dotpos=email.lastIndexOf(".");
		if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
		{
		alert("Please enter your valid Email Address");
		document.getElementById('txtemail').focus();
		return false;
		}
	}
	if(phone=='' || phone=='null')
	{
		alert('Please enter your Phone Number');
		document.getElementById('txtphone').focus();
		return false;
	}
	if(mobile=='' || mobile=='null')
	{
		alert('Please enter your Mobile Number');
		document.getElementById('txtmobile').focus();
		return false;
	}
	/*if(passport=='' || passport=='null')
	{
		alert('Please enter your Passport Number');
		document.getElementById('txtpassport').focus();
		return false;
	}*/
	else
	{   
	    document.getElementById('btn_submit').style.display='none';
		document.getElementById('smt').innerHTML="Processing...";
	    return true;
		
	}
}

//home page featured project find
function state_ajx(state)
{
	//var ropa =document.getElementById('siteurl_hf').value;
	//alert(ropa);
	
var xmlhttp;
if (window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
 	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
	xmlhttp.onreadystatechange=function()
	{
		
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			//alert(xmlhttp.responseText);
				if(xmlhttp.responseText!="")
						{
						
						
						document.getElementById('project_t').innerHTML=xmlhttp.responseText;
						$('#selectproject,#projecttype,#choosestate,#selectprojectS,#projecttypeS,#choosestateS,#Year,#Archives').SelectCustomizer();
						}
		}
	}
	
	
		xmlhttp.open("POST",ropa+"/wp-content/themes/aimforseva/project_type.php?state_id="+state,true);
	
	xmlhttp.send();
	//alert('after sending ajax function');
	}
	
	
function projectType_ajx(Project_type)
{

var xmlhttp;
if (window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
 	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
	xmlhttp.onreadystatechange=function()
	{
		
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			//alert(xmlhttp.responseText);
				if(xmlhttp.responseText!="")
						{
						
						
						document.getElementById('project_contnts').innerHTML=xmlhttp.responseText;
						$('#selectproject,#projecttype,#choosestate,#selectprojectS,#projecttypeS,#choosestateS,#Year,#Archives').SelectCustomizer();
						}
		}
	}
	    //  var pth = document.getElementById().value;
		//  alert(pth);
		xmlhttp.open("POST",ropa+"/wp-content/themes/aimforseva/project_posts.php?ptype_id="+Project_type,true);

	xmlhttp.send();
	//alert('after sending ajax function');
	}
	
	
		function content_search_hm(url)
	{
		
		//alert('find posts functionalities');
		var state=document.getElementById('choosestate_customselect').value;
		var project=document.getElementById('projecttype_customselect').value;
		//var posts=document.getElementById('selectproject_customselect').value;
		//if(state=='Choose State' && project=='Project Type' && posts=='Select Particular Project')
		if(state=='Choose State')
		{
			alert('choose any state');
			return false;
		}
		/*if(project=='Project Type ')
		{
			alert('please choose any project type');
			return false;
		}
		if(posts=='Select Particular Project')
		{
			alert('please choose any post content');
			return false;
		}*/
		else
		{
		document.forms['h_search'].submit();
		
		}
	}
	
	//  donate STARTS
	
		Number.prototype.formatMoney = function(c, d, t)
	{
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
 };

	var t_val=0;
	var c_flg=0;
	
	
	
	function price_cal(p_value,txval)
	{
		var t_val=0;
       if( document.getElementById('food_academics_ck').checked == true)
	   {
		t_val += parseFloat(document.getElementById('food_academics_ck').value);
		document.getElementById("food_academics_ck_tb").style.display='block';
	   }
	   else if( document.getElementById('food_academics_ck').checked == false)
	   {
		   document.getElementById("food_academics_ck_tb").style.display='none';
	   }
	   
	   
	   
	   if( document.getElementById('gift_ck').checked == true)
	   {
		t_val += parseFloat(document.getElementById('gift_ck').value);
		document.getElementById("gift_ck_tb").style.display='block';
	   }
	   else if( document.getElementById('gift_ck').checked == false)
	   {
		   document.getElementById("gift_ck_tb").style.display='none';
	   }
	   
	   
	   
	   
		if( document.getElementById('academic_ck').checked == true)
	   {
		t_val += parseFloat(document.getElementById('academic_ck').value);
		document.getElementById("academic_ck_tb").style.display='block';
	   }
	    else if( document.getElementById('academic_ck').checked == false)
	   {
		   document.getElementById("academic_ck_tb").style.display='none';
	   }
	   
	   
	   
	   
		if( document.getElementById('clothes_ck').checked == true)
	   {
		t_val +=	parseFloat(document.getElementById('clothes_ck').value);
		document.getElementById("clothes_ck_tb").style.display='block';
	   }
	    else if( document.getElementById('clothes_ck').checked == false)
	   {
		   document.getElementById("clothes_ck_tb").style.display='none';
	   }
	   
	   
	   
	   if( document.getElementById('sponsor_ck').checked == true)
	   {
		t_val +=	parseFloat(document.getElementById('sponsor_ck').value);
		document.getElementById("sponsor_ck_tb").style.display='block';
	   }
	    else if( document.getElementById('sponsor_ck').checked == false)
	   {
		   document.getElementById("sponsor_ck_tb").style.display='none';
	   }
	   
	   
	   
	    if( document.getElementById('others_ck').checked == true)
	   {
		   //alert("test");
		   
			var oval = document.getElementById('others').value;
			if(oval != "")
			{
				t_val +=	parseFloat(document.getElementById('others').value);
			}
			else
			{
				document.getElementById('others').value =oval;
				
			}
			
			if(document.getElementById('others').value!="")
			{
				var otot = parseFloat(document.getElementById('others').value);
			document.getElementById('others_tb').innerHTML = (otot).formatMoney(2, '.', ',');
			}
			else
			{
				document.getElementById("others_ck_tb").style.display='block';
				document.getElementById('others_tb').innerHTML = 0;
				
			}
			document.getElementById("sponsorship_pop").style.display='block';
			document.getElementById("others_ck_tb").style.display='block';
	   }
	   
	   
	   
	    else if( document.getElementById('others_ck').checked == false)
	   {
		   document.getElementById("others_ck_tb").style.display='none';
		   //document.getElementById('others').value="";
	   }
	   
	   
	   
	    if( document.getElementById('ace1_ck').checked == true)
	   {
		t_val +=	parseFloat(document.getElementById('ace1_ck').value);
		document.getElementById("ace1_ck_tb").style.display='block';
	   }
	    else if( document.getElementById('ace1_ck').checked == false)
	   {
		   document.getElementById("ace1_ck_tb").style.display='none';
	   }
	   
	   
	   
	   if( document.getElementById('ace2_ck').checked == true)
	   {
		t_val +=	parseFloat(document.getElementById('ace2_ck').value);
		document.getElementById("ace2_ck_tb").style.display='block';
	   }
	    else if( document.getElementById('ace2_ck').checked == false)
	   {
		   document.getElementById("ace2_ck_tb").style.display='none';
	   }
	   
	   
	   
	    if( document.getElementById('ace3_ck').checked == true)
	   {
		t_val +=	parseFloat(document.getElementById('ace3_ck').value);
		document.getElementById("ace3_ck_tb").style.display='block';
	   }
	    else if( document.getElementById('ace3_ck').checked == false)
	   {
		   document.getElementById("ace3_ck_tb").style.display='none';
	   }
	   
	   
	   if(t_val>0)
		{
			if(c_flg == 0)
			{
				document.getElementById('sponsorship_pop').style.display='block';
			}
			else
			{
				document.getElementById('sponsorship_pop_dl').style.display='block';
			}
		}
		else
		{
			if(c_flg == 0)
			{
				document.getElementById('sponsorship_pop').style.display='none';
			}
			else
			{
				document.getElementById('sponsorship_pop_dl').style.display='none';
			}
		}
		
		if(c_flg == 0)
			{
				document.getElementById('total_d').innerHTML =(t_val).formatMoney(2, '.', ',');
		
				document.getElementById('total_price').value = t_val;
			}
			else
			{
				document.getElementById('total_d_dl').innerHTML = (t_val).formatMoney(2, '.', ',');
		
				document.getElementById('total_price').value = t_val;
			}
	}

	
	function show_optn_gen(p_optn)
	{
		
			document.getElementById(p_optn+"_ctrl").style.display='block';
			document.getElementById('spesific_ctrl').style.display='none';
			document.getElementById('sponsor_ctrl').style.display='none';
				
		
	}
	
	function show_optn_spe(p_optn)
	{
		
			document.getElementById(p_optn+"_ctrl").style.display='block';
			document.getElementById('sponsor_ctrl').style.display='none';
			document.getElementById('genral_ctrl').style.display='none';
		
		
	}
	
	function show_optn_spo(p_optn)
	{
		
		
			
			document.getElementById(p_optn+"_ctrl").style.display='block';
			document.getElementById('genral_ctrl').style.display='none';
			document.getElementById('spesific_ctrl').style.display='none';
		
		
	}
	
	function rupee_fn(visi_tbl)
	{
		//document.getElementById('sponsorship_pop_dl').style.display='none';
		document.getElementById("dollar_tbl").style.display='none';
		document.getElementById("sponcer_dolar").style.display='none'
		document.getElementById("rupee_tbl").style.display='block';
		document.getElementById("sponcer_rupee").style.display='block';
		//document.getElementById('select_donte_opt').style.display='block';
		//document.getElementById('dondetail').style.display='block';	
		
		
		/*document.getElementById('food_academics_ck_dl').checked=false;
		document.getElementById('gift_ck_dl').checked=false;
		document.getElementById('academic_ck_dl').checked=false;
		document.getElementById('clothes_ck_dl').checked=false;

		document.getElementById('sponsor_ck_dl').checked=false;
		document.getElementById('ace1_ck_dl').checked=false;
		document.getElementById('ace2_ck_dl').checked=false;
		document.getElementById('ace3_ck_dl').checked=false;
		
		document.getElementById('food_academics_ck_dl_tb').style.display='none';
		document.getElementById('gift_ck_dl_tb').style.display='none';
		document.getElementById('academic_ck_dl_tb').style.display='none';
		document.getElementById('clothes_ck_dl_tb').style.display='none';

		document.getElementById('sponsor_ck_dl_tb').style.display='none';
		document.getElementById('ace1_ck_dl_tb').style.display='none';
		document.getElementById('ace2_ck_dl_tb').style.display='none';
		document.getElementById('ace3_ck_dl_tb').style.display='none';*/
		document.getElementById('dondetail_ct').style.display='block';
		document.getElementById('dol_don_pg').style.display='none';
		t_val=0;
		c_flg=0;
	}
	function doller_fn(visi_tbl)
	{
		document.getElementById("dollar_tbl").style.display='block';
		document.getElementById("sponcer_dolar").style.display='block';
		document.getElementById("rupee_tbl").style.display='none';
		document.getElementById("sponcer_rupee").style.display='none';
		document.getElementById('sponsorship_pop').style.display='none';
		//document.getElementById('select_donte_opt').style.display='none';
		//document.getElementById('dondetail').style.display='none';
		
		document.getElementById('food_academics_ck').checked=false;
		document.getElementById('gift_ck').checked=false;
		document.getElementById('academic_ck').checked=false;
		document.getElementById('clothes_ck').checked=false;
		document.getElementById('sponsor_ck').checked=false;
		document.getElementById('ace1_ck').checked=false;
		document.getElementById('ace2_ck').checked=false;
		document.getElementById('ace3_ck').checked=false;
		
		document.getElementById('food_academics_ck_tb').style.display='none';
		document.getElementById('gift_ck_tb').style.display='none';
		document.getElementById('academic_ck_tb').style.display='none';
		document.getElementById('clothes_ck_tb').style.display='none';
		
		document.getElementById('sponsor_ck_tb').style.display='none';
		document.getElementById('ace1_ck_tb').style.display='none';
		document.getElementById('ace2_ck_tb').style.display='none';
		document.getElementById('ace3_ck_tb').style.display='none';
		document.getElementById('dondetail_ct').style.display='none';
		document.getElementById('dol_don_pg').style.display='block';

		
		
		t_val=0;
		c_flg=1;
	}
	
	function spo_calc(cal_val)
	{
		
		for (var i=0; i < document.donateform.spo_rad.length; i++)
		   {
		   if (document.donateform.spo_rad[i].checked)
			  {
			  var rad_val = document.donateform.spo_rad[i].value;
			  }
		   }
		
		
		if(document.getElementById('nostu').value !="" && rad_val !="" )
		{
			document.getElementById('total_spo').value =rad_val*document.getElementById('nostu').value;
		}

		
		   
		   
		}
	function nos_calc(nos)
	{
		for (var i=0; i < document.donateform.spo_rad.length; i++)
		   {
		   if (document.donateform.spo_rad[i].checked)
			  {
			  var rad_val = document.donateform.spo_rad[i].value;
			  }
		   }
		
		
		if(document.getElementById(nos).value !="" && rad_val !="" )
		{
			document.getElementById('total_spo').value =rad_val*document.getElementById(nos).value;
		}
	}
	/*donate ENDS*/
	
	
//search for media
	
function state_ajxfind(state)
{
	//alert(state);
var xmlhttp;
if (window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
 	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
	xmlhttp.onreadystatechange=function()
	{
		
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			//alert(xmlhttp.responseText);
				if(xmlhttp.responseText!="")
						{
						document.getElementById('projectType_find').innerHTML=xmlhttp.responseText;
						$('#selectproject,#projecttype,#choosestate,#selectprojectS,#projecttypeS,#choosestateS,#Year,#Archives').SelectCustomizer();
						}
		}
	}
	
	xmlhttp.open("POST",ropa+"/wp-content/themes/aimforseva/project_type1.php?state_id="+state,true);
	xmlhttp.send();
	//alert('after sending ajax function');
	}
	
function projectType_ajxfind(Project_type)
{
//alert('Project_type------------------------------->'+Project_type);
var xmlhttp;
if (window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
 	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
	xmlhttp.onreadystatechange=function()
	{
		
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			//alert(xmlhttp.responseText);
				if(xmlhttp.responseText!="")
						{
						
						
						document.getElementById('projectContents_find').innerHTML=xmlhttp.responseText;
						$('#selectproject,#projecttype,#choosestate,#selectprojectS,#projecttypeS,#choosestateS,#Year,#Archives').SelectCustomizer();
						}
		}
	}
	
	xmlhttp.open("POST",ropa+"/wp-content/themes/aimforseva/project_posts1.php?ptype_id="+Project_type,true);
	xmlhttp.send();
	//alert('after sending ajax function');
	}

	

	function content_search(url)
	{
		
		//alert('find posts functionalities');
		var state=document.getElementById('choosestateS_customselect').value;
		var project=document.getElementById('projecttypeS_customselect').value;
		//var posts=document.getElementById('selectprojectS_customselect').value;
		if(state=='Choose State ')
		{
			alert('choose any state');
			return false;
		}
		/*if(project=='Project Type ')
		{
			alert('please choose any project type');
			return false;
		}
		if(posts=='Select Particular Project')
		{
			alert('please choose any post content');
			return false;
		}*/
		else
		{
		document.forms['find_search'].submit();
		
		}
	}
	

		
	
	function load_images()
	{
	   $('div#PDgallery img').each( function(index) {
			preImages[index] = new Image()
			preImages[index].src = $(this).attr('src');
		});
		for (i = 0; i < preImages.length; i++) { 
			loaded[i] = false
		}
		checkLoad()
	}
	
	function checkLoad() {
		if (currCount == preImages.length) { 

		$('div#PDgallery').css('display','block');
			$('.PDgallery').cycle({ 
		cleartypeNoBg:true,
		fastOnEvent: true,
		fx:         'fade',
		speed:  'fast',
		timeout: 4000,
		next:   '#next1', 
    	prev:   '#prev1',
		center:	true,
		height:	'322',
		width:	'633'
	});
		return
		}
		for (i = 0; i < preImages.length; i++) {
		//alert(preImages[i].complete);
			if (loaded[i] == false && preImages[i].complete) {
				loaded[i] = true
				currCount++
			}
		}
		timerID = setTimeout("checkLoad()",10) 
	}
	
	function isNumberKey(evt , tfield)
       {
		   
          var charCode = (evt.which) ? evt.which : event.keyCode
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
		   
		 
       }
	
