var adcc = new Object();
adcc[2] = 355;
adcc[3] = 213;
adcc[5] = 376;
adcc[6] = 244;
adcc[8] = 672;
adcc[10] = 54;
adcc[11] = 374;
adcc[12] = 297;
adcc[13] = 61;
adcc[14] = 43;
adcc[15] = 994;
adcc[17] = 973;
adcc[18] = 880;
adcc[20] = 375;
adcc[21] = 32;
adcc[22] = 501;
adcc[25] = 975;
adcc[26] = 591;
adcc[27] = 387;
adcc[28] = 267;
adcc[29] = 47;
adcc[30] = 55;
adcc[32] = 673;
adcc[33] = 359;
adcc[34] = 226;
adcc[35] = 257;
adcc[36] = 855;
adcc[37] = 237;
adcc[38] = 1;
adcc[39] = 238;
adcc[41] = 236;
adcc[42] = 235;
adcc[43] = 56;
adcc[44] = 86;
adcc[45] = 618;
adcc[47] = 57;
adcc[48] = 269;
adcc[49] = 242;
adcc[51] = 682;
adcc[52] = 506;
adcc[53] = 225;
adcc[54] = 385;
adcc[56] = 357;
adcc[57] = 420;
adcc[58] = 45;
adcc[59] = 253;
adcc[61] = 809;
adcc[63] = 20;
adcc[64] = 503;
adcc[65] = 240;
adcc[66] = 291;
adcc[67] = 372;
adcc[68] = 251;
adcc[69] = 500;
adcc[70] = 298;
adcc[71] = 679;
adcc[72] = 358;
adcc[73] = 33;
adcc[75] = 689;
adcc[76] = 596;
adcc[77] = 241;
adcc[78] = 220;
adcc[79] = 995;
adcc[80] = 49;
adcc[81] = 233;
adcc[82] = 350;
adcc[83] = 30;
adcc[84] = 299;
adcc[86] = 590;
adcc[88] = 502;
adcc[89] = 224;
adcc[91] = 592;
adcc[92] = 509;
adcc[95] = 504;
adcc[96] = 852;
adcc[97] = 36;
adcc[98] = 354;
adcc[99] = 91;
adcc[100] = 62;
adcc[101] = 98;
adcc[103] = 353;
adcc[104] = 972;
adcc[105] = 39;
adcc[107] = 81;
adcc[109] = 7;
adcc[110] = 254;
adcc[111] = 686;
adcc[113] = 82;
adcc[114] = 965;
adcc[115] = 996;
adcc[117] = 371;
adcc[116] = 856;
adcc[118] = 961;
adcc[119] = 266;
adcc[120] = 231;
adcc[122] = 423;
adcc[123] = 370;
adcc[124] = 352;
adcc[125] = 853;
adcc[126] = 381;
adcc[127] = 261;
adcc[128] = 265;
adcc[129] = 60;
adcc[130] = 960;
adcc[131] = 269;
adcc[132] = 356;
adcc[133] = 692;
adcc[134] = 596;
adcc[135] = 222;
adcc[136] = 230;
adcc[137] = 269;
adcc[138] = 52;
adcc[140] = 373;
adcc[141] = 377;
adcc[142] = 976;
adcc[144] = 212;
adcc[145] = 258;
adcc[146] = 95;
adcc[147] = 264;
adcc[148] = 674;
adcc[149] = 977;
adcc[150] = 31;
adcc[151] = 599;
adcc[1] = 93;
adcc[4] = 684;
adcc[23] = 229;
adcc[31] = 246;
adcc[50] = 243;
adcc[219] = 993;
adcc[221] = 688;
adcc[74] = 594;
adcc[90] = 245;
adcc[108] = 962;
adcc[112] = 850;
adcc[139] = 691;
adcc[152] = 687;
adcc[153] = 64;
adcc[154] = 505;
adcc[155] = 227;
adcc[156] = 234;
adcc[157] = 683;
adcc[158] = 672;
adcc[160] = 47;
adcc[161] = 968;
adcc[162] = 92;
adcc[163] = 680;
adcc[164] = 970;
adcc[165] = 507;
adcc[166] = 675;
adcc[167] = 595;
adcc[168] = 51;
adcc[169] = 63;
adcc[170] = 872;
adcc[171] = 48;
adcc[172] = 351;
adcc[174] = 974;
adcc[175] = 262;
adcc[176] = 40;
adcc[177] = 7;
adcc[178] = 250;
adcc[184] = 684;
adcc[185] = 378;
adcc[186] = 239;
adcc[187] = 966;
adcc[188] = 221;
adcc[189] = 381;
adcc[190] = 248;
adcc[191] = 232;
adcc[192] = 65;
adcc[193] = 421;
adcc[194] = 386;
adcc[195] = 677;
adcc[196] = 252;
adcc[197] = 27;
adcc[198] = 995;
adcc[199] = 34;
adcc[200] = 94;
adcc[179] = 290;
adcc[182] = 508;
adcc[201] = 249;
adcc[202] = 597;
adcc[204] = 268;
adcc[205] = 46;
adcc[206] = 41;
adcc[207] = 963;
adcc[208] = 886;
adcc[209] = 992;
adcc[210] = 255;
adcc[211] = 66;
adcc[212] = 670;
adcc[213] = 228;
adcc[214] = 690;
adcc[215] = 676;
adcc[217] = 216;
adcc[218] = 90;
adcc[222] = 256;
adcc[223] = 380;
adcc[224] = 971;
adcc[225] = 44;
adcc[226] = 1;
adcc[228] = 598;
adcc[229] = 998;
adcc[230] = 678;
adcc[231] = 58;
adcc[232] = 232;
adcc[234] = 340;
adcc[235] = 681;
adcc[236] = 236;
adcc[237] = 976;
adcc[238] = 260;
adcc[239] = 263;
adcc[7] = 1;
adcc[9] = 1;
adcc[16] = 1;
adcc[19] = 1;
adcc[24] = 1;
adcc[40] = 1;
adcc[46] = 61;
adcc[55] = 53;
adcc[60] = 1;
adcc[62] = 593;
adcc[85] = 1;
adcc[87] = 1;
adcc[94] = 379;
adcc[93] = 61;
adcc[102] = 964;
adcc[106] = 1;
adcc[240] = 90;
adcc[121] = 218;
adcc[143] = 1;
adcc[159] = 1;
adcc[173] = 1;
adcc[180] = 1;
adcc[181] = 1;
adcc[183] = 1;
adcc[203] = 47;
adcc[216] = 1;
adcc[220] = 1;
adcc[227] = 1;
adcc[233] = 1;
function R () {
}

R.loggedin = false;

var req = new Object();
var args = new Object();
function ajax(t) {
	t = rdm();
	this.get = function() {
		scrn = arguments[0];
		if (scrn.indexOf('http:\/\/') > -1) {
			scrn = scrn.split('http:\/\/')[1].split(document.domain)[1];
		}
		scrn = scrn.split('?')[0];
		if (arguments.length > 1) {
			t = hex_md5(scrn+arguments[1]);
		} else {
			t = hex_md5(scrn);
		}
		this.arguments = arguments;
		args[t] = arguments;
		req[t] = false;
		if (window.XMLHttpRequest) {
			req[t] = new XMLHttpRequest();
			if (req[t].overrideMimeType) {
				req[t].overrideMimeType('text/html; charset=utf-8');
			}
		} else if (window.ActiveXObject) {
			try {
				req[t] = new ActiveXObject('Msxml2.XMLHTTP');
				if (req[t].overrideMimeType) {
					req[t].overrideMimeType('text/html; charset=utf-8');
				}
			} catch (e) {
				try {
					req[t] = new ActiveXObject('Msxml2.XMLHTTP40');
					if (req[t].overrideMimeType) {
						req[t].overrideMimeType('text/html; charset=utf-8');
					}
				} catch (e) {
				}
			}
		}
		if (!req[t]) {
			if (arguments.length > 1) {
				dgi(arguments[1]).innerHTML = 'Cannot create XMLHTTP instance...';
			} else {
				return 'Cannot create XMLHTTP instance...';
			}
		}
		req[t].onreadystatechange = function() {
			if (args[t].length > 1) {
				myurl = args[t][0];
				myurl = myurl.split('\/')[myurl.split('\/').length-1];
				myurl = myurl.split('.')[0];
				switch (myurl) {
					case 'user_desktop_save':
					case 'rightpane_chat':
					case 'rightpane_visitors':
					case 'keep_alive':
					case 'call':
					case 'chat':
						break;
					default:
						if (dgi('img_progress')) {
							dgi('img_progress').src='/img/progress.gif';
						}
						break;
				}
			}
			if (req[t].readyState == 4) {
				if (req[t].status == 200) {
					var jsout = req[t].responseText
					if (jsout == 'int_msg_not_logged_in') {
						logoutUser('Oturumunuz zaman aşımına uğradı !');
					}
					if (jsout == 'int_msg_ccm') {
						var cmd = new ajax().get('/gc.php');
						eval(cmd);
						return false;
					}
					if (args[t].length > 1 && dgi(args[t][1]) && jsout) {
						dgi(args[t][1]).innerHTML = jsout;
						if (jsout.indexOf('jsloadajax') > -1) {
							var jsfiles = jsout.split('jsloadajax\" value=\"')[1].split('\"')[0].split('|');
							for (jsfi=0;jsfi<jsfiles.length;jsfi++) {
								var scrpt = document.createElement('script');
								scrpt.setAttribute('language','Javascript');
								scrpt.type = 'text/javascript';
								scrpt.src = jsfiles[jsfi];
								dgi(args[t][1]).appendChild(scrpt);
							}
						}
						if (jsout.indexOf('<script') > -1) {
							var jst = jsout.split('<script');
														for (iscr=1;iscr<jst.length;iscr++) {
								if (jst[iscr].indexOf('</script>') > -1) {
									jst[iscr] = jst[iscr].split('</script>')[0];
									if (jst[iscr].split('>')[0].indexOf('src="') > -1 && jst[iscr].split('>')[0].indexOf('language="Javascript"') > -1 && jst[iscr].split('>')[0].indexOf('type="text/javascript"') > -1) {
										ssrc = jst[iscr].split('>')[0].split('src="')[1].split('"')[0];
										ssrc = new ajax().get(ssrc);
										var scrpt = document.createElement('script');
										scrpt.setAttribute('language','Javascript');
										scrpt.type = 'text/javascript';
										if (navigator.appVersion.match(/MSIE/)) {
											scrpt.text = ssrc;
										} else {
											scrpt.appendChild(document.createTextNode(ssrc));
										}
										dgi(args[t][1]).appendChild(scrpt);
									} else if (jst[iscr].split('>')[0].indexOf('src="') == -1 && jst[iscr].split('>')[0].indexOf('language="Javascript"') > -1 && jst[iscr].split('>')[0].indexOf('type="text/javascript"') > -1) {
										ssrc = jst[iscr].split('">')[1].split('</script')[0];
										var scrpt = document.createElement('script');
										scrpt.setAttribute('language','Javascript');
										scrpt.type = 'text/javascript';
										if (navigator.appVersion.match(/MSIE/)) {
											scrpt.text = ssrc;
										} else {
											scrpt.appendChild(document.createTextNode(ssrc));
										}
										dgi(args[t][1]).appendChild(scrpt);
									}
								}
							}
													}
						if (args[t][1].substr(0,8) == 'content_') {
							if (dgi('gp_url_'+args[t][1].substr(8))) {
								urlval = args[t][0].replace(document.domain,'').replace('http:\/\/','');
								dgi('gp_url_'+args[t][1].substr(8)).value = urlval;
							}
						}
						if (args[t][1].substr(0,5) == 'idiv_') {
							if (dgi('idiv_url_'+args[t][1].substr(5))) {
								urlval = args[t][0].replace(document.domain,'').replace('http:\/\/','');
								dgi('idiv_url_'+args[t][1].substr(5)).value = urlval;
							}
						}
						findAutoFocus(dgi(args[t][1]));
						switch (args[t][0]) {
							case '/keep_alive.php':
							case '/timeout.php':
							case '/chat.php':
								break;
							default:
								//document.title = 'Vital Teknoloji Panel';
								R.sessionCurrent = 0;
								break;
						}
						findMCE();
					} else {
						if (args[t][1] == 'xw_ka' && jsout != '1' && jsout != '' && jsout.indexOf('newchat') > -1) {
							jsoa = jsout.split('\n');
							for (i=1;i<jsoa.length;i++) {
								if (!dgi('fdiv_wn_chat_'+jsoa[i])) {
									wOpen('wn_chat_'+jsoa[i],'CHAT','/chat.php?csess_id='+jsoa[i],400,400,22,true,false);
								} else {
									updateChatWind(jsoa[i]);
								}
							}
						}
						if (args[t][1] == 'xx_chat_data' && jsout != '1' && jsout != '') {
							if (jsout.indexOf(':::') > -1) {
								chaturl = args[t][0].split('?')[1];
								targetid = chaturl.split('csess_id=')[1].split('&')[0];
								var dvx = dce('div');
								dvx.style.marginBottom = '10px';
								var dvx1 = dce('div');
								dvx1.style.color = '#888';
								dvx1.innerHTML = jsout.split(':::')[0];
								var dvx2 = dce('div');
								dvx2.style.whiteSpace = 'pre-wrap';
								dvx2.innerHTML = jsout.split(':::')[1];
								dvx.appendChild(dvx1);
								dvx.appendChild(dvx2);
								dgi('chat_window_'+targetid).appendChild(dvx);
								dgi('chat_window_'+targetid).scrollTop = dgi('chat_window_'+targetid).scrollHeight;
								dgi('msg_data_'+targetid).value = '';
							}
						}
						if (args[t].length > 1 && dgi(args[t][1]) && !jsout) {
							dgi(args[t][1]).innerHTML = '';
						}
						if (args[t].length == 1) {
							if (jsout) {
								return jsout;
							} else {
								return '';
							}
						}
					}
				} else if (req[t].status == 403) {
					if (args[t].length > 1 && dgi(args[t][1])) {
						dgi(args[t][1]).innerHTML = '<table border="0" style="width:100%;height:100%;"><tr><td style="text-align:center;vertical-align:middle;"><img class="ico" src="/img/warning.gif"><br><br>Erişim Engellendi !<br><br>URL : '+args[t][0]+'</td></tr></table>';
					} else {
						return 'int_msg_access_denied';
					}
				} else if (req[t].status == 404) {
					if (args[t].length > 1 && dgi(args[t][1])) {
						dgi(args[t][1]).innerHTML = '<table border="0" style="width:100%;height:100%;"><tr><td style="text-align:center;vertical-align:middle;"><img class="ico" src="/img/warning.gif"><br><br>Sayfa Bulunamadı !<br><br>URL : '+args[t][0]+'</td></tr></table>';
					} else {
						return 'int_msg_content_not_found';
					}
				} else {
					if (args[t].length > 1 && dgi(args[t][1])) {
						dgi(args[t][1]).innerHTML = '<table border="0" style="width:100%;height:100%;"><tr><td style="text-align:center;vertical-align:middle;"><img class="ico" src="/img/warning.gif"><br><br>İç Sunucu Hatası !<br><br>URL : '+args[t][0]+'</td></tr></table>';
					} else {
						return 'int_msg_internal_error';
					}
				}
				if (args[t].length > 1) {
					myurl = args[t][0];
					myurl = myurl.split('\/')[myurl.split('\/').length-1];
					myurl = myurl.split('.')[0];
					switch (myurl) {
						case 'user_desktop_save':
						case 'rightpane_chat':
						case 'rightpane_visitors':
						case 'keep_alive':
						case 'call':
						case 'chat':
							break;
						default:
							if (dgi('img_progress')) {
								dgi('img_progress').src='/img/pxl.gif';
							}
							break;
					}
				} else {
					return 'int_msg_internal_error';
				}
			}
		}
		if (args[t].length > 1) {
			isAsync = true;
		} else {
			isAsync = false;
		}
		xurl = arguments[0];
		nocache = new Date().getTime()+Math.random();
		if (xurl.indexOf('nocache=') == -1) {
			if (xurl.indexOf('?') > -1) {
				if (xurl.split('?')[1]=='') {
					xurl = xurl + 'nocache='+nocache;
				} else {
					xurl = xurl + '&nocache='+nocache;
				}
			} else {
				xurl = xurl + '?nocache='+nocache;
			}
		}
		req[t].open('GET', xurl, isAsync);
		req[t].send('');
		req[t].close;
		if (args[t].length == 1) {
			if (req[t].status==200) {
				if (req[t].responseText) {
					return req[t].responseText;
				} else {
					return '';
				}
			} else if (req[t].status == 403) {
				gAlert('Erişim Engellendi !');
				return 'int_msg_access_denied'
			} else if (req[t].status == 404) {
				gAlert('Sayfa Bulunamadı !');
				return 'int_msg_content_not_found';
			} else {
				gAlert('İç Sunucu Hatası !');
				return 'int_msg_internal_error';
			}
		}
	}
}

