﻿var ArrayKeyBoard=new Array();

function Browser() {
	var b=navigator.appName;
	this.safari=false;
	if ((b=="Safari") || (navigator.userAgent.indexOf("Safari")>0)) this.safari = true;
	if (b=="Netscape") this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	if (!b) alert('Unidentified browser./nThis browser is not supported,');
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	this.ns6=(this.b=="ns" && this.v==5);
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.ie6=(this.version.indexOf('MSIE 6')>0);
	this.opera=(this.b=="opera");
	this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	var ua=navigator.userAgent.toLowerCase();
	if (ua.indexOf("win")>-1) this.platform="win32";
	else if (ua.indexOf("mac")>-1) this.platform="mac";
	else this.platform="other";
	
	
}
is = new Browser();


var objVP;
var onVP=false;
function startDrag(e) 
{
  	
if (is.platform!="mac")  {

if (onVP==true)
  	{
		objVP = document.getElementById("MagicVirtualPadLayer");
		objVP = objVP.style;
		if (is.ie)
		{
			X = event.clientX-objVP.pixelLeft;
			Y = event.clientY-objVP.pixelTop;			
		}
		else		
		{
			X = e.clientX-parseInt(objVP.left);
			Y = e.clientY-parseInt(objVP.top);
		}
	}
		}
}

function drag(e) 
{

if (is.platform!="mac") 	{

if (objVP) 
	{
		if (is.ie)
		{
			objVP.pixelTop = event.clientY-Y;
			objVP.pixelLeft = event.clientX-X;		
		}
		else
		{
			objVP.left = parseInt(e.clientX)-X;

			objVP.top = parseInt(e.clientY)-Y;
		}
		return false;
	}  
	}  
}


function endDrag() 
{
	objVP = null;
}

function lcase(ch) {
		if (ch=='İ') {return 'i';}
		if (ch=='I') {return 'ı';}
		if (ch=='Ğ') {return 'ğ';}
		if (ch=='Ş') {return 'ş';}
		if (ch=='Ö') {return 'ö';}
		if (ch=='Ü') {return 'ü';}
		if (ch=='Ç') {return 'ç';}
		return ch.toLowerCase();
	}

function ucase(ch) {
	
	if (ch=='i') {return 'İ';}
	if (ch=='ı') {return 'I';}
	if (ch=='ğ') {return 'Ğ';}
		if (ch=='ş') {return 'Ş';}
		if (ch=='ö') {return 'Ö';}
		if (ch=='ü') {return 'Ü';}
		if (ch=='ç') {return 'Ç';}
	return ch.toUpperCase();
}

document.onmousedown = startDrag;
document.onmousemove = drag; 
document.onmouseup = endDrag;
	
function MagicVirtualPad(nm) {
		this.QPad='1234567890';
		this.maxlength=1;
		this.keyPad=this.QPad;
		
		this.strHTML='';
		this.name=nm;
		this.cs=false;
		this.closed=false;
		this.visible=false;
		this.currentKeyValue='';
		this.currentInputObject='none';
		this.currentKeyObject='none';
		this.mdown=false;
		this.mdownStr=' ';
}

MagicVirtualPad.prototype.show=function() {
	if (!this.closed) {
		this.visible=true;
		document.getElementById("MagicVirtualPadLayer").style.visibility='visible';
		if (is.platform=='mac' && !is.ie) {
			this.updateKeyValues();
		}
	}
}

MagicVirtualPad.prototype.hide=function() {
	if (!this.closed) {
		this.visible=false;
		document.getElementById("MagicVirtualPadLayer").style.visibility='hidden';
	}
}

MagicVirtualPad.prototype.close=function() {
	this.hide();
	this.closed=true;
	this.loseFocus();
}

MagicVirtualPad.prototype.open=function() {
	this.show();
	this.closed=false;
}

MagicVirtualPad.prototype.del=function() {
	
	if (document.getElementById(this.currentInputObject).value.length>0) {
		ostr=document.getElementById(this.currentInputObject).value;
		ostr=ostr.substr(0,ostr.length-1);
		document.getElementById(this.currentInputObject).value=ostr;
	}
}


