//定义当前是否大写的状态
window.onload=
	function()
	{
		password1=null;		
		initcalc();
	}

var capslockvalue=0;

var check;
function setvariables() {
tablewidth=630;  // logo width, in pixels
tableheight=20;  // logo height, in pixels
if (navigator.appname == "netscape") {
horz=".left";
vert=".top";
docstyle="document.";
styledoc="";
innerw="window.innerwidth";
innerh="window.innerheight";
offsetx="window.pagexoffset";
offsety="window.pageyoffset";
}
else {
horz=".pixelleft";
vert=".pixeltop";
docstyle="";
styledoc=".style";
innerw="document.body.clientwidth";
innerh="document.body.clientheight";
offsetx="document.body.scrollleft";
offsety="document.body.scrolltop";
   }
}
function checklocation() {
if (check) {
objectxy="softkeyboard";
var availablex=eval(innerw);
var availabley=eval(innerh);
var currentx=eval(offsetx);
var currenty=eval(offsety);
x=availablex-tablewidth+currentx;
//y=availabley-tableheight+currenty;
y=currenty;

evalmove();
}
settimeout("checklocation()",0);
}
function evalmove() {
//eval(docstyle + objectxy + styledoc + horz + "=" + x);
eval(docstyle + objectxy + styledoc + vert + "=" + y);
}
	self.onerror=null;
	currentx = currenty = 0;  
	whichit = null;           
	lastscrollx = 0; lastscrolly = 0;
	ns = (document.layers) ? 1 : 0;
	ie = (document.all) ? 1: 0;
	function heartbeat() {
		if(ie) { diffy = document.body.scrolltop; diffx = document.body.scrollleft; }
	    if(ns) { diffy = self.pageyoffset; diffx = self.pagexoffset; }
		if(diffy != lastscrolly) {
	                percent = .1 * (diffy - lastscrolly);
	                if(percent > 0) percent = math.ceil(percent);
	                else percent = math.floor(percent);
					if(ie) document.all.softkeyboard.style.pixeltop += percent;
					if(ns) document.softkeyboard.top += percent; 
	                lastscrolly = lastscrolly + percent;}
		if(diffx != lastscrollx) {
			percent = .1 * (diffx - lastscrollx);
			if(percent > 0) percent = math.ceil(percent);
			else percent = math.floor(percent);
			if(ie) document.all.softkeyboard.style.pixelleft += percent;
			if(ns) document.softkeyboard.left += percent;
			lastscrollx = lastscrollx + percent;	}		}
	function checkfocus(x,y) { 
	        stalkerx = document.softkeyboard.pagex;
	        stalkery = document.softkeyboard.pagey;
	        stalkerwidth = document.softkeyboard.clip.width;
	        stalkerheight = document.softkeyboard.clip.height;
	        if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true;
	        else return false;}
	function grabit(e) {
	    check = false;
		if(ie) {
			whichit = event.srcelement;
			while (whichit.id.indexof("softkeyboard") == -1) {
				whichit = whichit.parentelement;
				if (whichit == null) { return true; } }
			whichit.style.pixelleft = whichit.offsetleft;
		    whichit.style.pixeltop = whichit.offsettop;
			currentx = (event.clientx + document.body.scrollleft);
	   		currenty = (event.clienty + document.body.scrolltop); 	
		} else { 
	        window.captureevents(event.mousemove);
	        if(checkfocus (e.pagex,e.pagey)) { 
	                whichit = document.softkeyboard;
	                stalkertouchedx = e.pagex-document.softkeyboard.pagex;
	                stalkertouchedy = e.pagey-document.softkeyboard.pagey;} }
	    return true;	}
	function moveit(e) {
		if (whichit == null) { return false; }
		if(ie) {
		    newx = (event.clientx + document.body.scrollleft);
		    newy = (event.clienty + document.body.scrolltop);
		    distancex = (newx - currentx);    distancey = (newy - currenty);
		    currentx = newx;    currenty = newy;
		    whichit.style.pixelleft += distancex;
		    whichit.style.pixeltop += distancey;
			if(whichit.style.pixeltop < document.body.scrolltop) whichit.style.pixeltop = document.body.scrolltop;
			if(whichit.style.pixelleft < document.body.scrollleft) whichit.style.pixelleft = document.body.scrollleft;
			if(whichit.style.pixelleft > document.body.offsetwidth - document.body.scrollleft - whichit.style.pixelwidth - 20) whichit.style.pixelleft = document.body.offsetwidth - whichit.style.pixelwidth - 20;
			if(whichit.style.pixeltop > document.body.offsetheight + document.body.scrolltop - whichit.style.pixelheight - 5) whichit.style.pixeltop = document.body.offsetheight + document.body.scrolltop - whichit.style.pixelheight - 5;
			event.returnvalue = false;
		} else { 
			whichit.moveto(e.pagex-stalkertouchedx,e.pagey-stalkertouchedy);
	        if(whichit.left < 0+self.pagexoffset) whichit.left = 0+self.pagexoffset;
	        if(whichit.top < 0+self.pageyoffset) whichit.top = 0+self.pageyoffset;
        if( (whichit.left + whichit.clip.width) >= (window.innerwidth+self.pagexoffset-17)) whichit.left = ((window.innerwidth+self.pagexoffset)-whichit.clip.width)-17;
	        if( (whichit.top + whichit.clip.height) >= (window.innerheight+self.pageyoffset-17)) whichit.top = ((window.innerheight+self.pageyoffset)-whichit.clip.height)-17;
	        return false;}
	    return false;	}
	function dropit() {whichit = null;
	    if(ns) window.releaseevents (event.mousemove);
	    return true;	}
	if(ns) {window.captureevents(event.mouseup|event.mousedown);
		window.onmousedown = grabit;
	 	window.onmousemove = moveit;
		window.onmouseup = dropit;	}
	if(ie) {
		document.onmousedown = grabit;
	 	document.onmousemove = moveit;
		document.onmouseup = dropit;	}
