function ajaxFunction()
{
    var xmlHttp;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
return xmlHttp;
}


//.......................................Functions For Categories availability.............................
/****************Global Varibles*************************/
var catego=new Array(0,0);
var total_category=0;
var flag=0;
var sec_busket0=new Array(5);
var sec_busket1=new Array(5);
var sec1=0;
var sec2=0;
function handleUserajax(xmlHttp,val1){
        
       if(xmlHttp.readyState==1){
		document.getElementById('loader').style.display="block";
		document.getElementById('loader').innerHTML="<img src='images/loader.gif' width='16' height='16' border='0' align='absmiddle'>&nbsp;Loading, Please Wait ...";
	}
        
	if(xmlHttp.readyState==4){
                
		if(xmlHttp.status==200){
                                
                                document.getElementById('loader').style.display="none";
                                document.getElementById('loader').innerHTML="";
                                
                                var reply=xmlHttp.responseText;
                                prime_cat=document.addevent.primary_category.value;
                                   
                                    for(k=0;k<2;k++){
                                        
                                            if(catego[k]==0 && flag==0 && catego[0]!=prime_cat && catego[1]!=prime_cat){
                                                    catego[k]=prime_cat;
                                                    //mridu_start_28thfeb
                                                    document.getElementById('result'+k).innerHTML ='<input type="checkbox" onClick="removePrimaryCategory1('+k+');" value="'+prime_cat+'" name="prime'+k+'" checked="checked">&nbsp;&nbsp;Secondary Categories for <b>'+val1+'</b>&nbsp;&nbsp;';/*<a href="#abc" onclick="addNewCategory('+k+');"><font color="red">Add new Secondary Category</font></a>*/
                                                    //mridu_end_28thfeb
                                                    document.getElementById('showsubcategories'+ k).innerHTML =reply;
                                                    flag++;
                                                   
                                            }
                                    }
                                    
                               
                }
                flag=0;
                
               
        }
}

//---------------------Remove Category if unchecked-----------------------
function removePrimaryCategory1(total_cate){
        //var cc=check.checked;
        res=window.confirm("Click OK to delete the Primary Category. Click Cancel to stop.");
        if(res){
            for(i=0;i<5;i++)
            document.getElementById("prime"+total_cate+"sec"+i).innerHTML ='';
                            
            //document.getElementById("prime"+total_cate+"sec").style.display='none';
            document.getElementById('showsubcategories'+total_cate).innerHTML ='';
            document.getElementById('result'+total_cate).innerHTML ='';
            catego[total_cate]=0;
            
            if(total_cate==0){
               
                sec1=0;
                stack1=new Array('prime0sec0','prime0sec1','prime0sec2','prime0sec3','prime0sec4');
            }
            else{
                sec2=0;
                stack2=new Array('prime1sec0','prime1sec1','prime1sec2','prime1sec3','prime1sec4');
            }
        }
        else{
            if(total_cate==0)
            document.addevent.prime0.checked=true;
            document.addevent.prime1.checked=true;
        }
    
}



//---------------------Remove and Select Category if unchecked-----------------------
function removeSecondaryCategory(catid,selectval,checkObject){
        //alert(checkObject.name);
        var ss=checkObject.checked;
        //var ss = document.getElementById('85').checked;
        //alert(ss);
        for(g=0;g<2;g++){
               
                if(ss){
                        if(catego[g]==catid){
                                if(g==0 && sec1<5){
                                        sec_busket0[sec1]=selectval;
                                        sec1++;
                                        
                                }
                                else if(g==0 && sec1>=5){
                                        alert("you can't select more than 5 subcategories.");
                                        document.getElementById(selectval).checked=false;
                                       
                                }
                                else if(g==1 && sec2<5){
                                        sec_busket1[sec2]=selectval;
                                        sec2++;
                                }
                                else if(g==1 && sec2>=5){
                                        alert("you cant select more than 5 subcategories.");
                                        document.getElementById(selectval).checked=false;
                                }
                        }
                }
                else{
               
                        for(var count=0;count<5;count++){
                               
                                if(sec_busket0[count]==checkObject.name){
                                        sec_busket0[count]="NULL";
                                        var y=count;
                                        for(z=y;z<5;z++){
                                                sec_busket0[z]=sec_busket0[z+1];
                                        }
                                        sec1--;
                                        
                                }
                                else if(sec_busket1[count]==checkObject.name){
                                        sec_busket1[count]="NULL";
                                        var y=count;
                                        for(z=y;z<5;z++){
                                                sec_busket1[z]=sec_busket1[z+1];
                                        }
                                        sec2--;
                                }
                        }
                }
                
                /*
                if(catego[g]==catid){
                        if(g==0 && sec1==5){
                                alert("no1");
                        }
                        else if(sec2==5){
                                alert("no2");
                        }
                }*/
                
        }
        
        
}