function updateChatWind(targetid) {
	lastmsgid = dgi('chat_window_'+targetid).childNodes[dgi('chat_window_'+targetid).childNodes.length-1].childNodes[0].childNodes[0].value;
	msgout = new ajax().get('/chat.php?act=printmsg&msg_id='+lastmsgid+'&csess_id='+targetid);
	if (msgout != '') {
		dgi('chat_window_'+targetid).innerHTML = dgi('chat_window_'+targetid).innerHTML+msgout;
		dgi('chat_window_'+targetid).scrollTop = dgi('chat_window_'+targetid).scrollHeight;
	}
}

function mktime() {
	var today = new Date();
	var mkt = today.getTime().toString();
	mkt = mkt.substr(0,mkt.length-3);
	return mkt;
}

document.onkeypress = disableEnter;

function disableEnter(e) {
	if (!e) {
		if (window.event) {
			e = window.event;
		} else {
			return;
		}
	}
	var ctrlPressed = e.ctrlKey;
	var altPressed = e.altKey;
	var shiftPressed = e.shiftKey;
	if (typeof(e.keyCode)=='number') {
		e = e.keyCode;
	} else if(typeof(e.which)=='number') {
		e = e.which;
	} else if(typeof(e.charCode)=='number') {
		e = e.charCode;
	} else {
		return;
	}
	switch (e) {
		case 13:
			if (document && document.activeElement && document.activeElement.tagName.toUpperCase() =='TEXTAREA') {
				if (document.activeElement.form && document.activeElement.form.name && document.activeElement.form.name == 'frmRightpaneNotes') {
					if (!ctrlPressed) {
						return false;
					}
				}
				if (document && document.activeElement && document.activeElement.form && document.activeElement.form.name && document.activeElement.form.name.toString().indexOf('frmChat_') > -1) {
					if (!ctrlPressed) {
						return false;
					}
				}
			}
			break;
	}
}

var get = new ajax().get;

function rdm() {
	k = 0
	while (k<100000) {
		k = Math.floor(Math.random()*1000000).toString().substr(0,6);
	}
	return k;
}

function Set_Cookie(name,value,expires,path,domain,secure) {
	var today = new Date();
	today.setTime( today.getTime() );
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape(value)+((expires)?";expires="+expires_date.toGMTString():"")+((path)?";path="+path:"")+((domain)?";domain="+domain:"")+((secure)?";secure":"");
}

document.mygetElementsByClassName = function() {
	var elms = document.getElementsByTagName('*');
	var ei = new Array();
	for (i=0;i<elms.length;i++) {
		ecl = elms[i].className.split(' ');
		for (j=0;j<ecl.length;j++) {
			if (ecl[j].toLowerCase() == arguments[0].toLowerCase()) {
				ei.push(elms[i]);
			}
		}
	}
	return ei;
}

function MM_preloadImages() {
	var d = document;
	if (d.images) {
		if (!d.MM_p) {
			d.MM_p = new Array();
		}
		var i,j = d.MM_p.length
		var a = MM_preloadImages.arguments;
		for (i=0; i<a.length; i++) {
			if (a[i].indexOf("#")!=0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
		}
	}
}

var hexcase = 0;
var b64pad  = "";

function hex_md5(s) {
	return rstr2hex(rstr_md5(str2rstr_utf8(s)));
}

function b64_md5(s) {
	return rstr2b64(rstr_md5(str2rstr_utf8(s)));
}

function any_md5(s, e) {
	return rstr2any(rstr_md5(str2rstr_utf8(s)), e);
}

function hex_hmac_md5(k, d) {
	return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
}

function b64_hmac_md5(k, d) {
	return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
}

function any_hmac_md5(k, d, e) {
	return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e);
}

function md5_vm_test() {
	return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
}

function rstr_md5(s) {
	return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
}

function rstr_hmac_md5(key, data) {
	var bkey = rstr2binl(key);
	if (bkey.length > 16) {
		bkey = binl_md5(bkey, key.length * 8);
	}
	var ipad = Array(16), opad = Array(16);
	for (var i = 0; i < 16; i++) {
		ipad[i] = bkey[i] ^ 0x36363636;
		opad[i] = bkey[i] ^ 0x5C5C5C5C;
	}
	var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
	return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
}

function rstr2hex(input) {
	try {
		hexcase;
	} catch(e) {
		hexcase=0;
	}
	var hex_tab = hexcase?"0123456789ABCDEF":"0123456789abcdef";
	var output = "";
	var x;
	for (var i = 0; i < input.length; i++) {
		x = input.charCodeAt(i);
		output += hex_tab.charAt((x >>> 4) & 0x0F)+hex_tab.charAt( x & 0x0F);
	}
	return output;
}

function rstr2b64(input) {
	try {
		b64pad;
	} catch(e) {
		b64pad='';
	}
	var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	var output = "";
	var len = input.length;
	for (var i = 0; i < len; i += 3) {
		var triplet = (input.charCodeAt(i) << 16) | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i+2) : 0);
		for (var j = 0; j < 4; j++) {
			if (i * 8 + j * 6 > input.length * 8) {
				output += b64pad;
			} else {
				output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
			}
		}
	}
	return output;
}

function rstr2any(input, encoding) {
	var divisor = encoding.length;
	var i, j, q, x, quotient;
	var dividend = Array(Math.ceil(input.length / 2));
	for(i = 0; i < dividend.length; i++) {
		dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
	}
	var full_length = Math.ceil(input.length * 8 /
					 (Math.log(encoding.length) / Math.log(2)));
	var remainders = Array(full_length);
	for (j = 0;j<full_length;j++) {
		quotient = Array();
		x = 0;
		for (i=0;i<dividend.length;i++) {
			x = (x << 16) + dividend[i];
			q = Math.floor(x / divisor);
			x -= q * divisor;
			if (quotient.length > 0 || q > 0) {
				quotient[quotient.length] = q;
			}
		}
		remainders[j] = x;
		dividend = quotient;
	}
	var output = "";
	for (i=remainders.length-1;i>=0;i--) {
		output += encoding.charAt(remainders[i]);
	}
	return output;
}

function str2rstr_utf8(input) {
	var output = "";
	var i = -1;
	var x, y;
	while (++i<input.length) {
		x = input.charCodeAt(i);
		y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
		if (0xD800<=x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
			x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
			i++;
		}
		if (x<=0x7F) {
			output += String.fromCharCode(x);
		} else if(x <= 0x7FF) {
			output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), 0x80 | ( x & 0x3F));
		} else if(x <= 0xFFFF) {
			output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 0x80 | ((x >>> 6 ) & 0x3F), 0x80 | ( x & 0x3F));
		} else if(x <= 0x1FFFFF) {
			output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 0x80 | ((x >>> 12) & 0x3F), 0x80 | ((x >>> 6 ) & 0x3F), 0x80 | ( x & 0x3F));
		}
	}
	return output;
}

function str2rstr_utf16le(input) {
	var output = "";
	for (var i = 0;i<input.length;i++) {
		output += String.fromCharCode( input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF);
	}
	return output;
}

function str2rstr_utf16be(input) {
	var output = "";
	for (var i = 0;i<input.length;i++) {
		output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF);
	}
	return output;
}

function rstr2binl(input) {
	var output = Array(input.length >> 2);
	for (var i = 0;i<output.length;i++) {
		output[i] = 0;
	}
	for (var i = 0;i<input.length * 8;i+=8) {
		output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
	}
	return output;
}

function binl2rstr(input) {
	var output = "";
	for (var i = 0;i<input.length * 32;i+=8) {
		output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
	}
	return output;
}