//	if(ns || ie) action = window.setinterval("heartbeat()",1);



	document.write("<div align=center id=\"softkeyboard\" name=\"softkeyboard\" style=\"position:absolute; left:0px; top:0px; width:500px; z-index:180;display:none\">  <table id=\"calctable\" width=\"\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"\">           <form id=calc name=calc action=\"\" method=post autocomplete=\"off\">       <tr> <td title=\"为了保证后台登陆安全,建议使用密码输入器输入密码!\" align=\"right\" valign=\"middle\" bgcolor=\"\" style=\"cursor: default;height:30\"> <input type=hidden value=\"\" name=password>  <input type=hidden value=ok name=action2>&nbsp<font style=\"font-size:13px;\">网趣购物系统xp版 </font>&nbsp;&nbsp;密码输入器&nbsp&nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;<input style=\"width:100px;height:20px;background-color:#54baf1;\" type=button value=\"使用键盘输入\" bgtype=\"1\" onclick=\"password1.readonly=0;password1.focus();softkeyboard.style.display='none';password1.value='';\"><span style=\"width:2px;\"></span></td>      </tr>      <tr align=\"center\">         <td align=\"center\" bgcolor=\"#ffffff\"> <table align=\"center\" width=\"%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">\n          <tr align=\"left\" valign=\"middle\"> \n            <td> <input type=button value=\" ~ \"></td>\n            <td> <input type=button value=\" ! \"></td>\n            <td> <input type=button  value=\" @ \"></td>\n            <td> <input type=button value=\" # \"></td>\n            <td> <input type=button value=\" $ \"></td>\n            <td> <input type=button value=\" % \"></td>\n            <td> <input type=button value=\" ^ \"></td>\n            <td> <input type=button value=\" & \"></td>\n            <td> <input type=button value=\" * \"></td>\n            <td> <input type=button value=\" ( \"></td>\n            <td> <input type=button value=\" ) \"></td>\n            <td> <input type=button value=\" _ \"></td>\n            <td> <input type=button value=\" + \"></td>\n            <td> <input type=button value=\" | \"></td>\n            <td colspan=\"1\" rowspan=\"2\"> <input name=\"button10\" type=button value=\" 退格\" onclick=\"setpassvalue();\"  ondblclick=\"setpassvalue();\" style=\"width:100px;height:42px\"> \n            </td>\n          </tr>\n          <tr align=\"left\" valign=\"middle\"> \n            <td> <input type=button value=\" ` \"></td>\n            <td> <input type=button value=\" 1 \"></td>\n            <td> <input type=button value=\" 2 \"></td>\n            <td> <input type=button value=\" 3 \"></td>\n            <td> <input type=button value=\" 4 \"></td>\n            <td> <input type=button value=\" 5 \"></td>\n            <td> <input type=button value=\" 6 \"></td>\n            <td> <input type=button value=\" 7 \"></td>\n            <td> <input type=button value=\" 8 \"></td>\n            <td> <input type=button value=\" 9 \"></td>\n            <td> <input name=\"button6\" type=button value=\" 0 \"></td>\n            <td> <input type=button value=\" - \"></td>\n            <td> <input type=button value=\" = \"></td>\n            <td> <input type=button value=\" \\ \"></td>\n            <td> </td>\n          </tr>\n          <tr align=\"left\" valign=\"middle\"> \n            <td> <input type=button value=\" q \"></td>\n            <td> <input type=button value=\" w \"></td>\n            <td> <input type=button value=\" e \"></td>\n            <td> <input type=button value=\" r \"></td>\n            <td> <input type=button value=\" t \"></td>\n            <td> <input type=button value=\" y \"></td>\n            <td> <input type=button value=\" u \"></td>\n            <td> <input type=button value=\" i \"></td>\n            <td> <input type=button value=\" o \"></td>\n            <td> <input name=\"button8\" type=button value=\" p \"></td>\n            <td> <input name=\"button9\" type=button value=\" { \"></td>\n            <td> <input type=button value=\" } \"></td>\n            <td> <input type=button value=\" [ \"></td>\n            <td> <input type=button value=\" ] \"></td>\n            <td><input name=\"button9\" type=button onclick=\"capslocktext();setcapslock();\"  ondblclick=\"capslocktext();setcapslock();\" value=\"切换大/小写\" style=\"width:100px;\"></td>\n          </tr>\n          <tr align=\"left\" valign=\"middle\"> \n            <td> <input type=button value=\" a \"></td>\n            <td> <input type=button value=\" s \"></td>\n            <td> <input type=button value=\" d \"></td>\n            <td> <input type=button value=\" f \"></td>\n            <td> <input type=button value=\" g \"></td>\n            <td> <input type=button value=\" h \"></td>\n            <td> <input type=button value=\" j \"></td>\n            <td> <input name=\"button3\" type=button value=\" k \"></td>\n            <td> <input name=\"button4\" type=button value=\" l \"></td>\n            <td> <input name=\"button5\" type=button value=\" : \"></td>\n            <td> <input name=\"button7\" type=button value=\" &quot; \"></td>\n            <td> <input type=button value=\" ; \"></td>\n            <td> <input type=button value=\" ' \"></td>\n            <td rowspan=\"2\" colspan=\"2\"> <input name=\"button12\" type=button onclick=\"overinput();\" value=\"   确定  \" style=\"width:130px;height:42\"></td>\n          </tr>\n          <tr align=\"left\" valign=\"middle\"> \n            <td> <input name=\"button2\" type=button value=\" z \"></td>\n            <td> <input type=button value=\" x \"></td>\n            <td> <input type=button value=\" c \"></td>\n            <td> <input type=button value=\" v \"></td>\n            <td> <input type=button value=\" b \"></td>\n            <td> <input type=button value=\" n \"></td>\n            <td> <input type=button value=\" m \"></td>\n            <td> <input type=button value=\" &lt; \"></td>\n            <td> <input type=button value=\" &gt; \"></td>\n            <td> <input type=button value=\" ? \"></td>\n            <td> <input type=button value=\" , \"></td>\n            <td> <input type=button value=\" . \"></td>\n            <td> <input type=button value=\" / \"></td>\n          </tr>\n        </table></td>    </form>      </tr>  </table></div>")
