
var who= document.createElement('span');

var imgobj;
var Opera = navigator.userAgent.indexOf('Opera') != -1 ? true : false;

var Ie7;
var nullAddress;
var changedAddress = false;
var adr;

function InitSubscrbe(address){
	adr = address;
	window.onload = function() {InitSubscrbe_On(adr);}
}

function InitSubscrbe_On(address){
	var atts = {fontSize:'1em',padding:'0',margin:'0',position:'absolute',lineHeight:'100%',visibility:'hidden',fontWeight:'bold',whiteSpace:'nowrap'};

	nullAddress = address;

	for (var p in atts){
		who.style[p]= atts[p];

	}
	who.appendChild(document.createTextNode('subscribe'));

	pa = document.getElementById('subscribeform') || document.body;
	pa.appendChild(who);

	Ie7 = window.ie7 != undefined ? true : false;

	var subsin = document.getElementById('subsin');
	subsin.style.color = "#666666";
	subsin.value = address;

	subsin.onkeydown = function(event){
		if( ! event)
			event = window.event;
		if(event && (event.keyCode == 8 || event.keyCode == 46 || event.which == 8 || event.which == 46))
			calibrate(this, null);
	}
   	subsin.onkeypress = function(event){
    	if( ! event)
			event = window.event;
		calibrate(this, event);
	}
    subsin.onfocus = function(){
   		if(this.value == '' || this.value == nullAddress){
			this.style.color = "#222222";
			this.value = '';
		}else
			calibrate(this, null);
	}
	subsin.onblur = function(){
		this.style.width = '107px';
		this.parentNode.style.width = '100%';
		this.parentNode.style.marginLeft = this.parentNode.style.marginRight = '0px';
		this.parentNode.parentNode.style.width = '175px';
		this.parentNode.parentNode.style.marginLeft = this.parentNode.parentNode.style.marginRight = '0px'
		if(this.value == '' || this.value == nullAddress){
			this.style.color = "#666666";
			this.value = nullAddress;
		}
	}

	//pa.removeChild(who);
}

document.pxWidth = function(val){
	who.innerHTML = val;
 	return who.offsetWidth;
}


function calibrate(obj, e)
{
	var keynum;
	var keychar = '';

	if (e)
		if(window.event){
	  		keynum = e.keyCode;
	  	}
		else if(e.which){
	  		keynum = e.which;
	  	}

	keychar = String.fromCharCode(keynum);

	if (keynum == undefined || keynum == 8)
	{
		keychar = '';
		if (e != null)
			return;
	}

	//alert(keychar);

	imgobj = imgobj || document.getElementById('sendsubsimg');
	var w = document.pxWidth(obj.value + keychar) + 7 - (keynum == 8 ? 10 : 0);

	//document.getElementById('testmsg').innerHTML = obj.value + keychar + ' ' + w + ' ' + keynum;

	if (w >= 107) {
		obj.style.width = w + 'px';
		obj.style.textAlign='center';
		if (Opera) {
			if (w >= 175 - 25){
				obj.parentNode.style.width = w + 25 + 'px';
				obj.parentNode.style.marginRight = obj.parentNode.style.marginLeft = - (w + 25 - 175)/2 + 'px';
			}
        } else if (Ie7) {
			if (w >= 175 - 25){
				obj.parentNode.parentNode.style.width = w + 25 + 'px';
				obj.parentNode.parentNode.style.marginRight = obj.parentNode.parentNode.style.marginLeft = - (w + 25 - 175)/2 + 'px';
			}
		} else {
			imgobj.style.right = obj.style.marginRight = obj.style.marginLeft = - (w - 107)/2 + 'px';
		}
	} else {
		obj.style.width = '107px';
		obj.style.textAlign='left'
	}
}