MagicVirtualPad.prototype.init=function() {
	
	lf=(parseInt(parseInt(document.body.scrollWidth)-701)/2)+260;
	lf=parseInt(lf);
	this.divHTML='';
	if (is.platform!='mac') {
		this.divHTML+='<div id="MagicVirtualPadLayer" style="position:absolute;left:60%;top:200px;width:144px;visibility:hidden;height:216px;z-index:999;">';
	} else {
		this.divHTML+='<div id="MagicVirtualPadLayer" style="position:absolute;left:'+900+'px;top:260px;width:144px;visibility:hidden;height:216px;z-index:999;">';
	}
	
	
	
	this.divHTML+='</div>';
	this.createKeyBoard();
	if (is.ns) {
		document.write(this.divHTML);
		document.write('<div id="tempDiv">'+this.strHTML+'</div>');
		document.getElementById('MagicVirtualPadLayer').innerHTML=document.getElementById('tempDiv').innerHTML;
		document.getElementById('tempDiv').innerHTML='';
	} else {
		document.getElementById('PadContent').innerHTML=this.divHTML;
		document.getElementById('MagicVirtualPadLayer').innerHTML=this.strHTML;
	}
}


MagicVirtualPad.prototype.initOnResize=function() {
	
}


MagicVirtualPad.prototype.createKeyBoard=function () {
	this.strHTML='';
	this.strHTML+='<table cellpadding="0" cellspacing="0" border="0" width="144">';
		this.strHTML+='<tr onMouseDown="onVP=true" onMouseUp="onVP=false;'+this.name+'.clicked(-100)">';
			this.strHTML+='<td height="18" valign="bottom" align="right" bgcolor="#FFDA8C" style="padding-right:10px;"><a href="javascript:'+this.name+'.close();"><span class="qmarkt">x</span></a></td>';
		this.strHTML+='</tr>';
		this.strHTML+='<form id="MagicVirtualPadForm">';
		
		
	this.strHTML+='<tr><td align="center" valign="top"  bgcolor="White" style="border:2px solid #FFDA8C;"><br>';
	
	for (i=0;i<=9;i++) {
		
		k=this.keyPad.charAt(i);
		
		this.strHTML+='<input id="MagicVirtualPadKey'+i+'" type="button" class="keyBoard1" value="'+k+'" onMouseUp="'+this.name+'.clicked('+i+')" onMouseDown="'+this.name+'.setStars(this);">';
		
		if (i==2 || i==5 || i==8) {this.strHTML+='<br>'}
	}

	this.strHTML+='<input id="mask" type="button" class="keyBoard1" value=" " onMouseUp="'+this.name+'.forwardClick()" style="position:absolute;display:none;" onMouseOut="'+this.name+'.clearStars();">';
	
		
	this.strHTML+='<br><br /><table cellpadding="0" cellspacing="0" border="0" align="center">';
		this.strHTML+='<tr>';
			this.strHTML+='<td><input type="button" value="Karıştır" class="keyboard2" style="width:66px;" onClick="'+this.name+'.obfuscate()"></td>';
			this.strHTML+='<td width="40" align="right"><input type="button" value="Sil" class="keyboard2" style="width:28px;color:#FFFFFF;padding-left:3px;" onClick="'+this.name+'.del();" style="cursor:hand;"></td>';
		this.strHTML+='</tr>';
	this.strHTML+='</table>';
	

	this.strHTML+='<br /></td></tr></form>';
	
	this.strHTML+='</table>';
}

MagicVirtualPad.prototype.clicked=function (I) {
	if(this.mdown) {
		this.clearStars();
		this.currentKeyValue=this.keyPad.charAt(I);
		if (this.currentInputObject!='none') {
			
			if (document.getElementById(this.currentInputObject).value.length<this.maxlength) {
				document.getElementById(this.currentInputObject).value+=this.currentKeyValue;
			} else {
				if (I!=-100) {
					alert('Bu alana '+this.maxlength+' karakterden fazla giremezsiniz.');
				}
			}
			this.putFocus();
		}
	}
}
MagicVirtualPad.prototype.setStars=function(obj) {
	if(!this.mdown) {
		this.currentKeyObject=obj;
		obj.className=obj.className+" noborder";
		
		this.mdown=true;
		this.keyPadClon=this.keyPad;
		arr=this.keyPad.split('');
		
		for (i=0;i<arr.length;i++) {
			arr[i]=this.mdownStr;
		}
		
		this.keyPad=arr.join('');
		if(!is.ie || is.platform!='mac') {
			this.updateKeyValues();
			
			xPos=parseInt(obj.offsetLeft)+obj.offsetParent.offsetLeft+4;
			yPos=parseInt(obj.offsetTop)+obj.offsetParent.offsetTop+4;
			if(is.ns6 && is.platform!='mac') {
				xPos-=obj.offsetParent.offsetLeft+4;
				yPos-=obj.offsetParent.offsetTop+4;
			}
			cls=new Array();
			cls=this.currentKeyObject.className.split(' ');
			document.getElementById("mask").style.width=obj.style.width;
			document.getElementById("mask").className=cls[0];
			document.getElementById("mask").style.top=yPos;
			document.getElementById("mask").style.left=xPos;
			document.getElementById("mask").style.display='block';
			document.getElementById("mask").value=this.mdownStr;
		}
	}
}