//----------------------------------------------------Get Secondary categories for a selected Primary category--------------------------
var disaster='';

function startAjaxSecondaryCategory(){
        var xmlHttp=ajaxFunction();
        
        val5=document.addevent.primary_category.value;
        
        val=document.getElementById('p_category');
        val1=val.options[val.selectedIndex].text;
       
        if(val5!='selectCategory'){
            
            if(disaster!=''){
                
                if(document.addevent.primary_category.value==9){
                    xmlHttp.open("GET","ajax_categories.php?val=9&disaster="+disaster,true);
                    xmlHttp.onreadystatechange=function(){handleUserajax( xmlHttp,val1);}
                    xmlHttp.send(null);
                }
            }
            else{
                  
                    xmlHttp.open("GET","ajax_categories.php?val="+val5,true);
                    xmlHttp.onreadystatechange=function(){handleUserajax( xmlHttp,val1);}
                    xmlHttp.send(null);
                   
            }
        }
}



function showHide(me,comboDiv,textDiv,combo,text){
	var me_dom=document.getElementById(me);
	var combo_dom=document.getElementById(comboDiv);
	var text_dom=document.getElementById(textDiv);
	if(me_dom.checked==true)
	{
	getById(combo).selectedIndex='0';
	combo_dom.style.display='none';
	text_dom.style.display='block';
	getById(text).focus();
	}
	else{
	combo_dom.style.display='block';
	getById(text).value='';
	text_dom.style.display='none';
	}
	
	if(me=='country_checkId' && me_dom.checked==true)
	{
		
		getById('state_comboId').selectedIndex='0';
		hide('stateDiv1');
		getById('state_checkId').checked=false;
		hide('state_checkDiv');
		show('stateDiv2');
		
		
		getById('city_comboId').selectedIndex='0';
		hide('cityDiv1');
		getById('city_checkId').checked=false;
		hide('city_checkDiv');
		show('cityDiv2');
	}
	else if(me=='country_checkId' && me_dom.checked==false){
		show('stateDiv1');
		show('state_checkDiv');
		getById('state_textboxId').value='';
		hide('stateDiv2');
		
		show('cityDiv1');
		show('city_checkDiv');
		getById('city_textboxId').value='';
		hide('cityDiv2');
	}
	
	if(me=='state_checkId' && me_dom.checked==true)
	{
		getById('city_comboId').selectedIndex='0';
		hide('cityDiv1');
		getById('city_checkId').checked=false;
		hide('city_checkDiv');
		show('cityDiv2');
	}
	else if(me=='state_checkId' && me_dom.checked==false){
		show('cityDiv1');
		show('city_checkDiv');
		getById('city_textboxId').value='';
		hide('cityDiv2');	
	}
	
	
}

function startAjaxState(){
	var xmlHttp=ajaxFunction();
	var element=document.getElementById('country_comboId');
        var val=element.options[element.selectedIndex].value;
	if(element.selectedIndex==0){
		alert("Please select a country");
        }
        else{
		var url="ajax_state.php?val="+val;
                xmlHttp.open("GET",url,true);
                xmlHttp.onreadystatechange=function (){ handleStateAjax(xmlHttp);}
                xmlHttp.send(null);
               
        }     
}