//给输入的密码框添加新值
	function addvalue(newvalue)
	{
		if (capslockvalue==0)
		{
			var str=calc.password.value;
			if(str.length<password1.maxlength)
			{
				calc.password.value += newvalue;
			}			
			if(str.length<=password1.maxlength)
			{
				password1.value=calc.password.value;
			}
		}
		else
		{
			var str=calc.password.value;
			if(str.length<password1.maxlength)
			{
				calc.password.value += newvalue.touppercase();
			}
			if(str.length<=password1.maxlength)
			{
				password1.value=calc.password.value;
			}
		}
	}
//实现backspace键的功能
	function setpassvalue()
	{
		var longnum=calc.password.value.length;
		var num
		num=calc.password.value.substr(0,longnum-1);
		calc.password.value=num;
		var str=calc.password.value;
			password1.value=calc.password.value;
	}
//输入完毕
	function overinput()
	{
		//m_pass.mempass.value=calc.password.value;
		var str=calc.password.value;
			password1.value=calc.password.value;
			//alert(theform.value);
		//theform.value=m_pass.mempass.value;
		softkeyboard.style.display="none";
		calc.password.value="";
		password1.readonly=1;
		//password1.value=calc.password.value;
	}
//关闭软键盘
	function closekeyboard(theform)
	{
		//eval("var theform="+theform+";");
		//theform.value="";
		softkeyboard.style.display="none";
		//calc.password.value="";

	}
