var xmlhttp;
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari 
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function resend_mail(uid)
{
   // alert("Rajasekar");
        xmlhttp=GetXmlHttpObject();
        var url="resend_mail.php?uid="+uid;
        xmlhttp.onreadystatechange=stateChangeresendmail;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
   // alert(url);
}
function stateChangeresendmail()
{
if (xmlhttp.readyState==4)
  {
   alert("Sent Successfully");
//alert(xmlhttp.responseText);
   history.go(0);
//document.getElementById("offlinedonorslist").innerHTML=xmlhttp.responseText;
  }
}

function editappeal(aid)
{
    window.location="patient_edit.php?pid="+aid;
}
function confirm_fundreceived()
{
    
    if(document.getElementById('receivedamnt').value!="")
    {
        var confirmation=confirm("Are you sure the entered amount is correct?");
    if(confirmation)
    {
        return true;
    }
    else
    {
        return false;
    }
    }
    else
    {
        alert("Please Enter The Amount");
    }
}

function IsNumeric(strString) //  check for valid numeric strings	
{
//alert(strString);
	if(!/\D/.test(strString)) return true;//IF NUMBER
	else if(/^\d+\.\d+$/.test(strString)) return true;//IF A DECIMAL NUMBER HAVING AN INTEGER ON EITHER SIDE OF THE DOT(.)
		else return false;
}

function IsInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function hidesharingdiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('sharing').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.showDonate.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.showDonate.style.visibility = 'hidden'; 
} 
} 
}

function showsharingdiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('sharing').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.showDonate.visibility = 'visible'; 
} 
else { // IE 4 
document.all.showDonate.style.visibility = 'visible'; 
} 
} 
}

function fieldset(id)
{
	fieldsetid="fieldset"+id;
	document.getElementById(fieldsetid).style.visibility="visible";
	document.getElementById(fieldsetid).style.display="block";
}

function showfieldset(id,count)
{
	for(i=1;i<=count;i++)
	{
		fieldid="fieldset"+i;
        activetabid="activetab"+i;
        document.getElementById('tabid').value=id;
		//tabid='listid'+i;
		//alert(fieldid);
		if(i==id)
		{
			document.getElementById(fieldid).className='activefieldset';
            document.getElementById(activetabid).className='activetab';
			//document.getElementById(tabid).className='activetab';
		}
		else
		{
			document.getElementById(fieldid).className='hiddenfieldset';
            document.getElementById(activetabid).className='inactivetab';
			//document.getElementById(tabid).className='hiddentab';	
		}
		
	}
}
function showparentnamediv()
{
    //alert("Rajasekarshow");
    //alert(document.getElementById('parentnamediv'));    
    document.getElementById('parentnamediv').style.visibility='visible';
    document.getElementById('parentdetailsdiv').style.display='table-row';
    document.getElementById('parentdetailsdiv').innerHTML='<td colspan="2"><center><font color="red">Enter Parent Details</font></center></td>';
}
function hideparentnamediv()
{
    //alert("Rajasekarhide");
    //alert(document.getElementById('parentnamediv'));
    document.getElementById('parentnamediv').style.visibility='hidden';
    document.getElementById('parentdetailsdiv').style.display='none';
    
}




/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr,divid,checkvalid){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
        document.getElementById(divid).className='errordiv';
		document.getElementById(divid).innerHTML='<img src=images/wa.png>The date format should be : mm/dd/yyyy';
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
        document.getElementById(divid).className='errordiv';
		document.getElementById(divid).innerHTML='<img src=images/wa.png>Please enter a valid month';
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
        document.getElementById(divid).className='errordiv';
		document.getElementById(divid).innerHTML='<img src=images/wa.png>Please enter a valid day';
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
        document.getElementById(divid).className='errordiv';
		document.getElementById(divid).innerHTML='<img src=images/wa.png>Please enter a valid year';
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
        document.getElementById(divid).className='errordiv';
		document.getElementById(divid).innerHTML='<img src=images/wa.png>Please enter a valid date';
		return false
	}
    var cdate = new Date();
    var currentdate = (cdate.getMonth()+1) + "/" + cdate.getDate() + "/" + cdate.getFullYear();
    var dtStr1 = new Date(dtStr);
    var currentdate1 = new Date(currentdate);
    //alert(currentdate);
    if(dtStr1<=currentdate1 && checkvalid==1)
    {
        document.getElementById(divid).className='errordiv';
		document.getElementById(divid).innerHTML='<img src=images/wa.png>date should be grater than today';
		return false
    }
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }


function checkall(count)
{
   // alert(count);
    var check=document.getElementsByName('sub');
    //alert(check);
    //alert("check="+check.length);
    if(document.getElementById('all').checked)
    {
        //alert("Checked");
    for (i=1; i<=count; i++)
    {
    //document.getElementsByName('sub')[i].checked=true;
    document.getElementById("sub"+i).checked=true;
    }
    }
    else
    {
       // alert("Unchecked");
     for (i=1; i<=count; i++)
    {
    document.getElementById("sub"+i).checked=false;
    }   
    }
}

function check_validate(count)
{
    var s=1;
    for (i=1; i<=count; i++)
    {
    //document.getElementsByName('sub')[i].checked=true;
    if(document.getElementById("sub"+i).checked==false)
    s=0;
    }
    //alert(s);
    if(s==0)
    {
        document.getElementById('all').checked=false;
    }
    else if(s==1)
    {
        document.getElementById('all').checked=true;
    }
}
function validatechangepwd()
{
   // alert("Rajasekar");
    
     if(document.getElementById('oldpwd').value=="")
     {
        document.getElementById("oldpwd").className='error';
		document.getElementById("oldpwddiv").style.visibility='visible';
		document.getElementById("oldpwddiv").innerHTML='<img src=images/wa.png> Enter Old Password';
		return false;
     }
     else
	{
		document.getElementById("oldpwd").className='success';
		document.getElementById("oldpwddiv").style.visibility='hidden';
	}
     if(document.getElementById('newpwd').value=="")
     {
        document.getElementById("newpwd").className='error';
		document.getElementById("newpwddiv").style.visibility='visible';
		document.getElementById("newpwddiv").innerHTML='<img src=images/wa.png> Enter New Password';
		return false;
     }
     else if(document.getElementById('newpwd').value.length<6)
     {
        document.getElementById("newpwd").className='error';
		document.getElementById("newpwddiv").style.visibility='visible';
		document.getElementById("newpwddiv").innerHTML='<img src=images/wa.png> Password should be minimum 6 chars';
		return false;
     }
     else
	{
		document.getElementById("newpwd").className='success';
		document.getElementById("newpwddiv").style.visibility='hidden';
	}
     if(document.getElementById('confirmnewpwd').value=="")
     {
        document.getElementById("confirmnewpwd").className='error';
		document.getElementById("confirmnewpwddiv").style.visibility='visible';
		document.getElementById("confirmnewpwddiv").innerHTML='<img src=images/wa.png> Enter New Password';
		return false;
     }
     else
	{
		document.getElementById("confirmnewpwd").className='success';
		document.getElementById("confirmnewpwddiv").style.visibility='hidden';
	}
     
     if(document.getElementById('confirmnewpwd').value!=document.getElementById('newpwd').value)
     {
      document.getElementById("confirmnewpwd").className='error';
		document.getElementById("confirmnewpwddiv").style.visibility='visible';
		document.getElementById("confirmnewpwddiv").innerHTML='<img src=images/wa.png>Password Mismatchs';
		return false;
     }
     else
	{
		document.getElementById("confirmnewpwd").className='success';
		document.getElementById("confirmnewpwddiv").style.visibility='hidden';
	}
}
function fochange(i,j)
{
    //alert(i);
    //alert(j);
    if(i==1)
    {
        document.getElementById("othersdiv"+j).className="hiddendiv";
    document.getElementById("frienddiv"+j).className="showdiv";
    }
    if(i==2)
    {
    document.getElementById("othersdiv"+j).className="showdiv";
    document.getElementById("frienddiv"+j).className="hiddendiv";
    }
    
}
function cat_others()
{
    //alert("Rajasekar");
    //alert(document.getElementById("cat_others_txt").style.visibility);
    if(document.getElementById("category_others").checked)
    document.getElementById("cat_others_txt").style.display="block";
    else
    document.getElementById("cat_others_txt").style.display="none";
    //alert(document.getElementById("cat_othersdiv"));
}