function handleStateAjax(xmlHttp){
       
	if(xmlHttp.readyState==4 && xmlHttp.status==200){
            getById("wait_msg_state").innerHTML='';
            var reply=new Array();
            reply=xmlHttp.responseText;
            document.getElementById("state_comboId").innerHTML='<option value="0">--------------Select a State--------------</option>'+reply;
            document.getElementById("city_comboId").selectedIndex=0;
	}else if(xmlHttp.readyState==1){
            getById("wait_msg_state").innerHTML="<img src='images/loader.gif' width='16' height='16' border='0' align='absmiddle'>&nbsp;Populating state please wait ...";
            
	}
}

function startAjaxCity(){
	var xmlHttp=ajaxFunction();
        var element=document.getElementById('state_comboId');
        var val=element.options[element.selectedIndex].value;
	
        if(element.selectedIndex==0){
		alert("Please select a State.");
        }
        else{
		xmlHttp.open("GET","ajax_city.php?val="+val,true);
		xmlHttp.onreadystatechange=function (){handleCityAjax(xmlHttp);}
		xmlHttp.send(null);
        }
       
}

function handleCityAjax(xmlHttp){
       	if(xmlHttp.readyState==4 && xmlHttp.status==200){
		var reply=new Array();
		reply=xmlHttp.responseText;
		document.getElementById("city_comboId").innerHTML='<option value="0">--------------Select a City--------------</option>'+reply;
	}              
}


//-----------------------------------------------------------Not used-------------------------------------------------------------------------
/*
function startAjaxUserRequest1(){
        val=document.customerSignUp.name.value;
	if(document.f1.name.value=="")
		alert("Please Enter your phone no");
	else{
		createXMLHttpRequest();
		xmlHttp.open("GET","ajax_user.php?val="+val,true);
		xmlHttp.onreadystatechange=handleUserajax;
		xmlHttp.send(null);
	}
}
*/
//-------------------------------------------------------------Not used----------------------------------------------------------------------------------
function valid(){
		document.getElementById('warning').innerHTML="SignUp successfull!!!";
		return true;
	}



//------------------------------------------------------Global Variables--------------------------------------------------------------------------------        
 var myArray=new Array();
 var column=0;
 var column1=0;
 var column2=0;
 var row=0;
 myArray[0] = new Array(5);
 myArray[1] = new Array(5);
 var val1;
//-----------------------------------------------------------------Show selected primary categories---------------------------------------------------- 
function selectPrimaryCategory(){
        
        val=document.getElementById('p_category');
        val1=val.options[val.selectedIndex].text;
        
       
        myArray[row][0] = val1;
       
        document.getElementById('primecat'+row).innerHTML='<input type="checkbox" name=val1 "checked" onClick="return removePrimaryCategory('+row+');" />'+val1;
        if(row==0){
                rowno=0;
                column1++;
        }
        else{
                column2++;
                rowno=1;
        }
        row++;
    
}


//----------------------------------------------------------------Show selected secondary categories-----------------------------------------
function selectSecodaryCategory(){
       
        val=document.getElementById('p_category');
        primval=val.options[val.selectedIndex].text;
        
        val2=document.getElementById('display_category');
        secondary_val=val2.options[val2.selectedIndex].text;
        
        for(i=0;i<2;i++){
                
                if(myArray[i][0]==primval && column<4){
                        
                        if(i==0){
                                myArray[0][column1]=secondary_val;
                                second_val=myArray[0][column1];
                                var col=column1;
                                column1++;
                        }
                        else{        
                                myArray[1][column2]=secondary_val;
                                second_val=myArray[1][column2];
                                var col=column2;
                                column2++;
                        }
                        column++;
                      
                        document.getElementById('secondcat'+i).innerHTML+='<li><input type="checkbox" "checked" onClick="return removeSecondaryCategory('+row+','+col+');" />'+second_val+'</li>';
                        
                }
        }
        //alert(column1+column2+column);
        /*
        alert("COLUMN"+column);
        myArray[row][column] = val1;
        
        
        
        //------------
         var element=document.getElementById('display_category');
        var val=element.options[element.selectedIndex].value;
        if(val=="Others"){
                document.getElementById('othercategory').style.display = 'block';
                document.getElementById('category1').style.display = 'none';
        }
        else
                document.getElementById('category1').style.display = 'block';
        */

}

