var invalidaddress=new Array();
invalidaddress[0]="afsfa";
invalidaddress[1]="fsadfa";
invalidaddress[2]="daef";
invalidaddress[3]="sfasef";
var testresults;
//////////
function Trim(s) 
{

	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
		{
			s = s.substring(1,s.length);
		}

	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
		{
			s = s.substring(0,s.length-1);
		}
	return s;
}
////////////////*
function checkbae(mailadres){
	//if (document.layers||document.getElementById||document.all)
		return checkemail(mailadres);
	//else
	//	return true;
}
function checkemail(mailadres){
	var invalidcheck=0;
	//var str=document.getElementById('txtEmail').value;
	var str = mailadres;
	var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){
		var tempstring=str.split("@");
		tempstring=tempstring[1].split(".");
		for (i=0;i<invalidaddress.length;i++){
			if (tempstring[0]==invalidaddress[i])
				invalidcheck=1;
		}
		if (invalidcheck!=1)
			testresults=true;
		else{
			//alert("Please input a more official email address!")
			testresults=false;
		}
	}
	else{
		//alert("Please input a valid email address!")
		testresults=false;
	}
	return (testresults)
}
//////////////////////////////////
function isCurrency(ch,key) 
{
	if (!(ch >= '0' && ch <= '9') && key != 8 && key!=44) // && key!=46
	{
		return false;
	}
	return true;
}

function getkey(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}


function keyCheck(e, obj)
{
	var key, ch;
	key = getkey(e);
//alert(key);
	if (key == null) return true;
	ch = String.fromCharCode(key);

	if (!isCurrency(ch,key)) 
	{
		if (window.event)
			window.event.returnValue = false;
		else
			e.preventDefault();
	}
	return true;
}

////////////////////////////////////////////////////////
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}
function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}
function displayItem(key){
	if(queryString(key)=='false') 
	{
		//result.innerHTML="you didn't enter a ?name=value querystring item.";
		return "";
	}else{
		//result.innerHTML+=queryString(key)+"<BR>";
		return queryString(key);
	}
}
////////////////////////////////////////////////////////
String.prototype.replaceAll=function(s1, s2) {return this.split(s1).join(s2)}

////////////////////////////////////////////////////////
function chkForm(tip,obj,val,msj,setfcs)
{
    var sonuc = true;
    switch(tip)
    {
        case "t"://textbox & dropdown
            if(Trim(document.getElementById(obj).value) == val)
                sonuc = false;
            break;
        case "r"://radio
            if(document.getElementById(obj).checked == val)
                sonuc = false;
            break;
        case "c"://checkbox
            if(document.getElementById(obj).checked == val)
                sonuc = false;
            break;
    }
    if(!sonuc && msj != '')alert(msj);
    if(!sonuc && setfcs)document.getElementById(obj).focus();

    return sonuc;
}