var helpDir = "help/";
var htmlDir = "html/";
var imageDir = "img/";

String.prototype.trim = function() { return this.toString().replace(/^\s+/,"").replace(/\s+$/,""); };
// mozilla bu satira kiziyor
// String.prototype.float = function() { return
// parseFloat(cleanNumber(this.toString(),true)); };
String.prototype.bool =  function() { return (parseInt(this.toString())==1) ? true : false; };

Array.prototype.name = null;

Date.defaultFormat = "dd/MM/yyyy";
Date.prototype.dayShort = new Array("Paz","Ptz","Sal","Çşm","Prş","Cum","Cts");
Date.prototype.dayNames = new Array("Pazar","Pazartesi","Salı","Çarşamba","Perşembe","Cuma","Cumartesi");
Date.prototype.monthNames = new Array("Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık");
Date.prototype.getDayShort = function(day) { return this.dayShort[day]; };
Date.prototype.getDayName = function(day) { return this.dayNames[day]; };
Date.prototype.getMonthName = function(month) { return this.monthNames[month]; };
Date.prototype.daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
Date.prototype.daysInFebruary = function(year) { return ( ((year%4 == 0) && ( (!(year%100 == 0)) || (year%400 == 0) ) ) ? 29 : 28 ); };
Date.prototype.getDaysInMonth = function(year, month) { return (month=1) ? daysInFebruary(year) : this.daysInMonth[month]; };

// ----------------------------------------
// genel util usage
// ----------------------------------------
function getComboText(comp)
{
	if (comp.selectedIndex != -1)
		return comp[comp.selectedIndex].text;

	return null;
}

function getComboCode(comp)
{
	if (comp.selectedIndex != -1)
		return comp[comp.selectedIndex].value;

	return null;
}

function clearCombo(comp) 
{
	comp.selectedIndex = -1;

	for (var j=comp.length; j>=0; j--)
		comp.options[j] = null;
}

function setSelectedItem(comp, code)
{
	comp.selectedIndex = -1;
	for (var i=0; i<comp.length; i++) {
		if (comp[i].value == code) {
			comp.selectedIndex = i;
			break;
		}
	}
	return comp.selectedIndex;
}

function getCheckedRadio(theRadioGroup)
{
	var val = null;
	for (var i=0;i < theRadioGroup.length; i++) {
		if (theRadioGroup[i].checked) {
			val = theRadioGroup[i].value;
			break;
		} // if checked
	} // for i
	return val;
}

function setCheckedRadio(theRadioGroup,val,bool)
{
	for (var i=0;i < theRadioGroup.length; i++) {
		if (theRadioGroup[i].value == val){
			theRadioGroup[i].checked=bool;
			break;
		} // if equal
	} // for i
}

function setFocus(theComp)
{
	theComp.focus();
}


function reportError(theComp,msg)
{
	if (arguments != null && arguments.length>2) {
		msg = msg.replace(/\{0\}/g,arguments[2]);
		if (arguments.length>3)
			msg = msg.replace(/\{1\}/g,arguments[3]);
	}
	alert(msg);
	setFocus(theComp);
	return false;
}

function confirmProcess(msg)
{
	if (arguments != null && arguments.length>2) {
		msg = msg.replace(/\{0\}/g,arguments[2]);
		if (arguments.length>3)
			msg = msg.replace(/\{1\}/g,arguments[3]);
	}
	return confirm(msg);
}

function showHelp(helpHtml,outputFrame)
{
	if (outputFrame==null || outputFrame.length==0) outputFrame = "helpWin";
	var helpWin = showUrl(htmlDir+helpDir+helpHtml,outputFrame);
	helpWin.focus();
	return helpWin;
}

function showHelpNew(helpHtml,outputFrame)
{
	if (outputFrame==null || outputFrame.length==0) outputFrame = "helpWin";
	var helpWin = showUrl(helpHtml,outputFrame);
	helpWin.focus();
	return helpWin;
}

function showUrl(linkUrl, outputFrame, outputWinOpts)
{
	if (outputWinOpts!=null) return window.open(linkUrl, outputFrame, outputWinOpts);
	return window.open(linkUrl, outputFrame);
}

// ----------------------------------------
// date manipulation utils
// ----------------------------------------
function selectDate(theComp,theAnchor)
{
	cal.select(theComp,theAnchor,Date.defaultFormat); 
}
function selectDateFromId(theId,theAnchor)
{
	var theComp = document.getElementById(theId);
	cal.select(theComp,theAnchor,Date.defaultFormat);
}

function checkDate(theDate)
{
	return isDate(theDate,Date.defaultFormat);
}

function truncDate(theDate)
{
	if (theDate!=null)
		return new Date(theDate.getFullYear(),theDate.getMonth(),theDate.getDate());
	return null;
}