//---------------------------------------------------Remove primary category if unchecked after checked--------------------------------------------------------
/*function removePrimaryCategory(rowno){
        alert(rowno);
        row=row-1;
        if(rowno==0){
                document.getElementById('primecat'+ rowno).innerHTML = '';
                myArray[0]=myArray[1];
                alert(myArray[0][1]);
        }
        document.getElementById('secondcat'+ rowno).innerHTML = '';
        //column1=0;
        column--;
}
*/
//---------------------------------------------------Remove secondary category if unchecked after checked--------------------------------------------------------
function removeCategory2(rowno,colno){
       
       
        myArray[rowno][colno]="";
        document.getElementById('secondcat'+colno).innerHTML = '';
        column2--;
        
        //return(row--);
}

//------------------------------------------------Get Date in Standard Format in the Display Form------------------------------------------------------


//mridu_start_28thfeb

/**********************Add New Secondary Category*************************/
var stack1=new Array('prime0sec0','prime0sec1','prime0sec2','prime0sec3','prime0sec4');
var stack2=new Array('prime1sec0','prime1sec1','prime1sec2','prime1sec3','prime1sec4');
function addNewCategory(new_num){
    
        //document.getElementById("prime"+new_num+"sec").style.display='block';
        if(new_num==0 && sec1<5){
                for(all_trav=0;all_trav<5; all_trav++){
                        //document.getElementById('prime0sec'+all_trav).style.display='block';
                        if(stack1[all_trav]!='t' && document.getElementById('prime0sec'+all_trav).innerHTML ==''){
                                stack1[all_trav]="t";
                                var idname='prime0'+'sec'+all_trav;
                                document.getElementById(idname).innerHTML='<input name="'+idname+'" type="text" class="input" /><a href="#avc" onclick="removeDiv(\''+idname+'\','+new_num+','+all_trav+')">Remove</a>';
                                sec1++;
                                break;
                        }
                }
        }
        if(new_num==1 && sec2<5){
                
                for(all_trav=0;all_trav<5; all_trav++){
                        //document.getElementById('prime1sec'+all_trav).style.display='block';
                        if(stack2[all_trav]!='t' && document.getElementById('prime1sec'+all_trav).innerHTML ==''){
                                stack1[all_trav]="t";
                                var idname='prime1'+'sec'+all_trav;
                              
                                document.getElementById(idname).innerHTML='<input name="'+idname+'" type="text" class="input" /><a href="#avc" onclick="removeDiv(\''+idname+'\','+new_num+','+all_trav+')">Remove</a>';
                                sec2++;
                                break;
                        }
                }
        }
        //document.getElementById('new'+new_num).style.display = 'block';
}
function removeDiv(divnum, new_num,rermove_num){
        ss=window.confirm("Click OK to delete the Secondary Category. Click Cancel to stop.");
        if(ss){
                if(new_num==0){
                        document.getElementById(divnum).innerHTML='';
                        stack1[rermove_num]='divnum';
                        sec1--;
                }
                if(new_num==1){
                        document.getElementById(divnum).innerHTML='';
                        stack2[rermove_num]='divnum';
                        sec2--;
                }
        }
}

//mridu_end_28thfeb
/*mriduStart5thMarch
*Display states according
*to country
*in the right side
*/
//-- this is for the right side li state id --
var statebgprev='l';
var allstatebgprev='m';

var continentprev=''