function binl_md5(x, len) {
	x[len >> 5] |= 0x80 << ((len) % 32);
	x[(((len + 64) >>> 9) << 4) + 14] = len;
	var a =  1732584193;
	var b = -271733879;
	var c = -1732584194;
	var d =  271733878;
	for(var i = 0; i < x.length; i += 16) {
		var olda = a;
		var oldb = b;
		var oldc = c;
		var oldd = d;
		a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
		d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
		c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
		b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
		a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
		d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
		c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
		b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
		a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
		d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
		c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
		b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
		a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
		d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
		c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
		b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);
		a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
		d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
		c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
		b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
		a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
		d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
		c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
		b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
		a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
		d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
		c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
		b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
		a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
		d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
		c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
		b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
		a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
		d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
		c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
		b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
		a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
		d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
		c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
		b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
		a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
		d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
		c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
		b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
		a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
		d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
		c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
		b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
		a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
		d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
		c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
		b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
		a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
		d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
		c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
		b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
		a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
		d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
		c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
		b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
		a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
		d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
		c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
		b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
		a = safe_add(a, olda);
		b = safe_add(b, oldb);
		c = safe_add(c, oldc);
		d = safe_add(d, oldd);
	}
	return Array(a, b, c, d);
}

function md5_cmn(q, a, b, x, s, t) {
	return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}

function md5_ff(a, b, c, d, x, s, t) {
	return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}

function md5_gg(a, b, c, d, x, s, t) {
	return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}

function md5_hh(a, b, c, d, x, s, t) {
	return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}

function md5_ii(a, b, c, d, x, s, t) {
	return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

function safe_add(x, y) {
	var lsw = (x & 0xFFFF) + (y & 0xFFFF);
	var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
	return (msw << 16) | (lsw & 0xFFFF);
}

function bit_rol(num, cnt) {
	return (num << cnt) | (num >>> (32 - cnt));
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

function myWidth() {
	if (typeof(window.innerWidth)=='number') {
		return window.innerWidth;
	} else if (document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)) {
		return document.documentElement.clientWidth;
	} else if(document.body&&(document.body.clientWidth||document.body.clientHeight)) {
		return document.body.clientWidth;
	}
}

function myHeight() {
	if(typeof(window.innerWidth)=='number') {
		return window.innerHeight;
	} else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)) {
		return document.documentElement.clientHeight;
	} else if(document.body&&(document.body.clientWidth||document.body.clientHeight)) {
		return document.body.clientHeight;
	}
}

function urlEncode(data) {
	return encodeURI(data).replace(/&/g,'%26').replace(/\+/g,'%2B').replace(/\//g,'%2F').replace(/\./g,'%2E').replace(/\?/g,'%3F').replace(/\=/g,'%3D');
}

function dgi(id) {
	return document.getElementById(id);
}

if(document.layers) {
	document.captureEvents(Event.CLICK);
	document.captureEvents(Event.MOUSEMOVE);
	document.onclick = clickHandler;
	document.onmousemove = mousePosHandler;
} else if(document.attachEvent) {
	document.attachEvent('onclick', clickHandler);
	document.attachEvent('onmousemove', mousePosHandler);
} else if(document.addEventListener) {
	document.addEventListener('click', clickHandler, false);
	document.addEventListener('mousemove', mousePosHandler, false);
}

function clickHandler(evt) {
	if (document.layers) {
		gClick(evt.target);
	} else if (window.event && window.event.srcElement) {
		gClick(window.event.srcElement);
	} else if (evt && evt.stopPropagation && !window.opera) {
		if (evt.target.nodeType == 1) {
			gClick(evt.target);
		} else {
			gClick(evt.target.parentNode);
		}
	} else if (window.opera && evt) {
		gClick(evt.target);
	}
}

function mousePosHandler(evt) {
	if (document.layers) {
		R.mouseX = evt.clientX;
		R.mouseY = evt.clientY;
	} else if (window.event && window.event.srcElement) {
		R.mouseX = window.event.clientX;
		R.mouseY = window.event.clientY;
	} else if (evt && evt.stopPropagation && !window.opera) {
		if (evt.target.nodeType == 1) {
			R.mouseX = evt.clientX;
			R.mouseY = evt.clientY;
		} else {
			R.mouseX = evt.clientX;
			R.mouseY = evt.clientY;
		}
	} else if (window.opera && evt) {
		R.mouseX = evt.clientX;
		R.mouseY = evt.clientY;
	}
}

function gClick(elm) {
	if(elm && elm.id && elm.id != '' && elm.id.substr(0,10)=='btn_close_') {
		var wn = elm.id.replace('btn_close_','');
		wClose(wn);
	}
	if(elm && elm.id && elm.id != '' && elm.id.substr(0,8)=='btn_max_') {
		var wn = elm.id.replace('btn_max_','');
		maxmin(wn);
	}
	if (dgi('div_imenu_container')) {
		if (!getParentElementById(elm,'div_imenu_container')) {
			imenuCloseAll();
		}
	}
}

function getParentElementById(elm,eid) {
	while (elm.parentNode) {
		if (elm.getAttribute('id') && elm.getAttribute('id')==eid) {
			return elm;
		}
		elm = elm.parentNode;
	}
	return false;
}

function wOpen(wn,ttl,wurl,wdth,hght,pos,closeButton,disablebg) {
	if (disablebg) {
		var sb = document.createElement('div');
		sb.setAttribute('id','sbdiv_'+wn);
		sb.style.position = 'absolute';
		document.body.style.overflow = 'hidden';
		var maxzindex = 5;
		var dvs = dgc('nwind');
		for (i=0;i<dvs.length;i++) {
			myzindex = parseInt(dvs[i].style.zIndex);
			if (myzindex > maxzindex) {
				maxzindex = myzindex;
			}
		}
		sb.style.zIndex = maxzindex;
		sb.style.width = '100%';
		sb.style.height = '100%';
		sb.style.left = '0px';
		sb.style.top = '0px';
		sb.innerHTML = '&nbsp;';
		document.body.appendChild(sb);
	}
	var ni = dgi('wopener');
	var wc = dgc('nwind').length;
	if (!dgi('fdiv_'+wn)) {
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id','fdiv_'+wn);
		newdiv.setAttribute('class','nwind');
		ni.appendChild(newdiv);
		newdiv.style.position='absolute';
		newdiv.style.width=wdth+'px';
		newdiv.style.height=hght+'px';
		switch(pos) {
			case 11:
				newdiv.style.left = (document.body.scrollLeft+10)+'px';
				newdiv.style.top = (document.body.scrollTop+10)+'px';
				break;
			case 12:
				xsleft = (myWidth()-wdth)/2;
				newdiv.style.left = (document.body.scrollLeft+xsleft)+'px';
				newdiv.style.top = (document.body.scrollTop+10)+'px';
				break;
			case 13:
				newdiv.style.right = (myWidth()-wdth-10+document.body.scrollLeft)+'px';
				newdiv.style.top = (document.body.scrollTop+10)+'px';
				break;
			case 21:
				xsleft = (myWidth()-wdth)/2;
				xstop = (myHeight()-hght)/2;
				newdiv.style.left = (document.body.scrollLeft+10)+'px';
				newdiv.style.top = (document.body.scrollTop+xstop)+'px';
				break;
			case 22:
				xsleft = (myWidth()-wdth)/2;
				xstop = (myHeight()-hght)/2;
				newdiv.style.left = (document.body.scrollLeft+xsleft)+'px';
				newdiv.style.top = (document.body.scrollTop+xstop)+'px';
				break;
			case 23:
				xsleft = (myWidth()-wdth)/2;
				xstop = (myHeight()-hght)/2;
				newdiv.style.right = (myWidth()-wdth-10+document.body.scrollLeft)+'px';
				newdiv.style.top = (document.body.scrollTop+xstop)+'px';
				break;
			case 31:
				newdiv.style.left = (document.body.scrollLeft+10)+'px';
				newdiv.style.bottom = (myHeight()-hght-10+document.body.scrollTop)+'px';
				break;
			case 32:
				xsleft = (myWidth()-wdth)/2;
				newdiv.style.left = (document.body.scrollLeft+xsleft)+'px';
				newdiv.style.bottom = (myHeight()-hght-10+document.body.scrollTop)+'px';
				break;
			case 33:
				newdiv.style.right = (myWidth()-wdth-10+document.body.scrollLeft)+'px';
				newdiv.style.bottom = (myHeight()-hght-10+document.body.scrollTop)+'px';
				break;
		}
		var ndih = '';
		val = 'idiv_'+wn;
		if (wurl.indexOf('window_name=') == -1) {
			if (wurl.indexOf('?') > -1) {
				if (wurl.split('?')[1]=='') {
					wurl = wurl + 'window_name='+val;
				} else {
					wurl = wurl + '&window_name='+val;
				}
			} else {
				wurl = wurl + '?window_name='+val;
			}
		}
		ndih = ndih+
		'<input type="hidden" id="idiv_wn_'+wn+'" value="'+wn+'">'+
		'<input type="hidden" id="idiv_ttl_'+wn+'" value="'+ttl+'">';
		if (R.develmode) {
			ndih = ndih+'<input class="txt" style="width:'+(wdth-15)+'px;margin-left:5px;" type="text" id="idiv_url_'+wn+'" value="'+wurl+'">';
		}
		ndih = ndih+
		'<input type="hidden" id="idiv_url_'+wn+'" value="'+wurl+'">'+
		'<input type="hidden" id="idiv_wdth_'+wn+'" value="'+wdth+'">'+
		'<input type="hidden" id="idiv_hght_'+wn+'" value="'+hght+'">'+
		'<input type="hidden" id="idiv_closeButton_'+wn+'" value="'+closeButton+'">'+
		'<input type="hidden" id="idiv_disablebg_'+wn+'" value="'+disablebg+'">'+
		'<input type="hidden" id="idiv_left_'+wn+'" value="'+newdiv.style.left+'">'+
		'<input type="hidden" id="idiv_top_'+wn+'" value="'+newdiv.style.top+'">'+
		'<input type="hidden" id="idiv_zindex_'+wn+'" value="5">'+
		'<input type="hidden" id="idiv_status_'+wn+'" value="1">'+
		//'<table border="0" cellspacing="0" cellpadding="0" style="width:'+wdth+'px;height:'+hght+'px;">'+
		'<table border="0" cellspacing="0" cellpadding="0" style="width:100%;height:100%;">';
				//if (closeButton) {
		//	ndih = ndih+'<tr ondblclick="maxmin(\''+wn+'\');">';
		//} else {
			ndih = ndih+'<tr>';
		//}
						ndih = ndih + '<td class="titlebar" onselectstart="return false" style="width:17px;height:37px;background:url(\/img\/templates\/tpl1\/nw2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="17" height="37"><\/td>';
				if (closeButton) {
					//ndih = ndih+'<td class="titlebar" style="width:'+(wdth-46)+'px;height:17px;background:url(\/img\/templates\/tpl1\/nn2.png);">'+
					ndih = ndih+'<td class="titlebar" style="height:17px;background:url(\/img\/templates\/tpl1\/nn2.png);">'+
					//'<div class="titlebar" onselectstart="return false" style="width:'+(wdth-46)+'px;margin-top:4px;">'+
					'<div class="titlebar" onselectstart="return false" style="width:100%;margin-top:4px;">'+
					ttl+
					'<\/div>'+
					'<\/td>'+
					'<td class="titlebar" onselectstart="return false" style="text-align:right;vertical-align:top;width:40px;height:37px;background:url(\/img\/templates\/tpl1\/nn2.png);">'+
					'<img src="\/img\/templates\/tpl1\/cl.png" style="width:12px;height:11px;margin-top:14px;" id="btn_close_'+wn+'" onmouseover="this.src = this.src.replace(\'.png\',\'_.png\');" onmouseout="this.src = this.src.replace(\'_.png\',\'.png\');">'+
					'<\/td>';
				} else {
					//ndih = ndih+'<td colspan="2" class="titlebar" style="width:100%;height:37px;background:url(\/img\/templates\/tpl1\/nn2.png);">'+
					ndih = ndih+'<td colspan="2" class="titlebar" style="width:'+(wdth-34)+'px;height:37px;background:url(\/img\/templates\/tpl1\/nn2.png);">'+
					'<div class="titlebar" onselectstart="return false" style="margin-top:7px;">'+
					'<img class="btn ico" onclick="new ajax().get(\''+wurl+'\',\'idiv_'+wn+'\');" src="/img/icons/refresh.gif" alt="Sayfayı Yenile">'+ttl+
					'<\/div>'+
					'<\/td>';
				}
				ndih = ndih+'<td class="titlebar" onselectstart="return false" style="width:17px;height:37px;background:url(\/img\/templates\/tpl1\/ne2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="17" height="37"><\/td>'+
			'</tr>'+
			'<tr>'+
				'<td class="titlebar" onselectstart="return false" style="width:17px;background:url(\/img\/templates\/tpl1\/ww2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="17" height="100%"><\/td>'+
				//'<td colspan="2" style="width:'+(wdth-34)+'px;height:'+(hght-54)+'px;vertical-align:top;background:#FFF;">'+
				'<td colspan="2" style="width:100%;vertical-align:top;background:#FFF;">'+
					//'<div id="idiv_'+wn+'" style="width:'+(wdth-34)+'px;height:'+(hght-10)+'px;overflow:auto;padding:5px;">'+
					'<div id="idiv_'+wn+'" style="width:'+(wdth-34)+'px;height:'+(hght-54)+'px;overflow:auto;">'+
					//'<div id="idiv_'+wn+'" style="width:100%;height:100%;overflow:auto;margin:0px;"><img class="titlebar" src="\/img\/pxl.gif" width="'+(wdth-44)+'" height="'+(hght-10)+'">'+
					'<\/div>'+
				'<\/td>'+
				//'<td class="titlebar" onselectstart="return false" style="width:17px;height:'+(hght-54)+'px;background:url(\/img\/templates\/tpl1\/ee2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="17" height="'+(hght-54)+'"><\/td>'+
				'<td class="titlebar" onselectstart="return false" style="width:17px;background:url(\/img\/templates\/tpl1\/ee2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="17" height="100%"><\/td>'+
			'</tr>'+
			'<tr>'+
				'<td class="titlebar" onselectstart="return false" style="width:17px;height:17px;background:url(\/img\/templates\/tpl1\/sw2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="17" height="17"><\/td>'+
				//'<td class="titlebar" onselectstart="return false" colspan="2" style="width:'+(wdth-34)+'px;height:6px;background:url(\/img\/templates\/tpl1\/ss2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="100%" height="17"><\/td>'+
				'<td class="titlebar" onselectstart="return false" colspan="2" style="width:100%;height:17px;background:url(\/img\/templates\/tpl1\/ss2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="100%" height="17"><\/td>'+
				'<td class="titlebar" onselectstart="return false" style="width:17px;height:17px;background:url(\/img\/templates\/tpl1\/se2.png);"><img class="titlebar" src="\/img\/pxl.gif" width="17" height="17"><\/td>'+
			'</tr>'+
		'<\/table>';
		
		newdiv.innerHTML = ndih;
		new ajax().get(wurl,'idiv_'+wn);
		var dragable = DragHandler.attach(document.getElementById('fdiv_'+wn));
		var maxzindex = 5;
		var dvs = dgc('nwind');
		for (i=0;i<dvs.length;i++) {
			myzindex = parseInt(dvs[i].style.zIndex);
			if (myzindex > maxzindex) {
				maxzindex = myzindex;
			}
		}
		newdiv.style.zIndex = maxzindex+1;
		dgi('idiv_zindex_'+wn).value = maxzindex+1;
		if (wn != 'wn_login') {
			
		}
	} else {
		activateWindow(wn);
	}
}

var swfu = new Array();

function wClose(wn) {
	if (dgi('btn_close_'+wn)) {
		var ni = dgi('wopener');
		var newdiv = dgi('fdiv_'+wn);
		var newdiv2 = dgi('sbdiv_'+wn);
		if(newdiv2) {
			document.body.removeChild(newdiv2);
			var dvs = document.getElementsByTagName('div');
			var dvnx = false;
			for(i=0;i<dvs.length;i++) {
				if (dvs[i].id && dvs[i].id.substr(0,5) == 'fdiv_') {
					var dvnx = true;
				}
			}
			if (!dvnx) {
				document.body.style.overflow = 'auto';
			}
		}
		if(ni&&newdiv) {
			if (newdiv.innerHTML.indexOf('swfu_container') > -1 && !isArray(swfu)) {
				swfu.destroy();
			}
			ni.removeChild(newdiv);
		}
	}
}

function maxmin(wn) {
	if (dgi('idiv_status_'+wn).value == 1) {
		dgi('fdiv_'+wn).style.left = '-5px';
		dgi('fdiv_'+wn).style.top = '-5px';

		dgi('idiv_'+wn).style.width = (myWidth()-40)+'px';
		dgi('idiv_'+wn).style.height = (myHeight()-44)+'px';

		dgi('idiv_status_'+wn).value = 2;
		dgi('btn_max_'+wn).src = '\/img\/templates\/tpl1\/rest.png';
	} else {
		dgi('fdiv_'+wn).style.left = dgi('idiv_left_'+wn).value
		dgi('fdiv_'+wn).style.top = dgi('idiv_top_'+wn).value

		dgi('idiv_'+wn).style.width = (dgi('idiv_wdth_'+wn).value-34)+'px';
		dgi('idiv_'+wn).style.height = (dgi('idiv_hght_'+wn).value-54)+'px';

		dgi('fdiv_'+wn).style.width = dgi('idiv_wdth_'+wn).value+'px';
		dgi('fdiv_'+wn).style.height = dgi('idiv_hght_'+wn).value+'px';

		dgi('idiv_status_'+wn).value = 1;
		dgi('btn_max_'+wn).src = '\/img\/templates\/tpl1\/max.png';
	}
}

function isArray(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1) {
		return false;
	} else {
		return true;
	}
}

