function ajaxFunction(){
	var ajaxRequest;

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				//browsers all not support, rare case
				alert("Your browser broke!");
				return false;
			}
		}

	}
	return ajaxRequest;
}

function openVisitorReply(id, user, user2, securitytoken, userid) {
	document.getElementById(id).style.display = 'block';
    if(document.getElementById(id) != null)
	document.getElementById(id).innerHTML = "<iframe name=\"iframe"+id+"\" scrolling=\"no\" align='center' style=\"border: 0;\" id=\"iframe"+id+"\" src=\"./visitorReply/visitorReply.php?u="+user+"&u2="+user2+"&securitytoken="+securitytoken+"&userid="+userid+"&id="+id+"\" width=\"100%\" height=\"100\"></iframe>";


	
}


function closeVisitorReply(id){
		
		document.getElementById(id).style.display = 'none';

}




function phpEncode(D){D=escape(D.toString()).replace(/\+/g,"%2B");var B=D.match(/(%([0-9A-F]{2}))/gi);if(B){for(var C=0;C<B.length;C++){var A=B[C].substring(1,3);if(parseInt(A,16)>=128){D=D.replace(B[C],"%u00"+A)}}}D=D.replace("%25","%u0025");return D}


function sendVisitorReply(id){
	htmlRequest = ajaxFunction();
	if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
		alert ("Browser does not support HTTP Request");
		return;
	} 

	
	
	iframe = parent.document.getElementById('iframe'+id);
	message = document.vbform.message.value;
	u = document.vbform.u.value;
	u2 = document.vbform.u2.value;
	securitytoken = document.vbform.securitytoken.value; 
	userid = document.vbform.loggedinuser.value;
	
	
	if(message == "" || message == "NULL" || message.length < 10){
		alert('You need at least 10 characters!');
		return;
	}
	
	
	htmlRequest.onreadystatechange = function(){
		if(htmlRequest.readyState == 4){
		    iframe.style.display = 'none';
		}
	}
	
	htmlRequest.open('POST', '../visitormessage.php?do=message');
	htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	htmlRequest.send('message='+phpEncode(message)+'&u='+u+'&u2='+u2+'&securitytoken='+securitytoken+'&loggedinuser='+userid+'&fromquickcomment=1&s=&do=message&ajax=1'); 
     
	 /* we show the waiting message, and hide the textarea... the state change function will hide all */
	document.getElementById('visitorReply'+id).style.display = 'none';
	document.getElementById('sending'+id).style.display = 'block';
   } 