function compareDateObjects(date1, date2)
{
	if (date1 > date2) return 1;
	if (date2 > date1) return -1;
	return 0;
}

function dateDiff(date1,date2)
{
	diff = new Date();
	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	return Math.floor(diff.getTime() / (1000 * 60 * 60 * 24)); 
}

// ----------------------------------------
// id checkbox table column
// ----------------------------------------
function selectIdItems(form,tag)
{
	if (tag==null) tag = "id";
	var tempIds = document.all[tag];
	var ids = new Array();
	if (tempIds!=null) {
		if (tempIds.length!=null) 
			ids = tempIds;
		else 
			ids[0] = tempIds;
	}

	for (var i=0;i<ids.length;i++) {
		ids[i].checked = form.all.checked;
	}
	form.deleteButton.disabled = !form.all.checked;
}

function selectIdItem(comp,form,tag)
{
	if (tag==null) tag = "id";
	var tempIds = document.all[tag];
	var ids = new Array();
	if (tempIds!=null) {
		if (tempIds.length!=null) 
			ids = tempIds;
		else 
			ids[0] = tempIds;
	}

	if (comp.checked) {
		form.deleteButton.disabled = false;

		var checkAll = true;
		for (var i=0;i<ids.length;i++) {
			if (ids[i].checked==false) checkAll = false;
		}
		form.all.checked = checkAll;
	}
	else {
		if (form.all.checked) form.all.checked = false;

		var allowSil = true;
		for (var i=0;i<ids.length;i++) {
			if (ids[i].checked) allowSil = false;
		}
		form.deleteButton.disabled = allowSil;
	}
}

function NewWindow(mypage, myname, w, h, scroll,resize) 
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize
	
	win = window.open(mypage, myname, winprops)
	
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}

// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

// valid_email = validateEmail(email_field,mandatory,messages);