var country;
var state;
var city;
function startAjaxCountryInTheRight(link,id,type,name){
    //country='<a href="#">'+name+'</a>';
    country=name;
    
    if(type=='s'){
    x=name;
      setInnerHTMLById("pre_country_arrow"," > ");
    document.getElementById("countryName").innerHTML= country;
    document.getElementById("countryName").onclick=link.onclick;
    setInnerHTMLById("pre_state_arrow","");
    setInnerHTMLById("pre_city_arrow","");
    document.getElementById("stateName").innerHTML="";
    document.getElementById("cityName").innerHTML="";
    document.getElementById("pri_category").innerHTML="";
    document.getElementById("sec_category").innerHTML="";
    document.getElementById("countryName").innerHTML= country;
    document.getElementById("countryName").onclick=link.onclick;
      
    }
    
    
    //-- this is for the right side li state id --
    statebgprev='l';
    allstatebgprev='m';
    if(type=='c'){
	document.getElementById("countryName").innerHTML= "";
	document.getElementById("continentName").onclick=link.onclick;
	document.getElementById("continentName").innerHTML= country;
	setInnerHTMLById("pre_country_arrow","");
	setInnerHTMLById("pre_state_arrow","");
	setInnerHTMLById("pre_city_arrow","");
	document.getElementById("stateName").innerHTML="";
	document.getElementById("cityName").innerHTML="";
	document.getElementById("pri_category").innerHTML="";
	document.getElementById("sec_category").innerHTML="";
	
	document.getElementById("cityName").innerHTML="";
	document.getElementById("pri_category").innerHTML="";
	document.getElementById("sec_category").innerHTML="";
        var cont="conteinent"+continentprev;
        var licont="liconteinent"+continentprev;
        
        if(continentprev!=''){
            document.getElementById(cont).className='';
            document.getElementById(licont).className='';
        }
    
        document.getElementById("conteinent"+id).className='a';
        document.getElementById("liconteinent"+id).className='drop';
        continentprev=id;
    }
    var xmlHttp=ajaxFunction();
    xmlHttp.open("GET","ajax_country.php?val="+id+"&type="+type,true);
    xmlHttp.onreadystatechange=function (){handleCountryAjax(xmlHttp,type);};
    xmlHttp.send(null);
}
//--------------------------------------------------------Sub function under startAjaxCity()---------------------------------------------------------
function handleCountryAjax(xmlHttp,type){
        if(xmlHttp.readyState==1){
		
                document.getElementById("country_state").innerHTML="<img src='images/loader.gif' width='16' height='16' border='0' align='absmiddle'><br/>Loading, Please Wait ...";
	}
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
                        var reply=new Array();
			reply=xmlHttp.responseText;
			document.getElementById("country_state").innerHTML=reply;
			if(type=='s')
			setInnerHTMLById("label_country","States");
			else if(type=='c')
			setInnerHTMLById("label_country","Countries");
		}
	}
                
   
}
/*mriduStart7thmarch
*/

function startAjaxCityInBase(link,id,name){
  //  state='&nbsp;>&nbsp;<a href="#">'+name+'</a>';
    state=name;
    setInnerHTMLById("pre_state_arrow"," > ");
    document.getElementById("stateName").innerHTML=state;
    document.getElementById("stateName").onclick=link.onclick;
    setInnerHTMLById("pre_city_arrow","");
    document.getElementById("cityName").innerHTML="";
    var xmlHttp=ajaxFunction();
    if(statebgprev!='l')
        document.getElementById(statebgprev).className='l';
    if(allstatebgprev!='m')
        document.getElementById(allstatebgprev).className='m';
        
    statebgprev="statebg"+id;
    var statebg="statebg"+id;
    
    allstatebgprev="allstatebg"+id;
    var allstatebg="allstatebg"+id;
    
    
    document.getElementById(statebg).className='a';
    document.getElementById(allstatebg).className='drop';
        
    xmlHttp.open("GET","ajax_cities.php?val="+id,true);
    xmlHttp.onreadystatechange=function (){handleCity(xmlHttp,name);};
    xmlHttp.send(null);
}