var DragHandler = {
	_oElem : null,
	attach : function(oElem) {
		oElem.onmousedown = DragHandler._dragBegin;
		oElem.dragBegin = new Function();
		oElem.drag = new Function();
		oElem.dragEnd = new Function();
		return oElem;
	},

	_dragBegin : function(e) {
		if (document.layers) {
			if (e.target) {
				var tgt = e.target.className.toLowerCase();
			}
		} else if (window.event && window.event.srcElement) {
			if (window.event.srcElement && window.event.srcElement.className) {
				var tgt = window.event.srcElement.className.toLowerCase();
			}
		} else if (e && e.stopPropagation && !window.opera) {
			if (e.target) {
				if (e.target.nodeType == 1) {
					var tgt = e.target.className.toLowerCase();
				} else {
					var tgt = e.target.parentNode.className.toLowerCase();
				}
			}
		} else if (window.opera && e) {
			if (e.target) {
				var tgt = e.target.className.toLowerCase();
			}
		}
		if (tgt=='titlebar' && dgi('idiv_status_'+this.id.replace('fdiv_','')).value == 1) {
			var maxzindex = 5;
			var dvs = dgc('nwind');
			for (i=0;i<dvs.length;i++) {
				myzindex = parseInt(dvs[i].style.zIndex);
				if (dvs[i].id != this.id) {
					if (myzindex > maxzindex) {
						maxzindex = myzindex;
					}
				}
			}
			for (i=0;i<dvs.length;i++) {
				if (dvs[i].id==this.id) {
					dvs[i].style.zIndex = maxzindex+1;
					var wid = this.id.toString().replace('fdiv_','');
					dgi('idiv_zindex_'+wid).value = maxzindex+1;
				}
			}
			var oElem = DragHandler._oElem = this;

			if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
			if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }

			var x = parseInt(oElem.style.left);
			var y = parseInt(oElem.style.top);

			e = e ? e : window.event;
			oElem.mouseX = e.clientX;
			oElem.mouseY = e.clientY;
			oElem.dragBegin(oElem, x, y);

			document.onmousemove = DragHandler._drag;
			document.onmouseup = DragHandler._dragEnd;
			return false;
		} else {
			var maxzindex = 5;
			var dvs = dgc('nwind');
			for (i=0;i<dvs.length;i++) {
				myzindex = parseInt(dvs[i].style.zIndex);
				if (dvs[i].id != this.id) {
					if (myzindex > maxzindex) {
						maxzindex = myzindex;
					}
				}
			}
			for (i=0;i<dvs.length;i++) {
				if (dvs[i].id==this.id) {
					dvs[i].style.zIndex = maxzindex+1;
					var wid = this.id.toString().replace('fdiv_','');
					dgi('idiv_zindex_'+wid).value = maxzindex+1;
				}
			}
		}
	},

	_drag : function(e) {
		var oElem = DragHandler._oElem;

		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);

		e = e ? e : window.event;

		newx = x + (e.clientX - oElem.mouseX);
		newy = y + (e.clientY - oElem.mouseY);

		if (newx < -5) {newx = -5};
		if (newy < -5) {newy = -5};
		if (newx > (myWidth()-oElem.offsetWidth+5)) {
			newx = myWidth()-oElem.offsetWidth+5;
		}
		if (newy > (myHeight()-oElem.offsetHeight+5)) {
			newy = myHeight()-oElem.offsetHeight+5;
		}

		oElem.style.left = newx + 'px';
		oElem.style.top = newy + 'px';

		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;

		oElem.drag(oElem, x, y);

		return false;
	},

	_dragEnd : function() {
		var oElem = DragHandler._oElem;

		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);

		oElem.dragEnd(oElem, x, y);

		if (oElem.id && oElem.id.indexOf('fdiv_') > -1) {
			var wid = oElem.id.toString().replace('fdiv_','');
			if (dgi('idiv_status_'+wid).value == 1) {
				dgi('idiv_left_'+wid).value = oElem.style.left;
				dgi('idiv_top_'+wid).value = oElem.style.top;
			}
		}

		document.onmousemove = null;
		document.onmouseup = null;
		DragHandler._oElem = null;
	}
}

function activateWindow(wn) {
	var maxzindex = 5;
	var dvs = dgc('nwind');
	for (i=0;i<dvs.length;i++) {
		myzindex = parseInt(dvs[i].style.zIndex);
		if (dvs[i].id != 'fdiv_'+wn) {
			if (myzindex > maxzindex) {
				maxzindex = myzindex;
			}
		}
	}
	for (i=0;i<dvs.length;i++) {
		if (dvs[i].id=='fdiv_'+wn) {
			dvs[i].style.zIndex = maxzindex+1;
			dgi('idiv_zindex_'+wn).value = maxzindex+1;
		}
	}
}

var swfu = new Array();

function isArray(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1) {
		return false;
	} else {
		return true;
	}
}

document.onkeyup = alertkey;
function alertkey(e) {
	if (!e) {
		if (window.event) {
			e = window.event;
		} else {
			return;
		}
	}
	var ctrlPressed = e.ctrlKey;
	var altPressed = e.altKey;
	var shiftPressed = e.shiftKey;
	if (typeof(e.keyCode)=='number') {
		e = e.keyCode;
	} else if(typeof(e.which)=='number') {
		e = e.which;
	} else if(typeof(e.charCode)=='number') {
		e = e.charCode;
	} else {
		return;
	}

	switch (e) {
		case 8:
			//BACKSPACE
			break;
		case 13:
			//ENTER
			if (document && document.activeElement && document.activeElement.tagName.toUpperCase() =='TEXTAREA') {
				if (document.activeElement.form && document.activeElement.form.name && document.activeElement.form.name == 'frmRightpaneNotes') {
					if (!ctrlPressed) {
						document.activeElement.value = document.activeElement.value.trim();
						submitForm(document.activeElement.form);
					} else {
						document.activeElement.value = document.activeElement.value+'\r\n';
						setCursorAtEnd(document.activeElement);
					}
				}
				if (document && document.activeElement && document.activeElement.form && document.activeElement.form.name && document.activeElement.form.name.toString().indexOf('frmChat_') > -1) {
					if (!ctrlPressed) {
						document.activeElement.value = document.activeElement.value.trim();
						submitForm(document.activeElement.form);
					} else {
						document.activeElement.value = document.activeElement.value+'\r\n';
						setCursorAtEnd(document.activeElement);
					}
				}
			}
			break;
		case 27:
			//ESCAPE
			var wn = false;
			var maxzindex = 5;
			var dvs = dgc('nwind');
			for (i=0;i<dvs.length;i++) {
				myzindex = parseInt(dvs[i].style.zIndex);
				if (dvs[i].id != 'fdiv_'+wn) {
					if (myzindex > maxzindex) {
						maxzindex = myzindex;
						wn = dvs[i].id.replace('fdiv_','');
					}
				}
			}
			if (wn && dgi('idiv_status_'+wn) && dgi('idiv_status_'+wn).value!=0) {
				wClose(wn);
			}
			break;
		case 37:
			//LEFT ARROW
			break;
		case 38:
			//UP ARROW
			break;
		case 39:
			//RIGHT ARROW
			break;
		case 40:
			//DOWN ARROW
			break;
		case 42:
			//ASTERISK
			break;
		case 46:
			//DELETE
			break;
		case 113:
			//F2
			break;
	}
}