function filelist()
{
    var typeid=document.getElementById('filetypes').value;
    if(typeid!=0)
    {
        xmlhttp=GetXmlHttpObject();
        var url="xml_filetypes_list.php";
        url=url+"?filetype="+typeid;
        xmlhttp.onreadystatechange=stateChangedft;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    else
    {
        history.go(0);
    }
}
function stateChangedft()
{
if (xmlhttp.readyState==4)
  {
 //   history.go(0);
//alert(xmlhttp.responseText);
document.getElementById("filetypeslist").innerHTML=xmlhttp.responseText;
  }
}

function offlineFunds(id,type)
{
    var appealid=document.getElementById('appeal').value;
    //alert(appealid);
    if(appealid!=0)
    {
        xmlhttp=GetXmlHttpObject();
        var url="xml_offlinefunds.php";
        url=url+"?appealid="+appealid+"&type="+type+"&offlinedonorid="+id;
        xmlhttp.onreadystatechange=stateChangeofflinefunds;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    else
    {
        //history.go(0);
    }
   // alert(url);
}
function stateChangeofflinefunds()
{
if (xmlhttp.readyState==4)
  {
 //   history.go(0);
//alert(xmlhttp.responseText);
document.getElementById("offlinedonorslist").innerHTML=xmlhttp.responseText;
  }
}

function offlinedonate(id,type)
{
    //alert(type);
    var appealid=document.getElementById('appeal').value;
    var name=document.getElementById('name').value;
    var address=document.getElementById('address').value;
    var amount=document.getElementById('amount').value;
    if(type==3)
    {
    appealid=document.getElementById('appeal').value;
    name=document.getElementById('aname').value;
    address=document.getElementById('aaddress').value;
    amount=document.getElementById('aamount').value;
    }
    //alert(name);
    var status=1;
    if(type==1 || type==3)
    {
     if(name=="")
    {
      document.getElementById("errmsg").innerHTML="<font color='red'><b>Enter Name</b></font>";
      status=0;
     // alert("s1");
    }
    if(address=="" && status==1)
    {
      document.getElementById("errmsg").innerHTML="<font color='red'><b>Enter Address</b></font>";
      status=0;
     // alert("s2");
    }
    if(amount=="" && status==1)
    {
      document.getElementById("errmsg").innerHTML="<font color='red'><b>Enter Amount</b></font>";
      status=0;
     // alert("s3");
    }
    if(amount!="" && status==1)
    {
     if(!IsNumeric((amount)))
     {
     document.getElementById("errmsg").innerHTML="<font color='red'><b>Enter Numeric Value for Amount</b></font>";
      status=0; 
     // alert("s4");
     }   
    }       
    }

   // alert(appealid);
    if(status==1)
    {
        xmlhttp=GetXmlHttpObject();
        var url="xml_offlinedonate.php";
        url=url+"?appealid="+appealid+"&name="+name+"&address="+address+"&amount="+amount+"&type="+type+"&id="+id;
        xmlhttp.onreadystatechange=stateChangeofflinedonate;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
   // alert(status);
    if(appealid==0)
    {
        //history.go(0);
    }
}
function stateChangeofflinedonate()
{
if (xmlhttp.readyState==4)
  {
  //history.go(0);
//alert(xmlhttp.responseText);
//document.getElementById('appeal').value='';
document.getElementById('name').value='';
document.getElementById('address').value='';
document.getElementById('amount').value='';
hideDonate();
document.getElementById("offlinedonorslist").innerHTML=xmlhttp.responseText;
  }
}