MagicVirtualPad.prototype.clearStars=function() {
	if(this.mdown) {
		cls=new Array();
		cls=this.currentKeyObject.className.split(' ');
		this.currentKeyObject.className=cls[0];
		
		this.keyPad=this.keyPadClon;
		this.mdown=false;
		if(!is.ie || is.platform!='mac') {
			this.updateKeyValues();
			document.getElementById("mask").style.display='none';
		}
		//this.currentKeyObject.blur();
	}
}

MagicVirtualPad.prototype.loseFocus=function () {
	this.currentInputObject='none';
}

MagicVirtualPad.prototype.getFocus=function (o,ml) {
	this.maxlength=ml;
	this.open();
	this.currentInputObject=o;
}

MagicVirtualPad.prototype.putFocus=function() {
	if (this.currentInputObject!='none') {
		document.getElementById(this.currentInputObject).focus();
	}
	
	this.open();
	
}


MagicVirtualPad.prototype.obfuscate=function() {
	arr=this.keyPad.split('');
	for (i=0;i<=9;i++) {
		r=Math.floor(Math.random(0)*10);
		tmp=arr[i];
		arr[i]=arr[r];
		arr[r]=tmp;
	}
	
	this.keyPad=arr.join('');
	ArrayKeyBoard=this.keyPad.split('');
	this.updateKeyValues();
	
}


MagicVirtualPad.prototype.clear=function () {
	if (this.currentInputObject!='none') {
		document.getElementById(this.currentInputObject).value='';
		this.putFocus();
	}
}

MagicVirtualPad.prototype.updateKeyValues=function() {
	
	if (is.platform=='mac' && (!is.ns || is.safari)) {
		this.createKeyBoard();
		document.getElementById('MagicVirtualPadLayer').innerHTML=this.strHTML;
	} else {
		
		for (i=0;i<=9;i++) {
			document.getElementById('MagicVirtualPadKey'+i).value=this.keyPad.charAt(i);
		}
	}
	
}

MagicVirtualPad.prototype.forwardClick=function() {
	i=parseInt(this.currentKeyObject.id.substr(18,1));
	this.clicked(i);
}

function keyboardMessage() {
	//alert('Lütfen sanal klavyeyi kullanınız.');
	return true;
}

//Dışbank Functions
 var ok_state = 'FALSE'; function check_ok(){
                                if (ok_state == 'FALSE') {ok_state = 'TRUE'; document.forms[0].submit(); return;}
                                else {return false;} }
function keyboardMessage() {
	alert('Şifrenizi girerken lütfen Sanal Klavye\'yi kullanınız.');
	return false;
}

bw=20;
	if (is.safari) {
		bw=50;
	} else if (is.platform=='mac' && is.ie) {
		bw=100;
	} 
	
		document.write('<style>');
		document.write('.keyBoard1 {width:25px;height:25px;margin:1px;border-right:1px solid #006699;border-left:1px solid #006699;border-top:1px solid #006699;border-bottom:1px solid #006699;font-size:9px;font-family:Geneva, Tahoma;font-weight:bold;color:black;background-color:#EFEFEF;}');
		document.write('.keyBoard2 {width:'+bw+'px;height:20px;margin:1px;font-size:11px;font-family:Verdana, Tahoma;font-weight:bold;color:white;background-color:#6699cc;}');
		document.write('.noborder {border-width:0px;}');
		//document.write('.qmarkt {font-family:Geneva, Tahoma;font-weight:bold;color:Black;}');
		document.write('.qmarkt 		 { font-family: arial; font-size: 12pt; color: #000000; text-decoration:none}');
		document.write('A.qmarkt:Hover	 { color: #FF0000 }')
		document.write('</style>');
		