function gvoid() {
}

function gAlert(txt) {
		var nd = document.createElement('div');
		var uniq = 'div_alert_'+new Date().getTime()+'.'+new Date().getMilliseconds();
		nd.style.padding = '0px';
		nd.style.background = '#FCC';
		nd.style.borderBottom = '1px solid #888';
		nd.style.borderLeft = '1px solid #888';
		nd.style.borderRight = '1px solid #888';
		nd.style.color = '#000000';
		nd.setAttribute('id',uniq);
		nd.style.zIndex = '150';
		nd.style.position = 'absolute';
		nd.style.fontFamily = 'Verdana';
		nd.style.fontWeight = 'normal';
		nd.style.fontSize = '10px';
		nd.style.lineHeight = '22px';
		nd.style.padding = '3px';
		nd.style.paddingLeft = '30px';
		nd.style.paddingRight = '30px';
		nd.style.verticalAlign = 'middle';
		nd.innerHTML = '<img class="ico" style="background: transparent;" src="/img/warning.png">&nbsp;'+txt;
		document.body.appendChild(nd);
		var ndw = nd.offsetWidth;
		var ndh = nd.offsetHeight;
		nd.style.left = ((myWidth()-ndw)/2)+'px';
		nd.style.top = '-'+ndh+'px';
		setTimeout(function() {
			gAlertD(uniq);
		},150);
}

function gAlertD(uniq) {
		dgi(uniq).style.filter='alpha(style=0, opacity=85)';
		dgi(uniq).style.opacity=0.85;
	if (parseFloat(dgi(uniq).style.top)<0) {
		dgi(uniq).style.top = (parseFloat(dgi(uniq).style.top)+1)+'px';
		setTimeout(function() {
			gAlertD(uniq);
		},15);
	} else {
		setTimeout(function() {
			gAlertR(uniq);
		},2500);
	}
}

function gAlertR(uniq) {
	if (parseFloat(dgi(uniq).style.top)+dgi(uniq).offsetHeight > 0) {
		dgi(uniq).style.top = (parseFloat(dgi(uniq).style.top)-1)+'px';
		setTimeout(function() {
			gAlertR(uniq);
		},15);
	} else {
		document.body.removeChild(dgi(uniq));
	}
}

function gInfo(txt) {
		var nd = document.createElement('div');
		var uniq = 'div_alert_'+new Date().getTime()+'.'+new Date().getMilliseconds();
		nd.style.padding = '0px';
		nd.style.background = '#FFC';
		nd.style.borderBottom = '1px solid #888';
		nd.style.borderLeft = '1px solid #888';
		nd.style.borderRight = '1px solid #888';
		nd.style.color = '#000000';
		nd.setAttribute('id',uniq);
		nd.style.zIndex = '150';
		nd.style.position = 'absolute';
		nd.style.fontFamily = 'Verdana';
		nd.style.fontWeight = 'normal';
		nd.style.fontSize = '10px';
		nd.style.lineHeight = '22px';
		nd.style.padding = '3px';
		nd.style.paddingLeft = '30px';
		nd.style.paddingRight = '30px';
		nd.style.verticalAlign = 'middle';
		nd.innerHTML = '<img class="ico" style="background: inherit;" src="/img/icons/info.png">&nbsp;'+txt;
		document.body.appendChild(nd);
		var ndw = nd.offsetWidth;
		var ndh = nd.offsetHeight;
		nd.style.left = ((myWidth()-ndw)/2)+'px';
		nd.style.top = '-'+ndh+'px';
		setTimeout(function() {
			gInfoD(uniq);
		},150);
}

function gInfoD(uniq) {
		dgi(uniq).style.filter='alpha(style=0, opacity=85)';
		dgi(uniq).style.opacity=0.85;
	if (parseFloat(dgi(uniq).style.top)<0) {
		dgi(uniq).style.top = (parseFloat(dgi(uniq).style.top)+1)+'px';
		setTimeout(function() {
			gInfoD(uniq);
		},15);
	} else {
		setTimeout(function() {
			gInfoR(uniq);
		},2500);
	}
}

function gInfoR(uniq) {
	if (parseFloat(dgi(uniq).style.top)+dgi(uniq).offsetHeight > 0) {
		dgi(uniq).style.top = (parseFloat(dgi(uniq).style.top)-1)+'px';
		setTimeout(function() {
			gInfoR(uniq);
		},15);
	} else {
		document.body.removeChild(dgi(uniq));
	}
}

function dce(etype) {
	return document.createElement(etype);
}

function dgt(tgn) {
	return document.getElementsByTagName(tgn);
}

function dgc(cls) {
	return document.mygetElementsByClassName(cls);
}

function gInsert(elm) {
	document.body.appendChild(elm);
}

function formatPercent(elm) {
	elm.value = elm.value.replace(/,/g,'.');
	num = elm.value;
	num = isNaN(num) || num === '' || num === null ? 0 : num;
	num = parseFloat(num);
	num = (num < 0) ? 0 : num;
	num = (num > 100) ? 100 : num;
	elm.value = parseFloat(num).toFixed(2);
}

function formatCurrency(elm) {
	elm.value = elm.value.replace(/,/g,'.');
	num = elm.value;
	num = isNaN(num) || num === '' || num === null ? 0.00 : num;
	elm.value = parseFloat(num).toFixed(2);
}

function formatInteger(elm) {
	elm.value = elm.value.replace(/,/g,'.');
	num = elm.value;
	num = isNaN(num) || num === '' || num === null ? 0 : num;
	num = parseFloat(num);
	num = (num < 0) ? 0 : num;
	elm.value = parseFloat(num);
}

function formatPhone(elm,cccode) {
	elm.value = elm.value.replace(/\(/g,'');
	elm.value = elm.value.replace(/\)/g,'');
	elm.value = elm.value.replace(/-/g,'');
	elm.value = elm.value.replace(/ /g,'');
	elm.value = elm.value.replace('+'+cccode,'');
	elm.value = elm.value.replace(/\+/g,'');
	ccl = cccode.toString().length;
	if (elm.value.substr(0,ccl)==cccode) {
		elm.value = elm.value.substr(ccl);
	}
	rema = 10-elm.value.length;
	for (remai=0;remai<rema;remai++) {
		elm.value = elm.value + '_';
	}
	num = elm.value;
	if (cccode!='') {
		num = '+'+cccode+' ('+num.substr(0,3)+') '+num.substr((3),3)+' '+num.substr((6),2)+''+num.substr((8));
	} else {
		num = '('+num.substr(0,3)+') '+num.substr(3,3)+' '+num.substr(6,2)+''+num.substr(8);
	}
	elm.value = num;
}

function formatAmount(elm) {
	elm.value = elm.value.replace(/,/g,'.');
	num = elm.value;
	num = isNaN(num) || num === '' || num === null ? 0 : num;
	num = num < 0 ? 0 : num;
	elm.value = parseFloat(num);
}

R.loggedin = false;

function session(str) {
	return new ajax().get('/get_session.php?session='+urlEncode(str));
}

findBody();
function findBody() {
	if (!document.body) {
		setTimeout("findBody();",100);
	} else {
		var dvx = dce('div');
		dvx.style.display='none';
		dvx.id = 'dvx_57848617';
		document.body.appendChild(dvx);
		startSession();
	}
}

function startSession() {
	R.dialogOpen = false;
	R.heartbeats = 3;//sn
	R.sessionTimeout = 300;//heartbeats, 900=15 minutes
	R.confirmTimeout = 20;//seconds
	R.sessionCurrent = 0;
	vtimerIncrement();
}