function handleCity(xmlHttp,name){
        
        if(xmlHttp.readyState==1){
		
                document.getElementById("country_state").innerHTML="<img src='images/loader.gif' width='16' height='16' border='0' align='absmiddle'><br/>Loading, Please Wait ...";
	}
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
                        var reply=new Array();
			reply=xmlHttp.responseText;
			document.getElementById("country_state").innerHTML=reply;
			setInnerHTMLById("label_country","Cities");
		}
	}
                
   
}


//---This function is for diplay the map when on select a Country,
//---State, City and Zip from Add and edit event
function startAjaxMap(){
    
    var xmlHttp=ajaxFunction();
    index1=document.getElementById('country_comboId');
    country=index1.options[index1.selectedIndex].text;
    
    
    index2=document.getElementById('state_comboId');
    state=index2.options[index2.selectedIndex].text;
   
    
    index3=document.getElementById('city_comboId');
    city=index3.options[index3.selectedIndex].text;
    
    zip=document.addevent.zip.value;
    xmlHttp.open("GET","ajax_map_info.php?country="+country+"&state="+state+"&city="+city+"&zip="+zip,true);
    xmlHttp.onreadystatechange=function (){handleMap(xmlHttp);};
    xmlHttp.send(null);
}

function handleMap(xmlHttp){
    
    if(xmlHttp.readyState==4){
        if(xmlHttp.status==200){
            var reply=new Array();
            reply=xmlHttp.responseText;
            
            if(reply !='N'){
                lat_lng=reply.split("|");
                
                latitude=lat_lng[0];
                longitude=lat_lng[1];
                
                initialize();
            }
            
        }
    }
}
function startAjaxCategoryInTheLeft(id,pm_name){
    var country=getInnerHTMLById('countryName');
    var state=getInnerHTMLById('stateName');
    var city=getInnerHTMLById('cityName');
    pm_name=pm_name.replace(/&/, "%26");
    var xmlHttp=ajaxFunction();
    xmlHttp.open("GET","ajax_cat.php?val="+id+"&pm_name="+pm_name+"&country="+country+"&state="+state+"&city="+city,true);
    xmlHttp.onreadystatechange=function (){handleCat(xmlHttp,id,country);};
    xmlHttp.send(null);
}

function handleCat(xmlHttp,id,country){
	
	if(country=='')
	{
		document.getElementById("displayevent").innerHTML='<div  style="font-weight:bold;color:#FE7800;text-align:center;font-size:17px;width:100%;background-color:#CCCCFF; border:1px solid #CC66FF;">Please choose one country first.</div>';
	}
	else
	{
		if(xmlHttp.readyState==1){
			 
			 document.getElementById("sec"+id).innerHTML="<img src='images/loader.gif' width='16' height='16' border='0' align='absmiddle'><br/>Loading, Please Wait ...";
		 }
		 if(xmlHttp.readyState==4){
			 if(xmlHttp.status==200){
				 var reply=new Array();
				 var category_mid_val=new Array();
				 reply=xmlHttp.responseText;		
				 //category_mid_val = reply.split(">|<");
				 //document.getElementById("sec"+id).innerHTML=category_mid_val[0];
				 document.getElementById("sec"+id).innerHTML=reply;
				 //document.getElementById("displayevent").innerHTML=category_mid_val[1];
				 
			 }
		 }
	}
}




