function fixWidth(id,min){
	//alert(window.navigator.userAgent);
	if(window.navigator.userAgent.indexOf("MSIE")<0)return;
	document.getElementById(id).style.width=((window.innerWidth||document.body.clientWidth)>min)?"100%":min+"px";
}


//addForm
function popup(flag){
	if(flag){
		document.getElementById('addForm').style.display='block';
	}
	else{
		document.getElementById('addForm').style.display='none';
	}
}

document.onmousedown = function(ev) {
	var ev = ev || window.event;
	var target = ev.target || ev.srcElement;
	if(document.getElementById('File1')){
		if (target && target.id == 'login' ) { 
			popup(true);
		}else{
			while(target.parentNode&&(target.id!='addForm')){
				target=target.parentNode;
			}
			if(!target.parentNode)popup(false);
		}
	}
}

/*function popup(){
	document.getElementById('addForm').style.display='block';
}*/

function testFile(){
	if(document.getElementById('File1')){
		var fileInput = document.getElementById('File1');
		var fileName = document.createElement('div');
		var activeButton = document.createElement('div');
		var bb = document.createElement('div');
		var bl = document.createElement('div');
		var wrap = document.getElementById('wrapIn');
		fileName.setAttribute('id','FileName');
		activeButton.setAttribute('id','activeBrowseButton');
		fileInput.value = '';
		fileInput.onchange = function test(){
			file = fileInput.value;
			fileTitle = fileInput.value.replace(/.*[\\\/]/, '');
			fileName.innerHTML = fileTitle;
		}		
		fileInput.className = 'customFile';
		activeButton.className = 'fakeButton';
		wrap.appendChild(activeButton);
		wrap.appendChild(fileName);
	}
}

//Сначала был init...
function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (_timer) {
		clearInterval(_timer);
		_timer = null;
	}
	// insert
	fixWidth('root',1004);
	testFile();
	// end
};
/* for Mozilla */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 50);
}


/* for other browsers */
window.onload = init;