function vtimerIncrement() {
	if (dgi('dvx_57848617')) {
		R.sessionCurrent++;
		if (R.sessionCurrent < R.sessionTimeout || !R.loggedin) {
			new ajax().get('/keep_alive.php?nocache='+Math.random(),'xw_ka');
			setTimeout("vtimerIncrement();",(R.heartbeats*1000));
		} else {
			R.dialogOpen = true;
			R.logoutCurrent = 0;
			w = 400;
			h = 100;
			l = screen.availWidth/2 - w/2;
			t = screen.availHeight/2 - h/2;
			window.open('/timeout.php?confirmTimeout='+R.confirmTimeout, 'sessionTimedOut', 'toolbar=no,location=no,width='+w+',height='+h+',directories=no,status=no,scrollbars=yes,resize=no,menubar=no,left='+l+',top='+t)
		}
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else { 
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function findAutoFocus(elm) {
	var inps = elm.getElementsByTagName('*');
	for (i=0;i<inps.length;i++) {
		if (inps[i].className && inps[i].type && inps[i].className.toString().indexOf('autofocus') > -1) {
			inps[i].focus();
		}
	}
}

function dateSelector(elm,tgt) {
	spnx = dgi('spn_'+tgt);
	tgtx = dgi(tgt);
	if (dgi('div_date_sel')) {
		dgi('div_date_sel').parentNode.removeChild(dgi('div_date_sel'));
	} else {
		R.ndLeft = findPos(elm)[0] + elm.offsetWidth;
		R.ndTop = findPos(elm)[1] + elm.offsetTop;
		var cdate = new Date();
		var da = new Array('P','S','Ç','P','C','C','P');
		var ma = new Array('','Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık');
		var lma = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
		var y = cdate.getFullYear();
		var dy = (cdate.getDay()+6) % 7;
		var d = cdate.getDate();
		var m = parseInt(cdate.getMonth())+1;
		var printDate = function(d,m,y) {
			if (parseInt(y/4) != y/4) {
				lma[2] = 28;
			} else {
				lma[2] = 29;
			}
			mdisp = m;
			if (mdisp < 10) {
				mdisp = '0' + mdisp;
			}
			ddisp = d;
			if (ddisp < 10) {
				ddisp = '0' + ddisp;
			}
			var dfirst = (parseInt(new Date(mdisp+'/01/'+y).getDay()) + 6) % 7;
			var dlast = (parseInt(new Date(mdisp+'/'+lma[m]+'/'+y).getDay()) + 6) % 7;
			var py = y;
			var pm = m - 1;
			var ny = y;
			var nm = m + 1;
			if (pm == 0) {
				pm = 12;
				py = y - 1;
			}
			if (nm == 13) {
				nm = 1;
				ny = y + 1;
			}
			if (dgi('div_date_sel')) {
				var nd = dgi('div_date_sel');
			} else {
				var nd = dce('div');
				nd.setAttribute('id','div_date_sel');
				nd.style.position = 'absolute';
				nd.style.display = 'inline';
				nd.style.border = '2px solid #DD0000';
				nd.style.backgroundColor = '#FFFFFF';
				if (dgi('fdiv_'+windowNameOf(elm))) {
					nd.style.filter = 'alpha(style=0, opacity=85)';
					nd.style.opacity = 0.85;
				}
				elm.parentNode.appendChild(nd);
				R.callastelm = elm;
				if(navigator.appName.toLowerCase().indexOf('microsoft')>-1 && navigator.appName.toLowerCase().indexOf('explorer')>-1) {
					if (dgi('fdiv_'+windowNameOf(elm))) {
						nd.style.top = (getElementAbsolutePos(elm).y-(dgi('idiv_'+windowNameOf(elm)).scrollTop)-(parseFloat(dgi('fdiv_'+windowNameOf(elm)).style.top)))+'px';
					} else {
						nd.style.top = (getElementAbsolutePos(elm).y)+'px';
					}
				} else {
					if (dgi('fdiv_'+windowNameOf(elm))) {
						nd.style.top = (getElementAbsolutePos(elm).y-(parseFloat(dgi('fdiv_'+windowNameOf(elm)).style.top)))+'px';
					} else {
						nd.style.top = (getElementAbsolutePos(elm).y)+'px';
					}
				}
				if (dgi('idiv_'+windowNameOf(elm))) {
					dgi('idiv_'+windowNameOf(elm)).onscroll = function() {
						if (dgi('div_date_sel')) {
							dgi('div_date_sel').parentNode.removeChild(dgi('div_date_sel'));
						}
					}
				}
			}
			if (nd.childNodes.length > 0) {
				for (i=0;i<nd.childNodes.length;i++) {
					nd.removeChild(nd.childNodes[i]);
				}
			}
			var tbl = dce('table');
			tbl.setAttribute('border','0');
			tbl.setAttribute('cellspacing','0');
			tbl.setAttribute('cellpadding','0');
			var tbd = dce('tbody');
			var tr = dce('tr');
			var td = dce('td');
			td.style.paddingLeft = '0px';
			td.style.paddingRight = '0px';
			td.style.width = '16px';
			var img = dce('img');
			img.className = 'btn';
			img.onclick = function() {
				printDate(d,m,(y-1));
			}
			img.src = '/img/icons/cal_frew.png';
			td.appendChild(img);
			tr.appendChild(td);
			var td = dce('td');
			td.style.paddingLeft = '0px';
			td.style.paddingRight = '0px';
			td.style.width = '16px';
			var img = dce('img');
			img.className = 'btn';
			img.onclick = function() {
				printDate(d,pm,py);
			}
			img.src = '/img/icons/cal_srew.png';
			td.appendChild(img);
			tr.appendChild(td);
			var td = dce('td');
			td.style.paddingLeft = '0px';
			td.style.paddingRight = '0px';
			td.style.width = '100px';
			td.style.textAlign = 'center';
			td.innerHTML = ma[m] + ' \'' + y.toString().substr(2,2);
			tr.appendChild(td);
			var td = dce('td');
			td.style.width = '16px';
			var img = dce('img');
			img.className = 'btn';
			img.onclick = function() {
				printDate(d,nm,ny);
			}
			img.src = '/img/icons/cal_sfwd.png';
			td.appendChild(img);
			tr.appendChild(td);
			var td = dce('td');
			td.style.paddingLeft = '0px';
			td.style.paddingRight = '0px';
			td.style.width = '16px';
			var img = dce('img');
			img.className = 'btn';
			img.onclick = function() {
				printDate(d,m,(y+1));
			}
			img.src = '/img/icons/cal_ffwd.png';
			td.appendChild(img);
			tr.appendChild(td);
			var td = dce('td');
			td.style.paddingLeft = '0px';
			td.style.paddingRight = '0px';
			td.style.width = '28px';
			td.style.textAlign = 'right';
			var img = dce('img');
			img.className = 'btn';
			img.onclick = function() {
				dgi('div_date_sel').parentNode.removeChild(dgi('div_date_sel'));
			}
			img.src = '/img/icons/delete.png';
			td.appendChild(img);
			tr.appendChild(td);
			tbd.appendChild(tr);
			var tr = dce('tr');
			var td = dce('td');
			td.style.paddingLeft = '0px';
			td.style.paddingRight = '0px';
			td.style.width = 'auto';
			td.setAttribute('colspan','6');
			td.innerHTML = '<hr style="font-size:2px;line-height:3px;height:1px;">';
			tr.appendChild(td);
			tbd.appendChild(tr);
			var tr = dce('tr');
			var td = dce('td');
			td.style.paddingLeft = '0px';
			td.style.paddingRight = '0px';
			td.style.width = 'auto';
			td.setAttribute('colspan','6');
			var tbli = dce('table');
			tbli.setAttribute('cellspacing','0');
			tbli.setAttribute('cellpadding','0');
			tbli.className = 'calendar';
			tbli.style.width = '100%';
			var tbdi = dce('tbody');
			var tri = dce('tr');
			tri.className = 'th';
			for (i=0;i<da.length;i++) {
				var tdi = dce('td');
				td.style.paddingLeft = '0px';
				td.style.paddingRight = '0px';
				td.style.width = 'auto';
				if (i > 4) {
					tdi.className = 'wke';
				}
				tdi.innerHTML = da[i];
				tri.appendChild(tdi);
			}
			tbdi.appendChild(tri);
			var tri = dce('tr');
			if (dfirst > 0) {
				for (i=0;i<dfirst;i++) {
					var tdi = dce('td');
					td.style.paddingLeft = '0px';
					td.style.paddingRight = '0px';
					td.style.width = 'auto';
					tdi.innerHTML = '&nbsp;';
					tri.appendChild(tdi);
				}
			}
			for (i=1;i<=lma[m];i++) {
				var tdi = dce('td');
				td.style.paddingLeft = '0px';
				td.style.paddingRight = '0px';
				td.style.width = 'auto';
				tri.appendChild(tdi);
				dx = i;
				if (dx < 10) {
					dx = '0'+i;
				}
				var dthis = (parseInt(new Date(mdisp+'/'+dx+'/'+y).getDay()) + 6) % 7;
				if (i == d) {
					tdi.style.color = '#E0E0E0';
					tdi.style.backgroundColor = '#555555';
				} else {
					if (dthis > 4) {
						tdi.style.color = '#FFFFFF';
						tdi.style.backgroundColor = '#DD0000';
						tdi.onmouseover = function() {
							this.style.color = '#E0E0E0';
							this.style.backgroundColor = '#555555';
						}
						tdi.onmouseout = function() {
							this.style.color = '#FFFFFF';
							this.style.backgroundColor = '#DD0000';
						}
					} else {
						tdi.style.color = '#000000';
						tdi.style.backgroundColor = '#FFFFFF';
						tdi.onmouseover = function() {
							this.style.color = '#E0E0E0';
							this.style.backgroundColor = '#555555';
						}
						tdi.onmouseout = function() {
							this.style.color =  '#000000';
							this.style.backgroundColor = '#FFFFFF';
						}
					}
				}
				tdi.innerHTML = i;
				tdi.title = dx+'.'+mdisp+'.'+y;
				tdi.style.cursor = 'pointer';
				tdi.onclick = function() {
					spnx.innerHTML = this.title;
					tgtx.value = this.title;
					dgi('div_date_sel').parentNode.removeChild(dgi('div_date_sel'));
				}
				if (dthis == 6) {
					tbdi.appendChild(tri);
					var tri = dce('tr');
				}
			}
			if (dlast < 6) {
				for (i=dlast;i<6;i++) {
					var tdi = dce('td');
					td.style.paddingLeft = '0px';
					td.style.paddingRight = '0px';
					td.style.width = 'auto';
					if (i > 3) {
						tdi.className = 'wke';
					}
					tdi.innerHTML = '&nbsp;';
					tri.appendChild(tdi);
				}
			}
			tbdi.appendChild(tri);
			tbli.appendChild(tbdi);
			td.appendChild(tbli);
			tr.appendChild(td);
			tbd.appendChild(tr);
			tbl.appendChild(tbd);
			nd.appendChild(tbl);
		}
		printDate(d,m,y);
	}
}

var __isIE =  navigator.appVersion.match(/MSIE/);
var __userAgent = navigator.userAgent;
var __isFireFox = __userAgent.match(/firefox/i);
var __isFireFoxOld = __isFireFox && (__userAgent.match(/firefox\/2./i) || __userAgent.match(/firefox\/1./i));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;

function __parseBorderWidth(width) {
	var res = 0;
	if (typeof(width) == "string" && width != null && width != "" ) {
		var p = width.indexOf("px");
		if (p >= 0) {
			res = parseInt(width.substring(0, p));
		} else {
			res = 1;
		}
	}
	return res;
}

function __getBorderWidth(element) {
	var res = new Object();
	res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
	if (window.getComputedStyle) {
		var elStyle = window.getComputedStyle(element, null);
		res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));
		res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));
		res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));
		res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));
	}
	else {
		res.left = __parseBorderWidth(element.style.borderLeftWidth);
		res.top = __parseBorderWidth(element.style.borderTopWidth);
		res.right = __parseBorderWidth(element.style.borderRightWidth);
		res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
	}
	return res;
}

function getElementAbsolutePos(element) {
	var res = new Object();
	res.x = 0; res.y = 0;
	if (element !== null) {
		res.x = element.offsetLeft;
		res.y = element.offsetTop;
		var offsetParent = element.offsetParent;
		var parentNode = element.parentNode;
		var borderWidth = null;
		while (offsetParent != null) {
			res.x += offsetParent.offsetLeft;
			res.y += offsetParent.offsetTop;
			var parentTagName = offsetParent.tagName.toLowerCase();
			if ((__isIE && parentTagName != "table") || (__isFireFoxNew && parentTagName == "td")) {
				borderWidth = __getBorderWidth(offsetParent);
				res.x += borderWidth.left;
				res.y += borderWidth.top;
			}
			if (offsetParent != document.body && offsetParent != document.documentElement) {
				res.x -= offsetParent.scrollLeft;
				res.y -= offsetParent.scrollTop;
			}
			if (!__isIE) {
				while (offsetParent != parentNode && parentNode !== null) {
					res.x -= parentNode.scrollLeft;
					res.y -= parentNode.scrollTop;
					if (__isFireFoxOld) {
						borderWidth = __getBorderWidth(parentNode);
						res.x += borderWidth.left;
						res.y += borderWidth.top;
					}
					parentNode = parentNode.parentNode;
				}
			}
			parentNode = offsetParent.parentNode;
			offsetParent = offsetParent.offsetParent;
		}
	}
	return res;
}

function logout() {
	var wnds = dgc('nwind');
	var urlx1 = session('urlx1');
	new ajax().get('/logout.php');
	if (urlx1!='') {
		window.location.assign(urlx1);
	} else {
		window.location.assign('/');
	}
}

function toHex(N) {
	if (N==null) return "00";
	N=parseInt(N); if (N==0 || isNaN(N)) return "00";
	N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
	return "0123456789abcdef".charAt((N-N%16)/16) + "0123456789abcdef".charAt(N%16);
}

function RGBtoHEX(str) {
	if (str.substring(0, 3) == 'rgb') {
		var arr = str.split(",");
		var r = arr[0].replace('rgb(','').trim(), g = arr[1].trim(), b = arr[2].replace(')','').trim();
		var hex = [
			toHex(r),
			toHex(g),
			toHex(b)
		];
		return "#" + hex.join('');
	}
	else{
		return str;
	}
}

function findMCE() {
	var txta = dgt('textarea');
	for (mce=0;mce<txta.length;mce++) {
		if (txta[mce].className && txta[mce].className.toString().toLowerCase().indexOf('wysiwyg') > -1) {
			if (!txta[mce].id || txta[mce].id == '' || txta[mce].id == null) {
				txta[mce].id = 'txta_wyiwyg_'+rdm()+'_'+mce;
			}
			tinyMCE.execCommand('mceAddControl', false, txta[mce].id);
		}
	}
}

function isValidated(elm) {
	R.validationError = null;
	if (elm.name) {
		en = elm.name;
		isRequired = false;
		if (en.substr(0,4) == 'req_') {
			isRequired = true;
			en = en.substr(4);
		}
		val = '';
		if (elm.value) {
			val = elm.value;
		}
		if (val != '') {
			switch(en) {
				case 'u_name':
				case 'u_name_k':
				case 'u_pass':
				case 'u_pass_k':
				case 'u_pass2':
				case 'u_pass2_k':
					var regex = new RegExp("^[0-9a-zA-Z]+$","");
					if (regex.test(val)) {
						if (val.length > 3 && val.length < 17) {
							return true;
						} else {
							R.validationError = 'Bu alana en az 4 en fazla 16 karakter uzunluğunda bir değer girmelisiniz !';
							return false;
						}
					} else {
						R.validationError = 'Bu alana sadece A-Z, a-z ve 0-9 arası değerler girebilirsiniz !';
						return false;
					}
					break;
				case 'wu_name':
				case 'wu_pass':
				case 'wu_new_pass':
				case 'wu_new_pass2':
					var regex = new RegExp("^[0-9a-zA-Z]+$","");
					if (regex.test(val)) {
						if (val.length > 3 && val.length < 12) {
							return true;
						} else {
							R.validationError = 'Bu alana en az 4 en fazla 11 karakter uzunluğunda bir değer girmelisiniz !';
							return false;
						}
					} else {
						R.validationError = 'Bu alana sadece A-Z, a-z ve 0-9 arası değerler girebilirsiniz !';
						return false;
					}
					break;
				case 'u_mail':
					var regex = new RegExp("^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$","");
					if (regex.test(val)) {
						if (val.indexOf('.') > -1) {
							return true;
						} else {
							R.validationError = 'E-posta adresi @ işareti ve . içermelidir !';
							return false;
						}
					} else {
						R.validationError = 'E-posta adresi @ işareti ve . içermelidir !';
						return false;
					}
					break;
				case 'wu_tckn':
				case 'u_tckn':
				case 'udt_11':
				case 'req_udt_11':
				case 'tckn':
					return tcknx(val);
					break;
				default:
					return true;
					break;
			}
		} else {
			if (isRequired) {
				R.validationError = 'Bu alan gereklidir: '+elm.title;
				return false;
			} else {
				return true;
			}
		}
	}
}