/*----------- This is for the Disaster Relief Posting ---*/
//var disaster_flag=0;
var replymsg='';
var all_user='';
var textflag=0;
function sendDisasterRelief(){
    var country=getInnerHTMLById('countryName');
    var state=getInnerHTMLById('stateName');
    var city=getInnerHTMLById('cityName');
    var content=document.getElementById('dfcontent').value;
    content =content.replace('&','%26');
    var url='type='+menu;
	if(country !='')
	    url+='&country='+country;
	if(state !='')
	    url+='&state='+state;
	if(city !='')
	    url+='&city='+city;
    if(content=='')
	alert("Please Insert the Text");
    else if(content.length>140)
	alert("Insert text not execed 140 characters");
    else{
        disaster_flag=1;
	var xmlHttp=ajaxFunction();
        
        //content=content.replace(replymsg, all_user);
        //content=content.replace(replymsg, '%3C font color="red" %3E'+all_user+'%3C%2F font %3E');
        //alert(replymsg);
        //alert(all_user);
        //content=content.replace(replymsg, '%3C span style="color:#FE7700;" %3E'+all_user+'%3C%2F span %3E');
	url+='&content='+content;
        document.getElementById('dfcontent').value='';
	xmlHttp.open("GET","disaster_relief.php?"+url,true);
	xmlHttp.onreadystatechange=function (){handleDisasterRelief(xmlHttp, 1);};
	xmlHttp.send(null);
        disaster_flag=0;
    }
}
function handleDisasterRelief(xmlHttp, noo){
    //var xhrTimeout=setTimeout("ajaxTimeout(\""+xmlHttp+"\");",5000);
    if(xmlHttp.readyState==1){
        if(noo == 1){
                if(replymsg=='' || (trim(replymsg) != trim(document.getElementById('dfcontent').value))){
                        document.getElementById('reply_msg').style.display='block';
                        document.getElementById("reply_msg").innerHTML="<img src='images/loader.gif' width='16' height='16' border='0' align='absmiddle'><br/>Loading, Please Wait ...";
                        textflag=0;
                }
        }
    }
    else if(xmlHttp.readyState==4){
	    if(xmlHttp.status==200){
                    var reply=new Array();
		    reply=xmlHttp.responseText;
		    document.getElementById("disaster_content").innerHTML='';
                    document.getElementById("disaster_content").innerHTML=reply;
                    disaster_flag=0;
                    
                    if(document.getElementById('dfcontent').value !='' && trim(replymsg) == trim(document.getElementById('dfcontent').value)){
                    //if(trim(replymsg) !='' && trim(replymsg) == trim(document.getElementById('dfcontent').value)){
                        document.getElementById('changeImage').setAttribute('src','images/replybbut.png');
                        //document.getElementById('reply_msg').innerHTML='';
                        //document.getElementById('reply_msg').style.display='none';
                    }
                    else if(textflag !=1){
                        document.getElementById('changeImage').setAttribute('src','images/submitbut.png');
                        document.getElementById('reply_msg').innerHTML='';
                        document.getElementById('reply_msg').style.display='none';
                        f=document.getElementById('char_count');
                        f.innerHTML="140";
                        replymsg='';
                        all_user='';
                    }
            }
    }
}
function ajaxTimeout(){
    //alert("hi");
   xmlHttpDis.abort();
   disaster_flag=0;   
}
var xmlHttpDis='';
function readMsgWithTime()
{
  //var req_reply = "index.php?menu="+menu;
  setTimeout("ajaxTimeout()", 19999);
  readMsg();
  setTimeout("readMsgWithTime()",20000);
}
function readMsg(){
    if(disaster_flag==0){
        disaster_flag=1;
        var country=getInnerHTMLById('countryName');
        var state=getInnerHTMLById('stateName');
        var city=getInnerHTMLById('cityName');
        //var content=document.getElementById('dfcontent').value;
        var url='type='+menu;
            if(country !='')
                url+='&country='+country;
            if(state !='')
                url+='&state='+state;
            if(city !='')
                url+='&city='+city;
	if(page_num!='')
	    url+='&page='+page_num;
	else
            url+='&page=1';
	    
        xmlHttpDis=ajaxFunction();
        //url+='&content='+content;
        xmlHttpDis.open("GET","disaster_relief.php?"+url,true);
        xmlHttpDis.onreadystatechange=function (){handleDisasterRelief(xmlHttpDis, 0);};
        xmlHttpDis.send(null);
        
    }
}
function ajax_delete_msg(id){
    
        var request;
        var country=getInnerHTMLById('countryName');
        var state=getInnerHTMLById('stateName');
        var city=getInnerHTMLById('cityName');
        var url='type='+menu;
            if(country !='')
                url+='&country='+country;
            if(state !='')
                url+='&state='+state;
            if(city !='')
                url+='&city='+city;
        
        
        request=window.confirm("Are you Sure You Want To Delete Message?Click Cancel to stop .");
        if(request){
            
            xmlHttp=ajaxFunction();
            //xmlHttp.open("GET","delete_disaster_relief.php?id="+id,true);
            xmlHttp.open("GET","disaster_relief.php?id="+id+"&"+url,true);
            xmlHttp.onreadystatechange=function (){handleDeleteDisasterRelief(xmlHttp);};
            xmlHttp.send(null);
        }
        
    }
