function xmlhttpPost(strURL) {
	//alert(strURL);
	//updatepage1("Searching, please wait<br><br><img src=images/loading.gif><br><br>");
	
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
       self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }

	var tosend = getquerystring();

	if(tosend != 0)
	{
		document.getElementById("pictcha").innerHTML = "Please wait<br><br><img src='http://utyp.net/images/loading.gif'>";
		self.xmlHttpReq.send(tosend);
	}

}

function xmlhttpPost2(strURL) {
	//alert("xmlhttpPost2"+strURL);
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
       self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage2(self.xmlHttpReq.responseText);
        }
    }
	self.xmlHttpReq.send('');
}


function getquerystring() {
    var form     = document.forms['form1'];
	if(form.name.value == "")
	{
		alert('name is missing');
		return 0;
	}
	else
	{
		if(form.comment.value == "")
		{
			alert('comment is missing');
			return 0;
		}
		else
		{
			qstr = 'lg=' + form.ulg.value + '&name=' + form.name.value + '&website=' + form.website.value + '&comment=' + form.comment.value.replace(/\n/g, "<BR>") + '&input=' + form.input.value;  // NOTE: no '?' before querystring
			return qstr;
		}
	}
}

function updatepage(str){
    document.getElementById("pictcha").innerHTML = str;
	var patt1 = /^<br>OK/g;

	if(str.match(patt1))
	{
		document.getElementById("formend").innerHTML = "";
		xmlhttpPost2("pictcha-sample.php?ajax=1&ajax2=1");
	}
	else
	{
		//alert('yooo');
	}

}

function updatepage2(str){
    document.getElementById("commentlist").innerHTML = str;
}


function openFrameless(){

var windowW=400 // wide
var windowH=500 // high

// set the screen position where the popup should appear

var windowX = (screen.width-windowW)/2;
var windowY = (screen.height-windowH)/2;

// set the url of the page to show in the popup

var urlPop = "pictcha-help.html"

// set the title of the page

var title =  "PICTCHA Form Spam Protection - HELP"

// set this to true if the popup should close
// upon leaving the launching page; else, false

var autoclose = true

	s = "width="+windowW+",height="+windowH;
var beIE = document.all?true:false
  if (beIE){
    NFW = window.open("","popFrameless",'toolbar=0,status=0,filemenu=0,scrolling=0,left=0,top=0,'+s) 
    NFW.blur()
    window.focus()       
    NFW.resizeTo(windowW,windowH)
    NFW.moveTo(windowX,windowY)
    var frameString=""+
"<html>"+
"<head>"+
"<title>"+title+"</title>"+
"</head>"+
"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
"<frame name='top' src='"+urlPop+"' scrolling=auto>"+
"<frame name='bottom' src='about:blank' scrolling='no'>"+
"</frameset>"+
"</html>"
    NFW.document.open();
    NFW.document.write(frameString)
    NFW.document.close()
  } else {
    NFW=window.open(urlPop,"popFrameless",'toolbar=0,status=0,filemenu=0,scrolling=0,left=0,top=0,'+s) 
    NFW.blur()
    window.focus() 
    NFW.resizeTo(windowW,windowH)
    NFW.moveTo(windowX,windowY)
  }   
  NFW.focus()   
  if (autoclose){
    window.onunload = function(){NFW.close()}
  }
}