	/* 
	Project : StoreCenter Public Functions v 5.0.0 (2012)
	Author : İsmail Türkay
	E-Mail : ismailturkay@almila.com
	Create : 11/2009
	
	Bismillah
	*/

	var SC_SID, SC_LID, SC_LIB, changeFlag = scAdmin = false;
	var SCUploadImgTypes =	'PNG;JPG;JPEG;GIF;';
	var SCDateFormat, SCCurrFormat, msgValidator = null;
	var quickmouseflag = false, quicktimer = null, quickwindow = null;
	
	function ChangeControl()				{ changeFlag = true; }
	function IsIE()							{ return $.browser.msie; }
	function NotNull(value)					{ if (IsNull(value)) { return(false); } else { return (true); } }
	function ScriptText(value)				{ return !IsNull(value) ? "'" + value + "'" : ''; }
	function Mod(v1, v2)					{ return v1 - (Math.floor(v1 / v2) * v2); }
	function LenControl (obj, len) 			{ if (obj.value == '' || obj.value.length < len) { alert(SCMessage['searchmustlen']); return false; } else return true; }
	function FocusControl(dv, fmt) 			{ if (dv.value == fmt) dv.value = ''; }
	function BlurControl(dv, fmt) 			{ if (dv.value == '') dv.value = fmt; }
	function SetHomePage(url) 				{ document.body.style.behavior='url(#default#homepage)'; document.body.setHomePage(url); }
	function AddFavorites(url, title) 		{ if (window.sidebar) { window.sidebar.addPanel(title, url,""); } else if( window.external ) { window.external.AddFavorite(url, title); } else if(window.opera && window.print) { return true; } }

	function Zero(v, c) {
		var z = '000000000000000000000000000000', tmp = String(v);
		if (tmp.length < c) return z.substr(0, c - tmp.length) + tmp; else return tmp;
	}

	function parseCurr(val) {
		if (IsNull(val)) return 0;
		var reg = new RegExp(SCCurrFormat.moneySymbol, 'gi');
		if (SCCurrFormat.thousandSymbol == ',') { tmp = val.replace(/\,/g, ''); }
		if (SCCurrFormat.thousandSymbol == '.') { tmp = val.replace(/\./g, ''); tmp = tmp.replace(/\,/g, '.'); }
		tmp = tmp.replace(reg, ''); return tmp;
	}

	function IsNull(value) 		{
		if (!value) return(true);
		if (value == null) return(true);
		if (typeof(value) == 'undefined') return(true);
		if (typeof(value) == 'number') { if (isNaN(value)) return(true); }
		if (typeof(value) == 'string') { if (value == '') return(true); }
		return(false);
	}

	function ImageRatio(w, h, r) {
		if (w == h) { if (w > r) return [r, r]; }
		if (w > h) 	{ if (w > r) return [r, Math.floor((h * r) / w)]; }
		if (w < h) 	{ if (h > r) return [Math.floor((w * r) / h), r]; }
		return [w, h];
	}

	function switchText() {
		if ($(this).val() == $(this).attr('title')) { $(this).val('').removeClass('exampleText'); } 
			else { if ($.trim($(this).val()) == '') { $(this).addClass('exampleText').val($(this).attr('title')); } }
	}
	
	function switchTextControl() {
		$('input[type=text][title!=""]').each(function() {
			if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
			if ($(this).val() == $(this).attr('title')) $(this).addClass('exampleText');
		}).focus(switchText).blur(switchText);
		
		$('form').submit(function() {
			$(this).find('input[type=text][title!=""]').each(function() {
				if ($(this).val() == $(this).attr('title')) $(this).val('');
			});
		});
	}

	function MailCheck(obj) {
		var x = obj.val(); if (x != '') { x = x.toLowerCase(); obj.value = x;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (filter.test(x)) { return true; } else { obj.value = ''; alert(SCMessage['mustemail']); obj.focus(); return false; }
		} else return true;
	}

	function ShowQuickClose() {
		if (quickmouseflag == false) { quickwindow.hide('fast'); clearTimeout(quicktimer); return; }
		quicktimer = setTimeout("ShowQuickClose()", 500);
	}

	$.fn.ShowQuickWin = function (quickdiv, iframe, ilink, qwidth, qheight, qleft, qtop, autoclose) {
		//$(this).click(function () {
			if (autoclose == undefined) var autoclose = true;
			var offset = $(this).offset();
			var quickLeft = offset.left, quickTop = offset.top;
			if (qleft) quickLeft = qleft;
			if (qtop) quickTop = qtop;

			if (!qwidth) quickWidth = quickdiv.css('width'); else quickWidth = qwidth;
			if (!qheight) quickHeight = quickdiv.css('height'); else quickHeight = qheight;

			if ((quickLeft + quickWidth) > $(document).width()) quickLeft = (quickLeft - quickWidth) + parseInt($(this).width());
			if ((quickTop + quickHeight) > $(document).height()) quickTop = (quickTop - quickHeight) - parseInt($(this).height());

			var sTop = 0; if (quickTop < $(document).scrollTop()) sTop = $(document).scrollTop() - quickTop + 10;
			var sLeft = 0; if (quickLeft < $(document).scrollLeft()) sLeft = $(document).scrollLeft() - quickLeft + 10;

			quickdiv.css('left', quickLeft+sLeft);
			quickdiv.css('top', quickTop+sTop);
			quickdiv.css('width', quickWidth);
			quickdiv.css('height', quickHeight);
			if (iframe && ilink) {
				iframe.attr('src', '/blank.htm');
				quickdiv.show('fast', function() { iframe.attr('src', ilink); });
			} else { quickdiv.show('fast'); }

			if (autoclose) {
				quickwindow = quickdiv; quicktimer = setTimeout("ShowQuickClose()", 1500);
				$(this).mouseover(function() { quickmouseflag = true; });
				quickdiv.mouseout(function() { quickmouseflag = false; });
				quickdiv.mouseover(function() { quickmouseflag = true; });
			}
		//});
	}

	$.fn.truncate = function(len) { this.val(this.val().substring(0,len)); return false; }
	$.fn.maxLength = function(len, ignore, printcount) {
		var maxLengthKeyPress = new Array();
		var maxLengthChange = new Array();
		var appleKeyOn = false;
  		var useAttr = arguments.length>1 ? arguments[1] : false;
		var keyCount = printcount, textarea = $(this);
		
		var handleCount = function(e) {
    		len = useAttr ? parseInt(textarea.attr('maxlength')) : len;
    		var val = textarea.val(), kcount = len-val.length;
			if (keyCount) { $(keyCount).html(SCMessage['keycount']+' ('+kcount+')'); }
		}
		var handleKeyUp = function(e) { handleCount(); if(e.keyCode==224||e.keyCode==91) appleKeyOn = false; }
  		var handleKeyDown = function(e) { if(e.keyCode==224||e.keyCode==91) appleKeyOn = true; }
  		var handleKeyPress = function(e) {   
			if (ignore) { if ($.inArray(e.keyCode, ignore) !== -1 ) return false; }
    		if(appleKeyOn || (e.charCode==0&&e.keyCode!=13) || e.ctrlKey) return;
    		len = useAttr ? parseInt(textarea.attr('maxlength')) : len;
    		var val = textarea.val();
    		var selected = Math.abs(textarea.attr('selectionStart') - textarea.attr('selectionEnd'));
    		selected = isNaN(selected) ? 0 : selected; //handleCount(); 
    		if(val.length==len && selected<1) { return false; }
    			else { if(val.length>len && selected<(val.length-len)) { return textarea.truncate(len); } }
  		};	
		var handleChange = function(e) { var textarea = $(this); len = useAttr ? parseInt(textarea.attr('maxlength')) : len; textarea.truncate(len); };
    	var removeKeyPress = maxLengthKeyPress[this.selector];
  		var removeChange = maxLengthChange[this.selector];
  		
		this.die('keypress', removeKeyPress);
  		this.die('change', removeChange);
  
  		if (len==0 && !useAttr) return;
  
		this.live('keypress', handleCount);
  		this.live('keypress', handleKeyPress);
  		this.live('change', handleChange);
  		this.live('keydown', handleKeyDown);
  		this.live('keyup', handleKeyUp);

  		maxLengthKeyPress[this.selector] = handleKeyPress;
  		maxLengthChange[this.selector] = handleChange;

  		this.keypress();
	};

	$.fn.KeyControl = function (method) {
		return this.each(function() {
			$(this).keydown(function(e) {
				var ecode = window.event ? e.keyCode : e.which;
				var keychar = String.fromCharCode(ecode), c = (method.substr(0, 1)).toLowerCase(), isCtrl = false;
				isCtrl = window.event ? window.event.ctrlKey : e.ctrlKey;
				if (ecode == 9 || ecode == 8 || ecode == 13 || ecode == 39 || ecode == 37 || isCtrl) return true;
				if (c == 'n') 	{ if ((ecode < 43 || ecode > 57)) return false; }
				if (c == 'e') 	{ if (ecode < 32 || ecode > 122) return false; }
				if (c == 'f') 	{ if ((ecode < 43 || ecode > 57) && ecode != 46 && ecode != 190) return false; }
				if (c == 'd') 	{ if (ecode < 46 || ecode > 57) return false; }
				if (c == 'a') 	{ if ((ecode < 46 || ecode > 57) && ecode != 32) return false; }
				if (c == 't') 	{ if (ecode < 48 || ecode > 58) return false; }
				if (c == 'p') 	{ if (ecode < 48 || ecode > 122) return false; }
			});
			$(this).blur(function() {
				if (method == 'd' || method == 'a') {
					var dateNow = new Date(), rDay, rMonth, rYear, re, dateValue = $(this).val(), tmp = SCDateFormat;
					if (method == 'a') { var dt = dateValue.split(' '), dateValue = dt[0], timeValue = dt[1], rHour, rMinute, rSecond; }
					re = /\./gi; dateValue = dateValue.replace(re, ''); re = /\//gi; dateValue = dateValue.replace(re, '');
					if (dateValue.length == 0 || dateValue == '') 	{ $(this).val(''); return; }
					if (dateValue.length == 2) 	{ rDay = parseFloat(dateValue.substr(0, 2)); rMonth = dateNow.getMonth + 1; rYear = dateNow.getFullYear(); }
					if (dateValue.length == 4) 	{ rDay = parseFloat(dateValue.substr(0, 2)); rMonth = parseFloat(dateValue.substr(2, 2)); rYear = dateNow.getFullYear(); }
					if (dateValue.length == 6) 	{ rDay = parseFloat(dateValue.substr(0, 2)); rMonth = parseFloat(dateValue.substr(2, 2)); rYear = parseFloat(String(rYear).substr(0, 2) + dateValue.substr(4, 2)); }
					if (dateValue.length == 8) 	{ rDay = parseFloat(dateValue.substr(0, 2)); rMonth = parseFloat(dateValue.substr(2, 2)); rYear = parseFloat(dateValue.substr(4, 4)); }
					if ((rDay > 31) || (rDay < 1) || isNaN(rDay)) rDay = dateNow.getDate();
					if ((rMonth > 12) || (rMonth < 1) || isNaN(rMonth)) rMonth = dateNow.getMonth() + 1;
					if ((rYear < 1900) || isNaN(rYear)) { rYear = dateNow.getYear(); if (rYear < 1000) rYear = 1900 + rYear; }
					re = /d/gi; tmp = tmp.replace(re, Zero(rDay.toString(), 2));
					re = /m/gi; tmp = tmp.replace(re, Zero(rMonth.toString(), 2));
					re = /Y/gi; tmp = tmp.replace(re, rYear.toString());
					if (method == 'a') {
						if (timeValue != undefined)  { 
							re = /\:/gi; timeValue = timeValue.replace(re, '');
							if (timeValue.length == 2) { rHour = parseFloat(timeValue.substr(0, 2)); rMinute = timeNow.getMinutes(); rSecond = 0; }
							if (timeValue.length == 4) { rHour = parseFloat(timeValue.substr(0, 2)); rMinute = parseFloat(timeValue.substr(2, 2)); rSecond = 0; }
							if (timeValue.length == 6) { rHour = parseFloat(timeValue.substr(0, 2)); rMinute = parseFloat(timeValue.substr(2, 2)); rSecond = parseFloat(timeValue.substr(4, 2)); }
						} else { rHour = rHour; rMinute = rMinute; rSecond = rSecond; }
						if ((rHour > 23) || isNaN(rHour)) rHour = dateNow.getHours();	
						if ((rMinute > 59) || isNaN(rMinute)) rMinute = dateNow.getMinutes();	
						if ((rSecond > 59) || isNaN(rSecond)) rSecond = 0;
						tmp = tmp + ' ' + Zero(rHour.toString(), 2) + ':' + Zero(rMinute.toString(), 2) + ':' + Zero(rSecond.toString(), 2);
					}
					$(this).val(tmp);
				}
				if (method == 't') {
					var timeValue = $(this).val(), timeNow = new Date(), re, rHour, rMinute, rSecond;
					re = /\:/gi; timeValue = timeValue.replace(re, '');
					if (timeValue.length == 0 || timeValue == '') { $(this).val(''); return; }
					if (timeValue.length == 2) { rHour = parseFloat(timeValue.substr(0, 2)); rMinute = timeNow.getMinutes(); rSecond = 0; }
					if (timeValue.length == 4) { rHour = parseFloat(timeValue.substr(0, 2)); rMinute = parseFloat(timeValue.substr(2, 2)); rSecond = 0; }
					if (timeValue.length == 6) { rHour = parseFloat(timeValue.substr(0, 2)); rMinute = parseFloat(timeValue.substr(2, 2)); rSecond = parseFloat(timeValue.substr(4, 2)); }
					
					if ((rHour > 23) || isNaN(rHour)) rHour = timeNow.getHours();	
					if ((rMinute > 59) || isNaN(rMinute)) rMinute = timeNow.getMinutes();	
					if ((rSecond > 59) || isNaN(rSecond)) rSecond = timeNow.getSeconds();
					$(this).val(Zero(rHour.toString(), 2) + ':' + Zero(rMinute.toString(), 2) + ':' + Zero(rSecond.toString(), 2));
				}
			});
		});
	}

	// HTML SLASHES
	function addslashes(str) {
		str=str.replace(/\'/g,'\\\'');
		str=str.replace(/\"/g,'\\"');
		str=str.replace(/\\/g,'\\\\');
		str=str.replace(/\0/g,'\\0');
		return str;
	}
	function stripslashes(str) {
		str=str.replace(/\\'/g,'\'');
		str=str.replace(/\\"/g,'"');
		str=str.replace(/\\\\/g,'\\');
		str=str.replace(/\\0/g,'\0');
		return str;
	}
	function html_entity_decode( string ) {
		var ret, tarea = document.createElement('textarea');
		tarea.innerHTML = string;
		ret = tarea.value;
		return ret;
	}

	function TCControl(a) {
		if(a.substr(0,1)==0 && a.lenght!=11) { return false; }
		var i = 9, md='', mc='', digit, mr='';
		while(digit = a.charAt(--i)) { i%2==0 ? md += digit : mc += digit; }
		if(((eval(md.split('').join('+'))*7)-eval(mc.split('').join('+')))%10!=parseInt(a.substr(9,1),10)){ return false; }
		for (c=0; c<=9; c++) { mr += a.charAt(c); }
		if(eval(mr.split('').join('+'))%10!=parseInt(a.substr(10,1),10)) { return false; }
		return true;
	}
