// Ajax
var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE
function xhrRequest(type) {
	if (!type) {
 		type = 'html';
	}
 	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
 	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
 	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
 	var xhrsend = xi.length; 
 	
 	// GO THROUGH AVAILABLE xi VALUES
 	for (var i=0; i<xi.length; i++) {
 		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
 		if (xi[i] == 1) {
 			xi[i] = 0;
 			xhrsend = i;
 			break;
 		}
 	}
 	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
 	xi[xhrsend] = 0;
	
 	// SET UP THE REQUEST
 	if (window.ActiveXObject) {
 		try {
 			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
 		} catch (e) {
 			try {
 				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
 			} catch (e) {}
 		}
 	}
	else if (window.XMLHttpRequest){
 		xhr[xhrsend] = new XMLHttpRequest();
 		if (xhr[xhrsend].overrideMimeType) {
 			xhr[xhrsend].overrideMimeType('text/' + type);
 		}
 	}
	else{
		alert('Your Browser does not support AJAX!');
		return false;
	}
 	return (xhrsend);
}

function fcn(url, div, status_text, reqType){
 	var xhri = xhrRequest('html');
	var areal = Math.random() + "";
	var rnd = areal.substring(2,8);

	try{
		xhr[xhri].open('POST', url, true);
		xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhr[xhri].onreadystatechange = function() {
 		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			document.getElementById(div).innerHTML = xhr[xhri].responseText;
 			xi[xhri] = 1;
 			xhr[xhri] = null;
 		}else{
			document.getElementById(div).innerHTML = status_text;
		}
		};
		xhr[xhri].send('&rnd='+rnd);
	}
	catch(e){
		xhr[xhri].open('GET', url, true);
		xhr[xhri].onreadystatechange = function() {
 		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			document.getElementById(div).innerHTML = xhr[xhri].responseText;
 			xi[xhri] = 1;
 			xhr[xhri] = null;
 		}else{
			document.getElementById(div).innerHTML = status_text;
		}
		};
		xhr[xhri].send(null);
	}
}

function numbersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if (unicode!=9){ //if the key isn't the tab key (which we should allow)
			if (unicode<48||unicode>57) //if not a number
			return false //disable key press
		}
	}
}

function ceknama(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if (unicode!=9){ //if the key isn't the tab key (which we should allow)
			if (unicode!=39){ //if the key isn't the ' key (which we should allow)
				if (unicode!=32){ //if the key isn't the space key (which we should allow)
					if (unicode!=44){ //if the key isn't the coma key (which we should allow)
						if (unicode!=46){ //if the key isn't the dot key (which we should allow)
							if ((unicode<65||unicode>90) && (unicode<97||unicode>122)) //if not a character
							return false //disable key press
						}
					}
				}
			}
		}
	}
}

function cekalnum(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if (unicode!=9){ //if the key isn't the tab key (which we should allow)
			if (unicode!=32){ //if the key isn't the space key (which we should allow)
				if (unicode!=44){ //if the key isn't the coma key (which we should allow)
					if (unicode!=45){ //if the key isn't the - key (which we should allow)
						if (unicode!=46){ //if the key isn't the dot key (which we should allow)
							if ((unicode<97||unicode>122) && (unicode<65||unicode>90) && (unicode<48||unicode>57)) //if not a character
							return false //disable key press
						}
					}
				}
			}
		}
	}
}

function cekusername(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if (unicode!=9){ //if the key isn't the tab key (which we should allow)
			if (unicode!=95){ //if the key isn't the _  key (which we should allow)
				if (unicode!=46){ //if the key isn't the .  key (which we should allow)
					if ((unicode<97||unicode>122) && (unicode<48||unicode>57)) //if not a character
					return false //disable key press
				}
			}
		}
	}
}

function cekemail(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if (unicode!=9){ //if the key isn't the tab key (which we should allow)
			if (unicode!=46){ //if the key isn't the . key (which we should allow)
				if (unicode!=95){ //if the key isn't the _  key (which we should allow)
					if (unicode!=64){ //if the key isn't the@  key (which we should allow)
						if (unicode!=45){ //if the key isn't the@  key (which we should allow)
							if ((unicode<97||unicode>122) && (unicode<48||unicode>57)) //if not a character
							return false //disable key press
						}
					}
				}
			}
		}
	}
}

function ceknotlp(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if (unicode!=9){ //if the key isn't the tab key (which we should allow)
			if (unicode<48||unicode>57) //if not a number
			return false //disable key press
		}
	}
}