//显示软键盘
	function showkeyboard()
	{
		if(event.y+140)
		softkeyboard.style.top=event.y+document.body.scrolltop+15;
		if((event.x-250)>0)
		{
			softkeyboard.style.left=event.x-250;
		}
		else
		{
			softkeyboard.style.left=0;
		}
		
		softkeyboard.style.display="block";
		password1.readonly=1;
		password1.blur();
		//password1.value="";
	}

//设置是否大写的值
function setcapslock()
{
	if (capslockvalue==0)
	{
		capslockvalue=1
//		calc.showcapslockvalue.value="当前是大写 ";
	}
	else 
	{
		capslockvalue=0
//		calc.showcapslockvalue.value="当前是小写 ";
	}
}


function setcalcborder()
{
	calctable.style.border="1px solid #0090fd"
}

function sethead()
{
	calctable.cells[0].style.backgroundcolor="#7edeff"	
}

function setcalcbuttonbg()
{
	for(var i=0;i<calc.elements.length;i++)
	{
		if(calc.elements[i].type=="button"&&calc.elements[i].bgtype!="1")
		{
	//		if(i==10)
//	alert(123);
			calc.elements[i].style.bordertopwidth= 0
			calc.elements[i].style.borderrightwidth= 2
			calc.elements[i].style.borderbottomwidth= 2
			calc.elements[i].style.borderleftwidth= 0
			calc.elements[i].style.bordertopstyle= "none";
			calc.elements[i].style.borderrightstyle= "solid";
			calc.elements[i].style.borderbottomstyle= "solid";
			calc.elements[i].style.borderleftstyle= "none";
			//#46ac17
			calc.elements[i].style.bordertopcolor= "#118acc";
			calc.elements[i].style.borderrightcolor= "#118acc";
			calc.elements[i].style.borderbottomcolor= "#118acc";
			calc.elements[i].style.borderleftcolor= "#118acc";
			//#cbf3b2
			calc.elements[i].style.backgroundcolor="#addef8";

			
			
			var str1=calc.elements[i].value;
			str1=str1.trim();
			/*
			if(str1=="`") 
			{
				calc.elements[i].style.fontsize=14;
			}
			*/

			if(str1.length==1)
			{
				//calc.elements[i].style.fontsize=16;
				//calc.elements[i].style.fontweight='bold';
			}
			
			var thisbuttonvalue=calc.elements[i].value;
			thisbuttonvalue=thisbuttonvalue.trim();
			if(thisbuttonvalue.length==1)
			{
				calc.elements[i].onclick=
					function ()
					{
						var thisbuttonvalue=this.value;
						thisbuttonvalue=thisbuttonvalue.trim();
						addvalue(thisbuttonvalue);
						//alert(234)
					}
				calc.elements[i].ondblclick=
					function ()
					{
						var thisbuttonvalue=this.value;
						thisbuttonvalue=thisbuttonvalue.trim();
						addvalue(thisbuttonvalue);
						//alert(234)
					}
			}
			
		}
	}
}

function initcalc()
{
	setcalcborder();
	sethead();
	setcalcbuttonbg();
}

string.prototype.trim = function()
{
    // 用正则表达式将前后空格
    // 用空字符串替代。
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

var capslockflag;
capslockflag=true;

function capslocktext()
{
if(capslockflag)//改成大写
{
	for(var i=0;i<calc.elements.length;i++)
	{
			var char=calc.elements[i].value;
			var char=char.trim()
		if(calc.elements[i].type=="button"&&char>="a"&&char<="z"&&char.length==1)
		{
		
			calc.elements[i].value=" "+string.fromcharcode(char.charcodeat(0)-32)+" "
		}
	}
}
else
{
	for(var i=0;i<calc.elements.length;i++)
	{
			var char=calc.elements[i].value;
			var char=char.trim()
		if(calc.elements[i].type=="button"&&char>="a"&&char<="z"&&char.length==1)
		{
		
			calc.elements[i].value=" "+string.fromcharcode(char.charcodeat(0)+32)+" "
		}
	}
}
capslockflag=!capslockflag;
}

window.onload=
	function ()
	{
		password1=null;		
		initcalc();
		

	}




