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 c_ajax()
	{
		var a=null;
		try {
				a=new ActiveXObject("Msxml2.XMLHTTP")
			}
		catch(b)
			{
			 try{
				 a=new ActiveXObject("Microsoft.XMLHTTP")
				 }
				 catch(c){
							 a=null
						 }
				}
				if(!a&&typeof XMLHttpRequest!="undefined")
					{
						a=new XMLHttpRequest
					}
		return a
	}

function h_ajax(url,method,divid,parameters)
		{
            a_request=c_ajax();

			if(a_request && a_request.readyState!=0)
				{
					a_request.abort()
				}

			if(a_request)
				{                
                        a_request.open(method,url,true);
                        
                    }
                    a_request.onreadystatechange=function()
						{
							if(a_request.readyState==4 && a_request.responseText)
								{
                                   var str=a_request.responseText;
                                   //document.getElementById(divid).innerHTML=str;
								    //alert(divid);
								    document.getElementById(divid).innerHTML=str;
								   //divid.innerHTML=str;
								  
			
								}
						};
					if(method=='POST') {
					   a_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					   a_request.setRequestHeader("Content-length", parameters.length);
					   a_request.setRequestHeader("Connection", "close");
					   }
					a_request.send(parameters);

				}

function getform(origin,mtype){

var formdiv="<div align=\"center\" id=\"response\" style=\"display:block;\">"+
"<form action=\"submitMsg.php\" method=\"post\" name=\"tb_form\" id=\"response_form\">"+
"<br><br><table align=\"center\" cellpadding=\"3\" style=\"color:black;width:500px;border:1px #1F4C6B solid #;background-color:#E5EAEE;\">"+
"<tr><td height=\"10\"></td></tr><tr>"+
"<td class=\"tdName\" style=\"background-color:#;text-align:right;width:100px;vertical-align:top;\">שם</td>"+
"<td class=\"tdinput\" style=\"\" dir=\"rtl\"><input type=\"text\" name=\"name\" id=\"nameid\" ></td>"+
"</tr>"+
"<tr>"+
"<td class=\"tdName\" style=\"background-color:#;text-align:right;width:100px;vertical-align:top;\">אימייל</td>"+
"<td class=\"tdinput\" style=\"\" dir=\"rtl\"><input type=\"text\" name=\"email\" id=\"emailid\" style=\"width:350px;\"></td>"+
"</tr>"+
"<tr>"+
"<td class=\"tdName\" style=\"background-color:#;text-align:right;width:100px;vertical-align:top;\">נושא ההודעה</td>"+
"<td class=\"tdinput\" style=\"\" dir=\"rtl\"><input type=\"text\" name=\"title\" id=\"subjectid\" style=\"width:350px;\">"+
"<input type=\"hidden\" name=\"origin\" id=\"originid\" value=\""+origin+"\">"+
"<input type=\"hidden\" id=\"mtypeid\" name=\"mtype\" value=\""+mtype+"\" />"+
"<input type=\"hidden\" name=\"security_code\" id=\"security_codeid\" value=\"\">"+
"</td>"+
"</tr>"+
"<tr>"+
"<td colspan=\"2\"><textarea name=\"message\" id=\"messageid\" cols=\"100\" rows=\"10\" style=\"width:500px;\" dir=\"rtl\" onKeyDown=\"textCounter(document.tb_form.message,document.tb_form.Len,2000)\" onKeyUp=\"textCounter(document.tb_form.message,document.tb_form.Len,2000)\"></textarea></td>"+
"</tr>"+
"<tr>"+    
"<TD colspan=\"2\"  align=\"center\">"+
"מקסימום&nbsp;<input class=\"Phones\"  readonly type=\"text\" disabled name=\"Len\" size=\"3\" maxlength=\"3\" value=\"2000\">תווים .&nbsp;"+
 "</TD>"+
"</tr>"+
"<tr>"+
"<td colspan=\"2\" style=\"text-align:center;\"><table align=center width=\"55\"><tr><td><input type=\"submit\" name=\"submit\" value=\"שלח\" onmouseover=\"hover(this)\" onmouseout=\"outs(this)\" class=\"Buttonsmal\"></td></tr></table></td>"+
"</tr>"+
"<tr><td colspan=\"2\" style=\"text-align:center;\">"+
"</table>"+
"</form><br></div>";
return(formdiv);

}

function openclose(id){
if(navigator.appName.indexOf("Microsoft") > -1){
var canSee = 'block'
} else {
var canSee = 'table-row';
}
var msgObj = document.getElementById(id);
msgObj.style.display = (msgObj.style.display==canSee)?'none':canSee;

}

function f_response2(id,origin){
var divid = id+'_response';
var msgObj = document.getElementById(divid);
var b = document.getElementById(id+'_add');
var mode="";
if(b.name=='add'){
b.name='close';b.innerHTML='<div align="center">סגור חלון תגובה</div>';
msgObj.innerHTML=getform(origin,0);
//scrollToId(id);
} else {
msgObj.innerHTML = '';
b.name='add';b.innerHTML='<div align="center">הוסף תגובה</div>';
}

}
function addnew(){
var b = document.getElementById('addmsg');
var msgObj = document.getElementById("addnew_response");
if(b.name=='add'){
b.name='close';b.innerHTML='סגור חלון';
msgObj.innerHTML=getform(0,1);
openclose('adddmsgtr');
} else {
msgObj.innerHTML = '';
b.name='add';b.innerHTML='הוסף הודעה';
openclose('adddmsgtr');
}
}

 function getcaptch() {       
      var divid = document.getElementById("idid").value+'_response';
      var poststr = "origin=" + encodeURI( document.getElementById("originid").value ) +
                    "&name=" + encodeURI( document.getElementById("nameid").value )+
					"&email=" + encodeURI( document.getElementById("emailid").value )+
					"&title=" + encodeURI( document.getElementById("subjectid").value )+
					"&mtype=" + encodeURI( document.getElementById("mtypeid").value )+
					"&security_code=" + encodeURI( document.getElementById("security_codeid").value )+
					"&message=" + encodeURI( document.getElementById("messageid").value );

      h_ajax('response2.php','POST',divid, poststr);
	  
   }

 function scrollToId(id){

   var el;
    var msie = ((navigator.appVersion.indexOf("MSIE")!= -1)&&!window.opera)? true : false;
    el=document.getElementById(id);
    if(el!=null){
		var topPos = el.offsetTop;
        if (msie){
          topPos = el.offsetParent.offsetTop+10;
        }
       else{
             topPos +=98;
        }

       window.scrollTo(0,topPos-6);
    }

}

function isLowerThenIE7(){
      var version=getIEVersion();
     if(version<7 && version>-1)
       {
           return true
       }
     else return false ;
}
function getIEVersion(){
   if (navigator.appVersion.indexOf("MSIE")!=-1){
    temp=navigator.appVersion.split("MSIE")
    version=parseFloat(temp[1]);
    return version;
    }
    return -1;
}