function getlocations(val)
{        
        //document.getElementById('getloc').innerHTML = "<select name='location' id = 'getloc'><option value='select' value=''>Select Location</option></select>";
        var url = '/recipients/alllocations/';
        var pars = 'city_id=' + val;
        var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function showFailure(){

}
function getanswers(val)
{  
  var url = '/answers/allanswers/';

  var pars = 'question_id =' + val;
  var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function showSuccess(){

}
function state(val,id)
{        
        var url = '/contents/state/';
        var pars = 'country_id=' + val + '&divid=' + id;
        var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function citys(val,id)
{        
        var url = '/contents/city/';
        var pars = 'state_id=' + val + '&divid=' + id;
        var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}

function getcities(val)
{        
        var url = '/recipients/allcities/';
  
        var pars = 'state_id=' + val;
        var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function getstates(val)
{        
        
        var url = '/recipients/allstates/';

        var pars = 'country_id=' + val;
        var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function smoke_status(value,res)
{
       var resdes = document.getElementById(res);
       if (value == "y")
       {
              resdes.style.display="block";    
       }
       if (value == "n")
       {
              resdes.style.display="none";    
       }
}
function changeclass(value)
{
       if (value == "all")
       {
              var name = document.getElementsByName("object[]")
              for (var i=0; i<name.length; i++)
              {
                  name[i].className="";
                  name[i].checked = "";
              } 
       }
       if (value == "selected")
       {
              var name = document.getElementsByName("object[]")
              for (var i=0; i<name.length; i++)
              {
                  name[i].className='validate[minCheckbox[1]] checkbox';
              } 
       }
}
function form_submit()
{
	document.search.submit();
}
function textCounter(field,cntfield,maxlimit)
  {
  if (field.value.length > maxlimit) // if too long...trim it!
  field.value = field.value.substring(0, maxlimit);
  // otherwise, update 'characters left' counter
  else
  cntfield.value = maxlimit - field.value.length;

  }
function change_block(pid,ch1_id,p_des,ch1_des)
{

       var p = document.getElementById(pid);
       var ch1 = document.getElementById(ch1_id);
       p.className="active";
       ch1.className="inactive";
       var pdes = document.getElementById(p_des);
       
       var ch1des = document.getElementById(ch1_des);
       pdes.style.display="block";	        
       ch1des.style.display="none";
}
function smoke_freqstatus(value,res,statid)
{
       
       var resdes = document.getElementById(res);
       var id1 = document.getElementById(statid);
       if (value == "y")
       {
              id1.style.display="none";   
              resdes.style.display="block";   
       }
       if (value == "n")
       {
              resdes.style.display="block";   
              id1.style.display="none";    
       }
}
function changestate(id)
{
       var url = '/donors/getallstates/';
       var pars = 'country=' + id;
       var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}

function get(val)
{

        var url = '/recipients/allbg/';
        var pars = 'bg_id=' + val;
        var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}


function changesearchstate(id)
{
       
       var url = '/donors/getsearchstates/';
       var pars = 'country=' + id;
       var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function changecity(id)
{
       var url = '/donors/getallcity/';
       var pars = 'state=' + id;
       var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function changesearchcity(id)
{
       var url = '/donors/getsearchcity/';
       var pars = 'state=' + id;
       var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function changelocation(id)
{
       var url = '/donors/getalllocation/';
       var pars = 'city=' + id;
       var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function changesearchlocation(id)
{
       var url = '/donors/getsearchlocation/';
       var pars = 'city=' + id;
       var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function showFailure(){
       
}
function showSuccess(){
       
}
function validate(no,val)
{
       var y = document.getElementById(no).value;
       if(isNaN(y)||y.indexOf(" ")!=-1)
       {
              if (val == "cntry")
              {
                     document.getElementById('msg4').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "area")
              {
                     document.getElementById('msg').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "mobcntry")
              {
                     document.getElementById('msg1').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "submitter_cntry")
              {
                     document.getElementById('submitter_msg4').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "submitter_area")
              {
                     document.getElementById('submitter_msg').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "submitter_mobcntry")
              {
                     document.getElementById('submitter_msg1').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "emercntry")
              {
                     document.getElementById('msg2').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "emerarea")
              {
                     document.getElementById('msg3').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              
              if (val == "emermobcntry")
              {
                     document.getElementById('msg5').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "phymobcntry")
              {
                     document.getElementById('msg6').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "hospmobcntry")
              {
                     document.getElementById('msg7').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              if (val == "phyclcntry")
              {
                     document.getElementById('msg8').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
	      if (val == "phyclarea")
              {
                     document.getElementById('msg8').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";            
              }
              document.getElementById(no).value = "";
              return false;
       }
       else if(document.getElementById(no).value == "")
       {
              if (val == "cntry")
              {
                     document.getElementById('msg4').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "area")
              {
                     document.getElementById('msg').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "mobcntry")
              {
                     document.getElementById('msg1').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "submitter_cntry")
              {
                     document.getElementById('submitter_msg4').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "submitter_area")
              {
                     document.getElementById('submitter_msg').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "submitter_mobcntry")
              {
                     document.getElementById('submitter_msg1').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "emercntry")
              {
                     document.getElementById('msg2').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "emerarea")
              {
                     document.getElementById('msg3').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              
              if (val == "emermobcntry")
              {
                     document.getElementById('msg5').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "phymobcntry")
              {
                     document.getElementById('msg6').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "hospmobcntry")
              {
                     document.getElementById('msg7').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              if (val == "phyclcntry")
              {
                     document.getElementById('msg8').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
	      if (val == "phyclarea")
              {
                     document.getElementById('msg8').innerHTML = '<font color="red">' + 'Field should not be left blank'+ "</font>";            
              }
              
              return false;
       }
       else
       {
              if (val == "cntry")
              {
                     document.getElementById('msg4').innerHTML = '';            
              }
              if (val == "area")
              {
                     document.getElementById('msg').innerHTML = '';
              }
              if (val == "mobcntry")
              {
                     document.getElementById('msg1').innerHTML = '';            
              }
              if (val == "submitter_cntry")
              {
                     document.getElementById('submitter_msg4').innerHTML = '';            
              }
              if (val == "submitter_area")
              {
                     document.getElementById('submitter_msg').innerHTML = '';
              }
              if (val == "submitter_mobcntry")
              {
                     document.getElementById('submitter_msg1').innerHTML = '';            
              }
              if (val == "emercntry")
              {
                     document.getElementById('msg2').innerHTML = '';            
              }
              if (val == "emerarea")
              {
                     document.getElementById('msg3').innerHTML = '';            
              }
              if (val == "emermobcntry")
              {
                     document.getElementById('msg5').innerHTML = '';            
              }
              if (val == "phymobcntry")
              {
                     document.getElementById('msg6').innerHTML = '';            
              }
              if (val == "hospmobcntry")
              {
                     document.getElementById('msg7').innerHTML = '';            
              }
              if (val == "phyclcntry")
              {
                     document.getElementById('msg8').innerHTML = '';            
              }
	      if (val == "phyclarea")
              {
                     document.getElementById('msg8').innerHTML = '';            
              }

       }
}
function validatepostal(no,val)
{

       var y = document.getElementById(no).value
       if(isNaN(y)||y.indexOf(" ")!=-1)
       {
              if (val == "emergencyphone")
              {
                     document.getElementById('msg3').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";
              }
              if (val == "phone")
              {
                     document.getElementById('msg2').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";
              }
              if (val == "postal")
              {
                
                     document.getElementById('msg1').innerHTML = '<font color="red">' + 'Enter numeric value'+ "</font>";
              }
              
              document.getElementById(no).value = "";
              return false;
       }
       else
       {
              if (val == "emergencyphone")
              {
                document.getElementById('msg3').innerHTML = '';
              }
              if (val == "phone")
              {
                  document.getElementById('msg2').innerHTML = '';
              }
              if (val == "postal")
              {
                
                  document.getElementById('msg1').innerHTML = '';
              }
       }
}
function donor_validate(donor)
{
       var s = document.getElementById("checkbox");
       var c_value = "";
       if (document.donor.donor_organ_selected.checked)
       {
              for (var i=0; i < document.donor.object_.length; i++)
              {
                     if (document.donor.object_[i].checked)
                     {
                     
                            c_value += c_value + document.donor.object_[i].value + "\n";
                     }
              }
              if(c_value=="")
              {
                     s.innerHTML="<font color = red>Select organ.</font>";
                     return false;
              }
              else
              {
                     s.innerHTML = "";
              }
       }
       
}
function savedata(){
       
}
function isValidDate(user) {
	flag=0;
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
        if(user == 'recipient')
        {
		dateStr = document.getElementById("recipient_birthdate_2i").value + "-" + document.getElementById("recipient_birthdate_3i").value + "-" + document.getElementById("recipient_birthdate_1i").value
	}
	else
	{
		dateStr = document.getElementById("donor_birthdate_2i").value + "-" + document.getElementById("donor_birthdate_3i").value + "-" + document.getElementById("donor_birthdate_1i").value
	}
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		document.getElementById('date_error').innerHTML = '<font color="red">' + 'Date is not in a valid format.'+ "</font>";            
		//alert("Date is not in a valid format.")
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		document.getElementById('date_error').innerHTML = '<font color="red">' + 'Month must be between 1 and 12.'+ "</font>";
		//alert("Month must be between 1 and 12.");
		flag = 1;
		return false;
	}
	if (day < 1 || day > 31) {
		document.getElementById('date_error').innerHTML = '<font color="red">' + 'Day must be between 1 and 31.'+ "</font>";
		//alert("Day must be between 1 and 31.");
		flag = 1;
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		document.getElementById('date_error').innerHTML = '<font color="red">' + 'Month '+month+' doesnt have 	31 days!'+ "</font>";
		//alert("Month "+month+" doesn't have 31 days!")
		flag = 1;
		return false
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			document.getElementById('date_error').innerHTML = '<font color="red">' + 'February ' + year + " doesnt have " + day + ' days!'+ "</font>";
			flag = 1;
			//alert("February " + year + " doesn't have " + day + " days!");
			return false;
		}
	}
	if (flag==0)
	{
		document.getElementById('date_error').innerHTML = '';
	}
	return true; 
}
function popup(id)
{
       
       if(document.getElementById("popup") != null)
       {
       var elem = document.getElementsByClassName("pop")
       for (var i = 0; i < elem.length; i++) {
       elem[i].innerHTML = '';
       }
       }
       var url = '/donors/donorinfo/';
       var pars = 'donor_id=' + id;
       finalid = "popup_" + id;
       document.getElementById(finalid).innerHTML = "<div id ='popup'><img src='/images/ajax-loader.gif'></div>"
       var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}

function popup_recipient(id)
{
       
       if(document.getElementById("popup") != null)
       {
       var elem = document.getElementsByClassName("pop")
       for (var i = 0; i < elem.length; i++) {
       elem[i].innerHTML = '';
       }
       }
       var tp = "popup_" + id;
       document.getElementById(tp).style.display = 'block';

       var url = '/recipients/recipientinfo/';
       var pars = 'recipient_id=' + id;
       var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure, onSuccess: showSuccess });
}
function check_emer_mob_unique(temp,temp2)
{
       if(temp == temp2)
       {
              document.getElementById('msg_mob').innerHTML = '<font color="red">' + 'Donor mobile no. and emergency mobile no.  should not be same'+ "</font>";
              //document.getElementById("donor_emergency_name").value = "";
       }
       else
       {
              document.getElementById('msg_mob').innerHTML = "";
       }
}
function check_emer_name_unique(temp1,temp2,temp3)
{
       var temp = temp1.replace(/\s+/g,"");
       var temp4 = temp2 + temp3;
       if(temp == temp4)
       {
              document.getElementById('msg_name').innerHTML = '<font color="red">' + 'Donor name and emergency contact name should not be same'+ "</font>";
              //document.getElementById("donor_emergency_name").value = "";
       }
       else
       {
              document.getElementById('msg_name').innerHTML = "";
       }
       
       /*alert(temp[0]);
       alert(temp[1]);
       alert(temp[2]);
       alert(document.getElementById("donor_name").value);
       alert(document.getElementById("donor_surname").value);*/

}
function close1(id)
{
       tempid = "popup_" + id;
       document.getElementById(tempid).innerHTML = '';
}
function openpopup()
{
       document.getElementById("popup").style.display = 'block';
}
function form_submit()
{
	document.search.submit();
}
function displayblock(mailid,id,tabtype)
{
     
       document.getElementById("reply_block").style.display = 'block';
       document.getElementById("text_field").innerHTML =  "<input id='email' name='email' type='hidden' value = '"+mailid +"'/><input id='id' name='id' type='hidden' value = '" + id + "'/><input id='tabtype' name='tabtype' type='hidden' value = '" + tabtype + "'/>";
       //document.getElementById("text_field").innerHTML =  "<input id='id' name='id' type='hidden' value = '"+id +"'/>";
       //document.getElementById("text_field").innerHTML =  "<input id='tabtype' name='tabtype' type='hidden' value = '"+ tabtype +"'/>";
       
}