var req;

function alphanumeric(alpha)
{
 return true;
}

function processReqChange()
{
    // only if req shows "complete"
//	document.addurl.dyn.value="Wait server...";
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
	document.getElementById("ajresults").innerHTML = req.responseText;
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

function processReqChangeEmail()
{
    // only if req shows "complete"
//	document.addurl.dyn.value="Wait server...";
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
	document.getElementById("ajresultsemail").innerHTML = req.responseText;
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

function checkName(input, response)
{
	var myRegExp = /h/;
	var matchPos1 = input.search(myRegExp);
	if (input.length < 12)
	{
		hidediv('ajresults');
		return;
	}
	else
	{
		showdiv('ajresults');
if (!alphanumeric(input)) { document.getElementById("url").style.backgroundColor = '#FED6D9';
	 	document.frmRegistration.username.focus();
		message.className = 'error';}
  if (response != ''){

    // Response mode
    message = document.getElementById('nameCheckFailed');
    if (response == 0){
	 	document.getElementById("url").style.backgroundColor = '#AAFFA8';
    	message.className = 'hidden';

    }else{
	 	document.getElementById("url").style.backgroundColor = '#FED6D9';
	 	document.frmRegistration.username.focus();
		message.className = 'error';
    }

  }else{
    // Input mode

    var url  = 'http://linkcentre.com/addurl/sites.php?url=' + input;
    loadXMLDoc(url);

  }
}
}


function checkCat(input, response)
{
	var myRegExp = /h/;
	var matchPos1 = input.search(myRegExp);
	if (input.length < 2)
	{
		hidediv('ajresults');
		return;
	}
	else
	{
		showdiv('ajresults');
if (!alphanumeric(input)) { document.getElementById("category").style.backgroundColor = '#FED6D9';
	 	document.frmRegistration.username.focus();
		message.className = 'error';}
  if (response != ''){

    // Response mode
    message = document.getElementById('catCheckFailed');
    if (response == 0){
	 	document.getElementById("category").style.backgroundColor = '#AAFFA8';
    	message.className = 'hidden';

    }else{
	 	document.getElementById("category").style.backgroundColor = '#FED6D9';
	 	document.frmRegistration.username.focus();
		message.className = 'error';
    }

  }else{
    // Input mode

    var url  = 'http://linkcentre.com/cats.php?cats=' + input;
    loadXMLDoc(url);

  }
}
}


function checkUserName(input, response)
{
	var myRegExp = /h/;
	var matchPos1 = input.search(myRegExp);
	if (input.length < 5)
	{
		// hidediv('ajresults');
		showdiv('ajresults');
		document.getElementById('ajresults').innerHTML = '<img src=\'/images/exclamation.png\' align=\'left\' />&nbsp;<span style=\'color:#cc0000; font-weight:bold;\'>Sorry,</span> minimum of 5 characters';
		return;
	}
	else
	{
		showdiv('ajresults');
if (!alphanumeric(input)) { document.getElementById("user").style.backgroundColor = '#FED6D9';
	 	document.frmRegistration.username.focus();
		message.className = 'error';}
  if (response != ''){

    // Response mode
    message = document.getElementById('nameCheckFailed');
    if (response == 0){
	 	document.getElementById("user").style.backgroundColor = '#AAFFA8';
    	message.className = 'hidden';

    }else{
	 	document.getElementById("user").style.backgroundColor = '#FED6D9';
	 	document.frmRegistration.username.focus();
		message.className = 'error';
    }

  }else{
    // Input mode

    var url  = 'http://linkcentre.com/addurl/users.php?id=' + input;
    loadXMLDoc(url);

  }
}
}

function checkEmail(input, response)
{
	var myRegExp = /h/;
	var matchPos1 = input.search(myRegExp);
	if (input.length < 1)
	{
		// hidediv('ajresults');
		showdiv('ajresultsemail');
		document.getElementById('ajresultsemail').innerHTML = '<img src=\'/images/exclamation.png\' align=\'left\' />&nbsp;<span style=\'color:#cc0000; font-weight:bold;\'>Sorry,</span> minimum of 5 characters';
		return;
	}
	else
	{
		showdiv('ajresultsemail');
if (!alphanumeric(input)) { document.getElementById("email").style.backgroundColor = '#FED6D9';
	 	document.frmRegistration.username.focus();
		message.className = 'error';}
  if (response != ''){

    // Response mode
    message = document.getElementById('emailCheckFailed');
    if (response == 0){
	 	document.getElementById("email").style.backgroundColor = '#AAFFA8';
    	message.className = 'hidden';

    }else{
	 	document.getElementById("email").style.backgroundColor = '#FED6D9';
	 	document.frmRegistration.email.focus();
		message.className = 'error';
    }

  }else{
    // Input mode

    var url  = 'http://linkcentre.com/addurl/email.php?id=' + input;
    loadXMLDocEmail(url);

  }
}
}

function loadXMLDoc(url)
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function loadXMLDocEmail(url)
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangeEmail;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function showdiv(id) {
	//safe function to show an element with a specified id

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
