function ConfirmClose() {
	return confirm("Kapatmak istedišinize emin misiniz?");
}

function trimNumber(s) {
	s = s.replace(/^\s*/,'').replace(/\s*$/, '');
	return s;
}

// REGEXP ile validation
function addCommas() {
	var x = document.forms[0];
	var objRegExp  = new RegExp('([0-9]{4})([0-9]{3})([0-9]{2})([0-9]{2})');

	while(objRegExp.test(x.fieldregexp.value)) {
		x.fieldregexp.value = x.fieldregexp.value.replace(objRegExp, '$1 $2 $3 $4');
	}
}

function FormatCreditCard(thisis) {
	var tempstr,newstr,str,i,str2 ;
	i = 0;

	thisis.value = trimNumber(thisis.value);
	str = thisis.value;

	while ( 20 > i) {
		str = str.replace(" ", "");
		i = i + 1;
	}

	if (str.length > 4)
	{
		tempstr = str;
		newstr = "";
		i = 0;
		while (tempstr.length > 4)
		{
			newstr = newstr + tempstr.substr(0, 4) + " ";
			tempstr = tempstr.substr(4);
		}
		thisis.value = newstr + tempstr;
	}

	return true;
}

var isFocus = 0;
function FormatPhoneNumber(thisis) {
	var tempstr,newstr,str,i,str2 ;
	var commapos,aftercomma,commacount;
	i=0;

	if (isFocus == 1) {
		isFocus = 0;
		return false;
	}

	thisis.value = trimNumber(thisis.value);
	str = thisis.value;

	while ( 15 > i) {
		str = str.replace(" ", "");
		i = i + 1;
	}

	if (str.length > 9) {
		tempstr = str;
		newstr = "";
		newstr = tempstr.substr(0, 4) + " " + tempstr.substr(4, 3) + " " + tempstr.substr(7, 2) + " " + tempstr.substr(9);
		thisis.value = newstr;
	} else if (str.length > 7) {
		tempstr = str;
		newstr = "";
		newstr = tempstr.substr(0, 4) + " " + tempstr.substr(4, 3) + " " + tempstr.substr(7);
		thisis.value = newstr;
	} else if (str.length > 4) {
		tempstr = str;
		newstr = "";
		newstr = tempstr.substr(0, 4) + " " + tempstr.substr(4);
		thisis.value = newstr;
	}
}

function Only_Numeric(e) {
	var whichCode = (window.Event) ? e.which : e.keyCode;
	//alert(whichCode);
	if (whichCode == 13) return true;  // Enter
	if (whichCode > 57 ) return false;
	if (whichCode < 48 && whichCode > 13) return false;
}

function trim(s) {
	s = s.replace(/^\s*/,'').replace(/\s*$/, '');
	return s;
}

function TrimAll(form) {
    for (var i=0, j=form.elements.length; i<j; i++) {
        myType = form.elements[i].type;
        if (myType == 'text' || myType == 'textarea')
            form.elements[i].value = trim(form.elements[i].value);
    }
}

function checkNum(data) {      // checks if all characters are valid numbers or a " "
	return data.match(/^[0-9 ]*$/);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	if (CheckForm(form1) == true) {
  		dede = window.open(theURL,winName,features + ',top=100 ,left=300');
		dede.focus();
		return true;
	} else {
		return false;
	}
}

function IsNumeric(strString) {
   return strString.match(/^\d+$/);
}

function IsNumeric2(strString) {
   if(isNaN(strString)) {
   	return false;
   } else {
   	return true;
   }
}

function ClearAll(form) {
	for( var i = 0, j = form.elements.length; i < j; i++ ) {
		myType = form.elements[i].type;
		if( myType == 'text' || myType == 'textarea' || myType == 'select-one' ) {
			form.elements[i].value = "";
		}
	}
}

function CheckEmail(str) {
	if (document.layers||document.getElementById||document.all) {
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		return filter.test(str);
	} else {
		return true;
	}
}

function CheckKKNo(str) {
	return str.match(/^\d{4}( \d{4}){3}$/);
}