function tcknx(tcno) {
	var tckontrol,toplam;
	tckontrol = tcno;
	toplam = Number(tcno.substring(0,1)) + Number(tcno.substring(1,2)) + Number(tcno.substring(2,3)) + Number(tcno.substring(3,4)) + Number(tcno.substring(4,5)) + Number(tcno.substring(5,6)) + Number(tcno.substring(6,7)) + Number(tcno.substring(7,8)) + Number(tcno.substring(8,9)) + Number(tcno.substring(9,10));
	strtoplam = String(toplam);
	onunbirlerbas = strtoplam.substring(strtoplam.length, strtoplam.length-1);
	if(onunbirlerbas == tcno.substring(10,11)) {
		return true;
	} else{
		R.validationError = 'Geçersiz T.C. Kimlik No girdiniz !';
		return false;
	}
}

function windowNameOf(elm) {
	do {
		if (elm.id && elm.id.toString().substr(0,5).toLowerCase()=='fdiv_') {
			return elm.id.substr(5);
		}
	} while (elm=elm.parentNode);
}
function menufn() {
	if (!R.menusys) {
		R.menusys = new Object();
	}
	function menuover(elm) {
		var menuid =elm.parentNode.parentNode.parentNode.parentNode.id;
		var menuex = false;
		for (var key in R.menusys) {
			if (key==menuid) {
				menuex = true;
			}
		}
		if (!menuex) {
			R.menusys[menuid] = new Object();
			R.menusys[menuid]['down'] = false;
		}
		R.menusys[menuid]['over'] = true;
		if (!R.menusys[menuid]['down']) {
			for (i=0;i<elm.parentNode.childNodes.length;i++) {
				if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='td2') {
					if (elm.className == 'tdarr') {
						elm.parentNode.childNodes[i].style.background='url(menu_g_c.png)';
					} else {
						elm.parentNode.childNodes[i].style.background='url(menu_h_c.png)';
					}
				}
				if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='tdarr') {
					elm.parentNode.childNodes[i].style.background='url(menu_h_c.png)';
				}
			}
		} else {
			for (i=0;i<elm.parentNode.childNodes.length;i++) {
				if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='td2') {
					elm.parentNode.childNodes[i].style.background='url(menu_a_c.png)';
				}
				if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='tdarr') {
					elm.parentNode.childNodes[i].style.background='url(menu_a_c.png)';
				}
			}
		}
	}
	function menuout(elm) {
		var menuid =elm.parentNode.parentNode.parentNode.parentNode.id;
		R.menusys[menuid]['over'] = false;
		for (i=0;i<elm.parentNode.childNodes.length;i++) {
			if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='td2') {
				elm.parentNode.childNodes[i].style.background='url(menu_p_c.png)';
			}
			if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='tdarr') {
				elm.parentNode.childNodes[i].style.background='url(menu_p_c.png)';
			}
		}
	}
	function menudown(elm) {
		var menuid =elm.parentNode.parentNode.parentNode.parentNode.id;
		if (!R.menusys[menuid]['down']) {
			R.menusys[menuid]['down'] = true;
			for (i=0;i<elm.parentNode.childNodes.length;i++) {
				if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='td2') {
					elm.parentNode.childNodes[i].style.background='url(menu_a_c.png)';
				}
				if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='tdarr') {
					elm.parentNode.childNodes[i].style.background='url(menu_a_c.png)';
				}
			}
		} else {
			R.menusys[menuid]['down'] = false;
			for (i=0;i<elm.parentNode.childNodes.length;i++) {
				if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='td2') {
					elm.parentNode.childNodes[i].style.background='url(menu_h_c.png)';
				}
				if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='tdarr') {
					elm.parentNode.childNodes[i].style.background='url(menu_h_c.png)';
				}
			}
		}
	}
	function menuup(elm) {
		var menuid =elm.parentNode.parentNode.parentNode.parentNode.id;
		R.menusys[menuid]['down'] = false;
		for (i=0;i<elm.parentNode.childNodes.length;i++) {
			if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='td2') {
				elm.parentNode.childNodes[i].style.background='url(menu_h_c.png)';
			}
			if (elm.parentNode.childNodes[i].nodeType==1 && elm.parentNode.childNodes[i].className=='tdarr') {
				elm.parentNode.childNodes[i].style.background='url(menu_h_c.png)';
			}
		}
	}
}

function submitForm(f) {
	var elms = f.elements;
	var fn = f.getAttribute('name');
	var faction = f.action;
	var frm = new Array();
	var k = -1;
	for (i=0;i<elms.length;i++) {
		var elm = elms[i];
		if (!elms[i].disabled) {
			switch (elm.tagName.toLowerCase()) {
				case 'input':
					switch (elm.getAttribute('type')) {
						case 'text':
						case 'hidden':
						case 'password':
							if (elm.getAttribute('name')) {
								if (elm.getAttribute('name').substr(0,4) == 'req_') {
									if (!isValidated(elm)) {
										gAlert(R.validationError);
										elm.focus();
										return false;
									} else {
										elmex = false;
										for (j=0;j<frm.length;j++) {
											if (frm[j].split('=')[0] == elm.getAttribute('name').substr(4)) {
												elmex = true;
												elmix = j;
											}
										}
										if (!elmex) {
											k++;frm[k] = elm.getAttribute('name').substr(4)+'='+urlEncode(elm.value);
										} else {
											frm[elmix] = frm[elmix]+', '+urlEncode(elm.value);
										}
									}
								} else {
									switch(elm.getAttribute('name')) {
										case 'u_name':
										case 'u_name_':
										case 'u_pass':
										case 'u_pass_k':
										case 'u_pass2':
										case 'u_pass2_k':
										case 'wu_name':
										case 'wu_pass':
										case 'wu_pass2':
										case 'u_mail':
										case 'u_mail_k':
											if (!isValidated(elm)) {
												gAlert(R.validationError);
												elm.focus();
												return false;
											} else {
												elmex = false;
												for (j=0;j<frm.length;j++) {
													if (frm[j].split('=')[0] == elm.getAttribute('name')) {
														elmex = true;
														elmix = j;
													}
												}
												if (!elmex) {
													k++;frm[k] = elm.getAttribute('name')+'='+urlEncode(elm.value);
												} else {
													frm[elmix] = frm[elmix]+', '+urlEncode(elm.value);
												}
											}
											break;
										default:
											elmex = false;
											for (j=0;j<frm.length;j++) {
												if (frm[j].split('=')[0] == elm.getAttribute('name')) {
													elmex = true;
													elmix = j;
												}
											}
											if (!elmex) {
												k++;frm[k] = elm.getAttribute('name')+'='+urlEncode(elm.value);
											} else {
												frm[elmix] = frm[elmix]+', '+urlEncode(elm.value);
											}
											break;
									}
								}
							}
							break;
						case 'radio':
							if (elm.getAttribute('name')) {
								if (elm.getAttribute('name').substr(0,4) == 'req_') {
									var elms2 = dgt('input');
									var elmval = '';
									for (j=0;j<elms2.length;j++) {
										if (elms2[j].getAttribute('name') == elm.getAttribute('name')) {
											if (elms2[j].checked) {
												elmval = elms2[j].value;
											}
										}
									}
									if (elmval == '') {
										gAlert('Bu alan gereklidir: '+elm.title);
										elm.focus();
										return false;
									} else {
										if (k > 0 && frm[k]) {
											if (frm[k].split('=')[0] != elm.getAttribute('name')) {
												k++;frm[k] = elm.getAttribute('name').substr(4)+'='+urlEncode(elmval);
											}
										} else {
											k++;frm[k] = elm.getAttribute('name').substr(4)+'='+urlEncode(elmval);
										}
									}
								} else {
									if (elm.checked) {
										if (elm.value != '') {
											retval = urlEncode(elm.value);
										} else {
											retval = 'on';
										}
										var elms2 = dgt('input');
										ffound = false;
										for (j=0;j<frm.length;j++) {
											if (frm[j].split('=')[0] == elm.getAttribute('name')) {
												ffound = true;
												findex = j;
											}
										}
										if (!ffound) {
											k++;frm[k] = elm.getAttribute('name')+'='+retval;
										} else {
											frm[findex] = frm[findex]+', '+retval;
										}
									}
								}
							}
							break;
						case 'checkbox':
							if (elm.getAttribute('name')) {
								if (elm.getAttribute('name').substr(0,4) == 'req_') {
									var elms2 = dgt('input');
									var elmval = '';
									for (j=0;j<elms2.length;j++) {
										if (elms2[j].getAttribute('name') == elm.getAttribute('name')) {
											if (elms2[j].checked) {
												elmval = elms2[j].value;
											}
										}
									}
									if (elmval == '') {
										gAlert('Bu alan gereklidir: '+elm.title);
										elm.focus();
										return false;
									} else {
										if (k > 0 && frm[k]) {
											if (frm[k].split('=')[0] != elm.getAttribute('name')) {
												k++;frm[k] = elm.getAttribute('name').substr(4)+'='+urlEncode(elmval);
											}
										} else {
											k++;frm[k] = elm.getAttribute('name').substr(4)+'='+urlEncode(elmval);
										}
									}
								} else {
									if (elm.checked) {
										if (elm.value != '') {
											retval = urlEncode(elm.value);
										} else {
											retval = 'on';
										}
										var elms2 = dgt('input');
										ffound = false;
										for (j=0;j<frm.length;j++) {
											if (frm[j].split('=')[0] == elm.getAttribute('name')) {
												ffound = true;
												findex = j;
											}
										}
										if (!ffound) {
											k++;frm[k] = elm.getAttribute('name')+'='+retval;
										} else {
											frm[findex] = frm[findex]+', '+retval;
										}
									}
								}
							}
							break;
					}
					break;
				case 'select':
					if (elm.getAttribute('name')) {
						if (elm.getAttribute('name').substr(0,4) == 'req_') {
							if (elm.options[elm.selectedIndex].value == '' || elm.options[elm.selectedIndex].innerHTML=='-- Seçiniz --') {
								gAlert('Bu alan gereklidir: '+elm.title);
								elm.focus();
								return false;
							} else {
								k++;frm[k] = elm.getAttribute('name').substr(4)+'='+urlEncode(elm.options[elm.selectedIndex].value);
							}
						} else {
							k++;frm[k] = elm.getAttribute('name')+'='+urlEncode(elm.value);
						}
					}
					break;
				case 'textarea':
					evl = elm.value;
					if (!elm.id) {
						elm.id = rdm();
					}
					if (elm.className && elm.className.toString().toLowerCase().indexOf('wysiwyg') > -1) {
						if (tinyMCE.get(elm.id)) {
							evl = tinyMCE.get(elm.id).getContent();
						}
					}
					if (evl.indexOf('!--[if') > -1) {
						gAlert('Geçersiz bir değer girdiniz: '+elm.title);
						elm.focus();
						return false;
					} else {
						if (elm.getAttribute('name')) {
							if (elm.getAttribute('name').substr(0,4) == 'req_') {
								if (evl == '') {
									gAlert('Bu alan gereklidir: '+elm.title);
									elm.focus();
									return false;
								} else {
									k++;frm[k] = elm.getAttribute('name').substr(4)+'='+urlEncode(evl);
								}
							} else {
								k++;frm[k] = elm.getAttribute('name')+'='+urlEncode(evl);
							}
						}
					}
					break;
			}
		}
	}
	if (f.target == '_null') {
		var out = new ajax().get(f.action+'?'+frm.join('&'));
		switch (out) {
			case 'int_msg_req_fields':
				gAlert('Bu alan gereklidir');
				break;
			case 'int_msg_login_success':
				R.loggedin = true;
				var urlx1 = f.urlx1.value;
				if (urlx1!='') {
					window.location.assign(urlx1);
				} else {
					window.location.assign('/members/');
				}
				break;
			case 'int_msg_login_failure':
				gAlert('Geçersiz kullanıcı adı yada şifre !');
				f.req_u_pass.focus();
				R.loggedin = false;
				break;
			case 'int_msg_invalid_captcha':
				gAlert('Geçersiz Güvenlik Kodu !');
				f.req_captcha.focus();
				break;
			case 'int_msg_password_mismatch':
				gAlert('Girdiğiniz şifreler uyuşmuyor !');
				if (f.req_u_pass2) {
					f.req_u_pass2.focus();
				}
				if (f.req_u_pass2_k) {
					f.req_u_pass2_k.focus();
				}
				if (f.u_pass2) {
					f.u_pass2.focus();
				}
				if (f.u_pass2_k) {
					f.u_pass2_k.focus();
				}
				break;
			case 'int_msg_user_added':
				alert('Kullanıcı kaydı başarıyla tamamlandı !');
				window.location.assign('/members/');
				break;
			case 'int_msg_user_updated':
				alert('Bilgiler güncellendi !');
				var ua_redir = session('ua_redir');
				var u_type = session('u_type');
				if (ua_redir != 'false') {
					window.location.assign(ua_redir);
				} else {
					if (u_type==1) {
						window.location.assign('/members/');
					} else {
						window.location.assign('/members/account.php');
					}
				}
				break;
			case 'int_msg_user_exists':
				alert('Belirttiğiniz kullanıcı adı yada e-posta adresi sistemde kayıtlıdır !');
				break;
			case 'int_msg_access_denied':
				//wOpen('wn_display_error','Invalid response from server',f.action+'?'+frm.join('&'),400,300,22,true,false);
				//wClose('wn_userdelete');
				break;
			case 'int_msg_password_reset':
				alert('Parolanız sıfırlanmıştır !');
				window.location.assign('/login.php');
				break;
			case 'int_msg_reminder_sent':
				atxt = 'Parolanızı sıfırlamak için gerekli yönergeleri içeren bir e-posta, %%%mailaddr%%% adresine gönderilmiştir !';
				atxt = atxt.replace('%%%mailaddr%%%',session('reminder_mail'));
				alert(atxt);
				window.location.assign('/resetpass.php');
				break;
			default:
				wOpen('wn_display_error','Invalid response from server',f.action+'?'+frm.join('&'),400,300,22,true,false);
				break;
		}
	} else {
		if (dgi('gp_url_'+f.target.toString().substr(8))) {
			dgi('gp_url_'+f.target.toString().substr(8)).value = f.action.replace('http:\/\/','').replace(document.domain,'')+'?'+frm.join('&');
		}
		new ajax().get(f.action+'?'+frm.join('&'),f.target.toString());
	}
	return false;
}