function validateEmail(addr,man,db) 
{
	if (addr == '' && man) {
	   if (db) alert('email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
	      if (db) alert('email address contains invalid characters');
	      return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
	      if (db) alert("email address contains non ascii characters.");
	      return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
	return true;
}

/*
 * 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
 * international characters) were allowed.
 * 
 * 1.1.3: Added the restriction to only accept addresses ending in two letters
 * (interpreted to be a country code) or one of the known TLDs (com, net, org,
 * edu, int, mil, gov, arpa), including the new ones (biz, aero, name, coop,
 * info, pro, museum). One can easily update the list (if ICANN adds even more
 * TLDs in the future) by updating the knownDomsPat variable near the top of the
 * function. Also, I added a variable at the top of the function that determines
 * whether or not TLDs should be checked at all. This is good if you are using
 * this function internally (i.e. intranet site) where hostnames don't have to
 * conform to W3C standards and thus internal organization e-mail addresses
 * don't have to either. Changed some of the logic so that the function will
 * work properly with Netscape 6.
 * 
 * 1.1.2: Fixed a bug where trailing . in e-mail address was passing (the bug is
 * actually in the weak regexp engine of the browser; I simplified the regexps
 * to make it work).
 * 
 * 1.1.1: Removed restriction that countries must be preceded by a domain, so
 * abc@host.uk is now legal. However, there's still the restriction that an
 * address must end in a two or three letter word.
 * 
 * 1.1: Rewrote most of the function to conform more closely to RFC 822.
 * 
 * 1.0: Original
 */
// -->

<!-- Begin
function emailCheck (emailStr) 
{

	/*
	 * The following variable tells the rest of the function whether or not to
	 * verify that the address ends in a two-letter country or well-known TLD. 1
	 * means check it, 0 means don't.
	 */
	
	var checkTLD=1;
	
	/*
	 * The following is the list of known TLDs that an e-mail address must end
	 * with.
	 */
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	/*
	 * The following pattern is used to check if the entered e-mail address fits
	 * the user@domain format. It also is used to separate the username from the
	 * domain.
	 */
	
	var emailPat=/^(.+)@(.+)$/;
	
	/*
	 * The following string represents the pattern for matching all special
	 * characters. We don't want to allow special characters in the address.
	 * These characters include ( ) < > @ , ; : \ " . [ ]
	 */
	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/*
	 * The following string represents the range of characters allowed in a
	 * username or domainname. It really states which chars aren't allowed.
	 */
	
	var validChars="\[^\\s" + specialChars + "\]";
	
	/*
	 * The following pattern applies if the "user" is a quoted string (in which
	 * case, there are no rules about which characters are allowed and which
	 * aren't; anything goes). E.g. "jiminy cricket"@disney.com is a legal
	 * e-mail address.
	 */
	
	var quotedUser="(\"[^\"]*\")";
	
	/*
	 * The following pattern applies for domains that are IP addresses, rather
	 * than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address.
	 * NOTE: The square brackets are required.
	 */
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/*
	 * The following string represents an atom (basically a series of
	 * non-special characters.)
	 */
	
	var atom=validChars + '+';
	
	/*
	 * The following string represents one word in the typical username. For
	 * example, in john.doe@somewhere.com, john and doe are words. Basically, a
	 * word is either an atom or quoted string.
	 */
	
	var word="(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	/*
	 * The following pattern describes the structure of a normal symbolic
	 * domain, as opposed to ipDomainPat, shown above.
	 */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/*
	 * Finally, let's start trying to figure out if the supplied address is
	 * valid.
	 */
	
	/*
	 * Begin with the coarse pattern to simply break up user@domain into
	 * different pieces that are easy to analyze.
	 */
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
		/*
		 * Too many/few @'s or something; basically, this address doesn't even
		 * fit the general mould of a valid e-mail address.
		 */
		
		alert(emailError1);
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings
	// (0-127).
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert(emailError2);
			return false;
	    }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert(emailError3);
			return false;
	    }
	}

	// See if "user" is valid

	if (user.match(userPat)==null) {
		// user is not valid
	
		alert(emailError4);
		return false;
	}

	/*
	 * if the e-mail address is at an IP address (as opposed to a symbolic host
	 * name) make sure the IP address is valid.
	 */
		
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		
		// this is an IP address
	
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert(emailError5);
				return false;
			   }
		}
		return true;
	}

	// Domain is symbolic name. Check if it's valid.
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert(emailError6);
			return false;
		   }
	}

	/*
	 * domain name seems valid, but now make sure that it ends in a known
	 * top-level domain (like com, edu, gov) or a two-letter word, representing
	 * country (uk, nl), and that there's a hostname preceding the domain or
	 * country.
	 */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert(emailError7);
		return false;
	}
	
	// Make sure there's a host name preceding the domain.

	if (len<2) {
		alert(emailError8);
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

function CheckLen(Target,maxlength)
{
	StrLen=Target.value.length;

	if (StrLen == 1 && Target.value.substring(0,1) == " ")
	{
		Target.value=""; 
		StrLen=0;
	}
	if (StrLen > maxlength )
	{
		Target.value=Target.value.substring(0,maxlength);
		CharsLeft=0;
	}
	else
		CharsLeft=maxlength-StrLen;

	return CharsLeft;
}

function jm_currencymask(t)
{
	var patt = /(\d*)\,{1}(\d{0,2})/;
	var donepatt = /^(\d*)\,{1}(\d{2})$/;
	var str = t.value;
	var result;
	if (!str.match(donepatt))
	{
		result = str.match(patt);
		if (result!= null)
		{	
			t.value = t.value.replace(/[^\d]/gi,'');
			str = result[1] + ',' + result[2] ;
			t.value = str;
		}
		else{
			if (t.value.match(/[^\d]/gi))
			t.value = t.value.replace(/[^\d]/gi,'');
		}
	}
}

function jm_datemask(t)
{
	var donepatt = /^(\d{2})\/(\d{2})\/(\d{4})$/;
	var patt = /(\d{2}).*(\d{2}).*(\d{4})/;
	var str = t.value;
	if (!str.match(donepatt))
	{
		result = str.match(patt);
		if (result!= null)
		{
			t.value = t.value.replace(/[^\d]/gi,'');
			str = result[1] + '/' + result[2] + '/' + result[3];
			t.value = str;
		}
		else{
			if (t.value.match(/[^\d]/gi))
				t.value = t.value.replace(/[^\d]/gi,'');
		}
	}
}

function jm_phonemask(t)
{
	var patt1 = /(\d{3}).*(\d{3}).*(\d{4})/;
	var patt2 = /^\((\d{3})\).(\d{3})-(\d{4})$/;
	var str = t.value;
	var result;
	if (!str.match(patt2))
	{
		result = str.match(patt1);
		if (result!= null)
		{
			t.value = t.value.replace(/[^\d]/gi,'');
			str = '(' + result[1] + ') ' + result[2] + '-' + result[3];
			t.value = str;
		}
		else{
			if (t.value.match(/[^\d]/gi))
				t.value = t.value.replace(/[^\d]/gi,'');
		}
	}
}

function jm_ssnmask(t)
{
	var patt = /(\d{3}).*(\d{2}).*(\d{4})/;
	var donepatt = /^(\d{3})-(\d{2})-(\d{4})$/;
	var str = t.value;
	var result;
	if (!str.match(donepatt))
	{
		result = str.match(patt);
		if (result!= null){
			t.value = t.value.replace(/[^\d]/gi,'');
			str = result[1] + '-' + result[2] + '-' + result[3];
			t.value = str;
		}
		else{
			if (t.value.match(/[^\d]/gi))
				t.value = t.value.replace(/[^\d]/gi,'');
		}
	}
}