/* START AJAX FUNCTIONS START AJAX FUNCTIONS START AJAX FUNCTIONS START AJAX FUNCTIONS */
var xmlhttp;
function loadXMLDoc(url){
    if (window.XMLHttpRequest){// code for Mozilla, etc.
      xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=xmlhttpChange;
      //alert(url);
      xmlhttp.open("GET",url,true);
      xmlhttp.send(null);
    }else if (window.ActiveXObject){// code for IE
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp){
            xmlhttp.onreadystatechange=xmlhttpChange;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        }
    }
}

function postXMLDoc(url,formname){
    if (window.XMLHttpRequest){// code for Mozilla, etc.
      xmlhttp=new XMLHttpRequest();
        if (xmlhttp){
            var fields = new Array();
            if(formname){
                var ajax = formname;
            }
            //alert(formname);
            //loop through form elements and retrieve field NAMEs and Values
            for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
                // join them into a string.
                eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
            }
            elem = 'errors';
            //sendf looks like "username=myusername&password=mypass"
            var sendf = fields.join('&');
            
            
            xmlhttp.open("POST", url, true);
            xmlhttp.onreadystatechange=xmlhttpChange;
            xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//          xmlhttp.setRequestHeader('Content-Type', 'multipart/form-data');
            xmlhttp.send(sendf);                
        }
    }else if (window.ActiveXObject){// code for IE
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp){
            var fields = new Array();
            if(formname){
                var ajax = formname;
            }
            //loop through form elements and retrieve field NAMEs and Values
            for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
                // join them into a string.
                eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
            }
            elem = 'errors';
            //sendf looks like "username=myusername&password=mypass"
            var sendf = fields.join('&');
            
            
            xmlhttp.open("POST", url, true);
            xmlhttp.onreadystatechange=xmlhttpChange;
            xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//          xmlhttp.setRequestHeader('Content-Type', 'multipart/x-www-form-urlencoded');

            
            xmlhttp.send(sendf);                
        }
    }
}



function xmlhttpChange(){
    //alert(xmlhttp.status);
    if (xmlhttp.readyState==4){// if xmlhttp shows "loaded"
        if (xmlhttp.status==200){// if "OK"
            if(xmlhttp.responseText != 'exit'){
                var temp = new Array();
                //alert(xmlhttp.responseText);
                temp = xmlhttp.responseText.split('|');
                for(i = 0; i <= temp.length; i = i + 2){
                    if(temp[i]){
                        if(temp[i] == 'script'){
                            eval(temp[(i+1)]);
                        }else{
                            //alert(temp[i]);
                            document.getElementById(temp[i]).innerHTML= temp[(i+1)];    
                        }     
                    }   
                }
            }
        }else{
            alert("Problem retrieving data Comment Data")
        }
    }
}


function click_post(form_name){
    postXMLDoc('/inc/ajax.inc.php',form_name);
}
function click_get(query_str){
    loadXMLDoc('/inc/ajax.inc.php' + query_str);
}
/* END AJAX FUNTIONS END AJAX FUNTIONS END AJAX FUNTIONS END AJAX FUNTIONS  */

function remove_onclick_function(id){
    document.getElementById(id).onclick = function() { eval("void(0)") };
}


/* Show Hide Function */
function hide_show(id){
    if(document.getElementById(id)){
        var it = document.getElementById(id);
    }
   if(it.style.visibility != 'hidden'){
        it.style.display = 'none';
        it.style.visibility = 'hidden';
   }else{
        it.style.display = 'block';
        it.style.visibility = 'visible';
   }
}
/* End of Show Hide Function */

/* EVENTS SEND TO FRIEND FORM VALIDATION */
/*
function check_da_form(formname){
    if((document.formname.send_name.value != '') && (document.formname.send_name.value != document.formname.send_name.defaultValue)){
        if((document.formname.send_email.value != '') && (document.formname.send_email.value != document.formname.send_email.defaultValue)){
             if((document.formname.rec_name.value != '') && (document.formname.rec_name.value != document.formname.rec_name.defaultValue)){
                if((document.formname.rec_email.value != '') && (document.formname.rec_email.value != document.formname.rec_email.defaultValue)){
                document.formname.submit();
            }else{
                alert('Please supply an Email address of your friend');
                return false;
            }
        }else{
            alert('Please supply the Name of your friend');
            return false;
        }
    }else{
        alert('Please supply your Email address');
        return false;
        }
    }else{
        alert('Please supply your Name');
        return false;
    }
}
*/
/* END OF EVENTS SEND TO FRIEND FORM VALIDATION */