count=0;
empty_message="Burayı doldurman lazım";
function FormSubmit(){
    if (document.getElementById("ff_ad").value=="" || document.getElementById("ff_ad").value==" " || document.getElementById("ff_ad").value==empty_message){
        document.getElementById("ff_ad").value=empty_message;
        document.getElementById("ff_ad").select();
    } else if (document.getElementById("ff_comment_body").value=="" || document.getElementById("ff_comment_body").value==" " || document.getElementById("ff_comment_body").value==empty_message){
        document.getElementById("ff_comment_body").value=empty_message;
        document.getElementById("ff_comment_body").select();
    } else {
        sndReq();  
    }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq() {
/*?post_id='+document.getElementById("ff_post_id").value+'&ad='+document.getElementById("ff_ad").value+'&email='+document.getElementById("ff_email").value+'&website='+document.getElementById("ff_website").value+'&comment_body='+document.getElementById("ff_comment_body").value*/
    http.open('post', 'comments.php',true);
    var sc ='post_id='+document.getElementById("ff_post_id").value+'&ad='+document.getElementById("ff_ad").value+'&email='+document.getElementById("ff_email").value+'&website='+document.getElementById("ff_website").value+'&comment_body='+document.getElementById("ff_comment_body").value+'&recaptcha_response_field='+document.getElementById("recaptcha_response_field").value+'&recaptcha_challenge_field='+document.getElementById("recaptcha_challenge_field").value;
    //alert(sc);
    http.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
    http.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=ISO-8859-9');
    http.setRequestHeader('Content-length', sc.length);
    http.setRequestHeader('Connection', 'close');
    http.onreadystatechange = handleResponse;
    http.send(sc);

    
    
//    http.send(null);
    //setTimeout('sndReq("foo")',1000);
}

function handleResponse() {
//document.getElementById("sayac").innerHTML = http.readyState;

//alert(http.readyState);
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
        
        //alert("<"+response+">");
        update = response.split('|');
        if (update[0]==1){
			
			new_comment_box_html='<div class="comment_container"><div class="comment_date_container" ><div class="month_container">'+update[1]+' </div><div class="month_shadow"></div><div class="day_container">'+update[2]+'</div></div><div class="comment_header"><div class="comment_background"><div class="comment_author"><img src="http://www.gravatar.com/avatar.php?gravatar_id='+update[6]+'&size=40&default=http://hakkikotek.net/images/comment_images/gravatar_default">&nbsp;'+update[3]+'<label> dedi ki</label><br /><br /><div class="comment_open_quata"></div><div class="comment_content" >'+update[4]+'</div>   <div class="comment_close_quata"></div></div><div class="comment_time">'+update[5]+'</div></div><div class="comment_footer"></div></div></div><div id="new_comment_block'+(count+1)+'" style="width:550px; float: left; display:block; clear:both;  margin-left:0px;"></div>';
       
			document.getElementById("new_comment_block"+count).innerHTML = new_comment_box_html; 
			count++;
			document.getElementById("ff_ad").value="";
			document.getElementById("ff_email").value="";
			document.getElementById("ff_website").value="";
			document.getElementById("ff_comment_body").value="";
			document.getElementById("ff_ad").focus();
        } else {
			alert(update[1]);
        }
    }
}


function setFocus(obj_id){
    document.getElementById("ff_"+obj_id).select();
}

function toggle(id){
    ul = "ul_" + id;
    img = "img_" + id;
    ulElement = document.getElementById(ul);
    imgElement = document.getElementById(img);
    if (ulElement){
    if (ulElement.className == 'closed'){
        ulElement.className = "open";
        imgElement.src = "templates/default/images/bullet_open.png";
    }else{
        ulElement.className = "closed";
        imgElement.src = "templates/default/images/bullet_close.png";
        }
    }
}
function fill_form(){
    document.getElementById("ff_ad").value      ="Hakkı Kötek";
    document.getElementById("ff_email").value   ="hunkarozcan@gmail.com";
    document.getElementById("ff_website").value ="http://www.hakkikotek.net";
    document.getElementById("ff_comment_body").focus();
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
function pngfix(){
    if ((version >= 5.5) && (document.body.filters)) 
    {
    //alert("girdim:"+document.images.length);
       for(var i=0; i<document.images.length; i++)
       {
          var img = document.images[i]
          var imgName = img.src.toUpperCase()
		  //alert("girdim: "+imgName );
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText 
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
             img.outerHTML = strNewHTML
             i = i-1
          }
       }
    }
}