function handleDeleteDisasterRelief(xmlHttp){
    
    
    if(xmlHttp.readyState==1){
        	document.getElementById('reply_msg').style.display='block';
                document.getElementById("reply_msg").innerHTML="<img src='images/loader.gif' width='16' height='16' border='0' align='absmiddle'><br/>Loading, Please Wait ...";
    }
    else if(xmlHttp.readyState==4){
	    if(xmlHttp.status==200){
                    
		    var reply;
		    reply=xmlHttp.responseText;
                    document.getElementById("disaster_content").innerHTML='';
		    document.getElementById("disaster_content").innerHTML=reply;
                    document.getElementById('reply_msg').style.display='none';
                    document.getElementById("reply_msg").innerHTML="";
                    replymsg='';
                    all_user='';
	    }
    }
}
function countDisaster(num){
    if(num >140){
            document.getElementById('dfcontent').value = document.getElementById('dfcontent').value.substring(0,140);
            document.getElementById('char_count').value = 0;
            alert("Maximum allowable size is 140 character");
    }
    else if(num < replymsg.length){
        document.getElementById('changeImage').setAttribute('src','./images/submitbut.png');
        document.getElementById('reply_msg').innerHTML='';
        document.getElementById('reply_msg').style.display='none';
        replymsg='';
        all_user='';
    }
}

function replyMsgFunction(username){
        var nextusername='@'+username+' ';
        var str = replymsg.split(' ');
        var flagreply=0;
        textflag=1;
        //disaster_flag=1;
        if(str.length==1){
                if(trim(replymsg) != trim(nextusername)){
                        document.getElementById('dfcontent').value = replymsg+'@'+username;
                        all_user+=' '+username;
                }
                else{
                        document.getElementById('dfcontent').value = '@'+username;
                        all_user = username;
                }
        }
        else{
                for(var i=0;i<str.length;i++){
                        if(trim(str[i]) == trim(nextusername)){
                                flagreply=1;
                        }
                }
                if(flagreply!=1){
                        document.getElementById('dfcontent').value = replymsg+'@'+username;
                        all_user=trim(all_user)+', '+username;
                }
        }
        document.getElementById('dfcontent').focus();
        replymsg = document.getElementById('dfcontent').value;
        document.getElementById('changeImage').setAttribute('src','images/replybbut.png');
        document.getElementById('reply_msg').innerHTML='Reply to '+all_user+':';
        document.getElementById('reply_msg').style.display='block';
        val=document.getElementById('dfcontent').value.length;
        //alert(val);
        //countDisaster(val);
        f=document.getElementById('char_count');
        f.innerHTML= 140-document.getElementById('dfcontent').value.length;
}
function refreshPage(){
    var country=getInnerHTMLById('countryName');
    var state=getInnerHTMLById('stateName');
    var city=getInnerHTMLById('cityName');
    var url='';
    var redirecturl='';
	if(country !='')
	    url+='&country='+country;
	if(state !='')
	    url+='&state='+state;
	if(city !='')
	    url+='&city='+city;
    if(menu == 'happening_now'){
	redirecturl="index.php?menu=happening_now"+url;
	window.location=redirecturl;
    }
    else if(menu == 'local_help'){
	redirecturl="index.php?menu=local_help"+url;
	window.location=redirecturl;
    }
    else if(menu == 'open_now'){
	redirecturl="index.php?menu=open_now"+url;
	window.location=redirecturl;
    }
}