addLoadEvent(function() {
	//wOpen('wn_test','test page','/style.php',400,400,22,true,false);
	 findPhones(document.body);
});

function autoCurrency(evt) {
	if(typeof(evt.keyCode)=='number') {
		key = evt.keyCode;
	} else if(typeof(evt.which)=='number') {
		key = evt.which;
	} else if(typeof(evt.charCode)=='number') {
		key = evt.charCode;
	} else {
		return false;
	}

	if(document.layers) {
		tgt = evt.target;
	} else if(window.event && window.event.srcElement) {
		tgt = window.event.srcElement;
	} else if(evt && evt.stopPropagation && !window.opera) {
		if (evt.target.nodeType == 1) {
			tgt = evt.target;
		} else {
			tgt = evt.target.parentNode;
		}
	} else if (window.opera && evt) {
		tgt = evt.target;
	} else {
		return false;
	}

	if ((key < 48 || (key > 57 && key < 96) || key > 105)) {
		switch(key) {
			case 8:
			case 46:
				tgt.value = (tgt.value.replace('\.','').substr(0,tgt.value.replace('\.','').length-1)/100).toFixed(2);
				createSelection(tgt,tgt.value.length-1,tgt.value.length);
				break;
			case 9:
			case 13:
			case 116:
				return true;
				break;
			default:
				break;
		}
		return false;
	} else {
		if (key > 95) {
			key = key - 48;
		}
		var val = parseFloat(tgt.value).toFixed(2).toString();
		tgt.value = (parseFloat(val+String.fromCharCode(key))*10).toFixed(2).toString();
		createSelection(tgt,tgt.value.length-1,tgt.value.length);
		return false;
	}
}

function autoPercent(evt) {
	if(typeof(evt.keyCode)=='number') {
		key = evt.keyCode;
	} else if(typeof(evt.which)=='number') {
		key = evt.which;
	} else if(typeof(evt.charCode)=='number') {
		key = evt.charCode;
	} else {
		return false;
	}

	if(document.layers) {
		tgt = evt.target;
	} else if(window.event && window.event.srcElement) {
		tgt = window.event.srcElement;
	} else if(evt && evt.stopPropagation && !window.opera) {
		if (evt.target.nodeType == 1) {
			tgt = evt.target;
		} else {
			tgt = evt.target.parentNode;
		}
	} else if (window.opera && evt) {
		tgt = evt.target;
	} else {
		return false;
	}

	if ((key < 48 || (key > 57 && key < 96) || key > 105)) {
		switch(key) {
			case 8:
			case 46:
				if (tgt.value.length==1) {
					tgt.value = 0;
				} else {
					tgt.value = tgt.value.substr(0,tgt.value.length-1);
				}
				createSelection(tgt,tgt.value.length-1,tgt.value.length);
				break;
			case 9:
			case 116:
				return true;
				break;
			default:
				break;
		}
		return false;
	} else {
		if (key > 95) {
			key = key - 48;
		}
		if (tgt.value==0) {
			tgt.value = String.fromCharCode(key);
		} else {
			if (parseFloat(tgt.value+String.fromCharCode(key)) > 100) {
				tgt.value = 100;
			} else {
				tgt.value = tgt.value+String.fromCharCode(key);
			}
		}
		createSelection(tgt,tgt.value.length-1,tgt.value.length);
		return false;
	}
}

function autoInteger(evt) {
	if(typeof(evt.keyCode)=='number') {
		key = evt.keyCode;
	} else if(typeof(evt.which)=='number') {
		key = evt.which;
	} else if(typeof(evt.charCode)=='number') {
		key = evt.charCode;
	} else {
		return false;
	}

	if(document.layers) {
		tgt = evt.target;
	} else if(window.event && window.event.srcElement) {
		tgt = window.event.srcElement;
	} else if(evt && evt.stopPropagation && !window.opera) {
		if (evt.target.nodeType == 1) {
			tgt = evt.target;
		} else {
			tgt = evt.target.parentNode;
		}
	} else if (window.opera && evt) {
		tgt = evt.target;
	} else {
		return false;
	}

	if ((key < 48 || (key > 57 && key < 96) || key > 105)) {
		switch(key) {
			case 8:
			case 46:
				if (tgt.value.length==1) {
					tgt.value = 0;
				} else {
					tgt.value = tgt.value.substr(0,tgt.value.length-1);
				}
				createSelection(tgt,tgt.value.length-1,tgt.value.length);
				break;
			case 9:
			case 116:
				return true;
				break;
			default:
				break;
		}
		return false;
	} else {
		if (key > 95) {
			key = key - 48;
		}
		if (tgt.value==0) {
			tgt.value = String.fromCharCode(key);
		} else {
			tgt.value = tgt.value+String.fromCharCode(key);
		}
		createSelection(tgt,tgt.value.length-1,tgt.value.length);
		return false;
	}
}

function autoPhone(evt, cccode) {
	if(typeof(evt.keyCode)=='number') {
		key = evt.keyCode;
	} else if(typeof(evt.which)=='number') {
		key = evt.which;
	} else if(typeof(evt.charCode)=='number') {
		key = evt.charCode;
	} else {
		return false;
	}

	if(document.layers) {
		tgt = evt.target;
	} else if(window.event && window.event.srcElement) {
		tgt = window.event.srcElement;
	} else if(evt && evt.stopPropagation && !window.opera) {
		if (evt.target.nodeType == 1) {
			tgt = evt.target;
		} else {
			tgt = evt.target.parentNode;
		}
	} else if (window.opera && evt) {
		tgt = evt.target;
	} else {
		return false;
	}
	val = tgt.value;
	val = val.replace(/\(/g,'');
	val = val.replace(/\)/g,'');
	val = val.replace(/-/g,'');
	val = val.replace(/ /g,'');
	val = val.replace(/_/g,'');
	val = val.replace(/\+/g,'');

	if ((key < 48 || (key > 57 && key < 96) || key > 105)) {
		switch(key) {
			case 8:
			case 46:
				if (val.length > cccode.toString().length) {
					val = val.substr(0,val.length-1);
				}
				tgt.value = val;
				formatPhone(tgt, cccode);
				selpos = tgt.value.split('_')[0].length;
				createSelection(tgt,selpos,1);
				break;
			case 9:
			case 116:
				return true;
				break;
			default:
				break;
		}
		return false;
	} else {
		if (cccode!='') {
			if (val.length>=(10+cccode.toString().length)) {
				val = val.substr(0,val.length-1);
			}
		} else {
			if (val.length>=10) {
				val = val.substr(0,val.length-1);
			}
		}
		if (key > 95) {
			key = key - 48;
		}
		val = val + String.fromCharCode(key);
		tgt.value = val;
		formatPhone(tgt, cccode);
		selpos = tgt.value.split('_')[0].length;
		if (selpos == tgt.value.length) {
			selpos = selpos-1;
		}
		createSelection(tgt,selpos,1);
		return false;
	}
}

function createSelection(field, start, end) {
	if( field.createTextRange ) {
		var selRange = field.createTextRange();
		selRange.collapse(true);
		selRange.moveStart('character', start);
		selRange.moveEnd('character', end);
		selRange.select();
	} else if( field.setSelectionRange ) {
		field.setSelectionRange(start, end);
	} else if( field.selectionStart ) {
		field.selectionStart = start;
		field.selectionEnd = end;
	}
	field.focus();
}

function findCurrencies() {
	var inps = document.getMyElementsByClassName('currency');
	for (i=0;i<inps.length;i++) {
		formatCurrency(inps[i]);
		inps[i].onfocus = inps[i].onclick = function () {
			if(this.value!=''){createSelection(this,this.value.length-1,this.value.length);}
		}
		inps[i].onblur = inps[i].onkeydown = inps[i].onchange = function () {
			return autoCurrency(event);
		}
	}
}

function findPercents() {
	var inps = document.getMyElementsByClassName('percent');
	for (i=0;i<inps.length;i++) {
		formatPercent(inps[i]);
		inps[i].onfocus = inps[i].onclick = function () {
			if(this.value!=''){createSelection(this,this.value.length-1,this.value.length);}
		}
		inps[i].onblur = inps[i].onkeydown = inps[i].onchange = function () {
			return autoPercent(event);
		}
	}
}

function findIntegers() {
	var inps = document.getMyElementsByClassName('integer');
	for (i=0;i<inps.length;i++) {
		formatInteger(inps[i]);
		inps[i].onfocus = inps[i].onclick = function () {
			if(this.value!=''){createSelection(this,this.value.length-1,this.value.length);}
		}
		inps[i].onblur = inps[i].onkeydown = inps[i].onchange = function () {
			return autoInteger(event);
		}
	}
}

function findPhones(underelm) {
	var inps = underelm.getElementsByTagName('input');
	for (fpi=0;fpi<inps.length;fpi++) {
		if (inps[fpi] && inps[fpi].type.toString().toLowerCase()=='text' && inps[fpi].className && inps[fpi].className.indexOf('phone') > -1) {
			if (inps[fpi].form.req_udt_13) {
				var cccode = adcc[inps[fpi].form.req_udt_13.value];
			} else {
				var cccode = '';
			}
			attachPhone(inps[fpi], cccode);
		}
	}
}

function findPhonesRefresh(underelm) {
	var inps = underelm.getElementsByTagName('input');
	for (fpi=0;fpi<inps.length;fpi++) {
		if (inps[fpi] && inps[fpi].type.toString().toLowerCase()=='text' && inps[fpi].className && inps[fpi].className.indexOf('phone') > -1) {
			inps[fpi].value='';
			if (inps[fpi].form.req_udt_13) {
				var cccode = adcc[inps[fpi].form.req_udt_13.value];
			} else {
				var cccode = '90';
			}
			attachPhone(inps[fpi], cccode);
		}
	}
}

function attachPhone(elm, cccode) {
	elm.onfocus = elm.onclick = function () {
		if(this.value!=''){
			val = this.value;
			val = val.replace(/\(/g,'');
			val = val.replace(/\)/g,'');
			val = val.replace(/-/g,'');
			val = val.replace(/ /g,'');
			val = val.replace(/_/g,'');
			formatPhone(this, cccode);
			selpos = this.value.split('_')[0].length;
			if (selpos == this.value.length) {
				selpos = selpos-1;
			}
			createSelection(this,selpos,1);
		}
	}
	elm.onblur = elm.onkeydown = elm.onchange = function () {
		return autoPhone(event, cccode);
	}
	formatPhone(elm, cccode);
}
