$(document).keydown(function(event){
  if (event.keyCode == 8) {
      if (Ext.isIE)
            if (!event.target.isContentEditable) event.preventDefault();
  }
});

/*content in .indexIntr, change with tabs*/
function changeContentWithTabs(currentTab){
	$(".intro > div.infoline").hide();
	$(".intro #"+currentTab+"_min_cont").show();
}

/* jquery clicable tabs_new*/
function tabsClickablePreview() {
	var currentObject = 0;
	$(".block_with_tabs .tabs_new li a").click(function(){
		var bwt = $('.block_with_tabs');
		var t = $(this);
		var li = t.parent();
		var hash = t.attr('href').split('#')[1];
		bwt.find('.current').removeClass('current');
		li.addClass("current");
		currentObject = li.attr("id");
		bwt.find(".box #"+currentObject+"_cont").addClass("current");
		if(hash){
			document.location.hash = hash;
		}
		changeContentWithTabs(currentObject);
		bwt = null; t=null; li=null;
		return false;
	});
}

/* function add or remove class="active" */
function ClickAddOrRemoveClassActive() {
	$(".faq_slider .faq_quest").toggle(
		function () {
			$(this).addClass("active");
			$(this).next().fadeIn(300);
		},
		function () {
			$(this).removeClass("active");
			$(this).next().fadeOut(300);
		}
	);
}


function feedbackFromUser() {
	$(".feedback_from_user .user_blank").hover(
		function () {
			$(this).find(".user_blank_pop_up").fadeIn(50);
		},
		function () {
			$(this).find(".user_blank_pop_up").fadeOut(50);
		}
	);
}


function navigateByHash(){
	var hash = document.location.hash;
	if (hash) {
	   $('.block_with_tabs .tabs_new li a[href='+hash+']').click();
	}
}

function watchForHash(){
	if(document.location.hash != window.prevoiusDocumentHash){
        window.prevoiusDocumentHash = document.location.hash;
        navigateByHash();
	}
    setTimeout(watchForHash,100);
}


/*delete word "password" when browser write his automatically*/
function deletePsswordWord(){
	$(".login .input_login #password").change(function(){
		$(this).css({"background-image":"url('../img/bg_password_input_enter_form_clean.jpg')"});
	});
	
		$(".top .center_aligner").mousemove(function(){
			var check_val_password = $(".login .input_login #password").val();
			if(check_val_password != "") {
				$(".login .input_login #password").css({"background":"url('../img/bg_password_input_enter_form_clean.jpg') no-repeat -3px 0px"});
			}
			
			if(check_val_password == "") {
				$(".login .input_login #password").css({"background":"url('../img/bg_password_input_enter_form.png') no-repeat -3px 0px"});
			}
		});
			
}

$(document).ready(function(){ 
	deletePsswordWord();
	ClickAddOrRemoveClassActive();
	feedbackFromUser();
});

$(document).keypress(function(event){
  if (event.keyCode == 8) {
    if (event.target.readOnly != false)
        event.preventDefault();
  }
});

function getChildNodes(node){ 
	var childArray = new Array(); 
	for(var i=0; i<node.childNodes.length; i++){ 
		if(node.childNodes[i].nodeName.substr(0,1) != "#"){ 
			childArray[childArray.length] = node.childNodes[i]; 
		} 
	} 
	return childArray; 
}

function getTmpTime () {
	var tDate=new Date();
//	return tDate.getMinutes()+""+tDate.getSeconds()+""+tDate.getMilliseconds();
	return tDate.getTime();
}

function getNodeById(node, id){ 
	for(var i=0; i<node.childNodes.length; i++){ 
		if(node.childNodes[i].id && node.childNodes[i].id == id){ 
			return node.childNodes[i];
		} 
		if (node.childNodes[i].childNodes.length>0) {
			var ret=getNodeById(node.childNodes[i], id);
			if (ret!=null) return ret;
		}
	} 
	return null; 
}

function getObj (id) {
	return document.getElementById(id);
}

function checkUrl (url) {
	var check_url=url.split("?");
	if (check_url.length>1) { url+='&';}
	else{ url+='?';}
	return url;
}

function findPosX(obj) { 
	var curleft=0; 
	if (obj.offsetParent) { 
		while (obj.offsetParent) { 
			curleft+=getOffsets(obj).x;
			obj=obj.offsetParent;
		} 
	} else if (obj.x) curleft += obj.x; //NETSCAPE 4 ONLY 
	return curleft; 
}

function getOffsets(obj) {
	var offsetLeft=0, offsetTop=0;
	if (document.getBoxObjectFor) {
		var box=document.getBoxObjectFor(obj);
		offsetLeft=box.x;
		offsetTop=box.y;
	} else if (obj.getBoundingClientRect) {
		var rect=obj.getBoundingClientRect();
		offsetLeft=rect.left;
		offsetTop=rect.top;
	} else {
		do {
			offsetLeft+=obj.offsetLeft||0;
			offsetTop+=obj.offsetTop||0;
			obj=obj.offsetParent;
		} while (obj);
	}
	return {'x':offsetLeft, 'y':offsetTop};
}

function getPos(obj, useOwnPadding) {
	var offsetLeft=0;
	var offsetTop=0;
	var el=obj;
	if (el)
	{
		var w=getPadding(el, "l");
		var h=getPadding(el, "t");
		offsetLeft+=el.offsetLeft;
		offsetTop+=el.offsetTop;
		if (useOwnPadding) {
			offsetLeft+=w;
			offsetTop+=h;
		}
		el=el.offsetParent;
		while (el) {
			w=getPadding(el, "l");
			h=getPadding(el, "t");
			if (detectBrowser()=="IE")
			{
				if (getStyle(el, "position")!="absolute")
				{
					offsetLeft+=w;
					offsetTop+=h;
				}
			} else {
				if (getStyle(el, "position")=="absolute")
				{
					offsetLeft+=w;
					offsetTop+=h;
				}
			}
			offsetLeft+=el.offsetLeft;
			offsetTop+=el.offsetTop;
			el=el.offsetParent;
		}
	}
	el=obj;

	var offset;
	while (el.tagName!="BODY") {
		var offsetL=el.scrollLeft;
		if (offsetL) offsetLeft-=el.scrollLeft;
		var offsetT=el.scrollTop;
		if (offsetT) offsetTop-=el.scrollTop;
		el=el.parentNode;
	}
	return {'x':offsetLeft, 'y':offsetTop};
}

function getPadding(o, type) {
	var p={
		"l": Array("border-left-width"),
		"r": Array("border-right-width"),
		"t": Array("border-top-width"),
		"b": Array("border-bottom-width")
	};
	var res=getStyle(o, p[type][0]);
	var units=res.substr(res.length-2, 2);
	var val=parseFloat(res);
	if (isNaN(val)) val=0;
	if ( units=="em" ) {
		return Math.floor(val*16+0.5);
	} else if (units=="ex") {
		return Math.floor(val*7+0.5);
	} else if (units=="pt") {
		return Math.floor(val*4/3+0.5);
	} else if (units=="pc") {
		return Math.floor(val*16+0.5);
	} else if (units=="cm") {
		return Math.floor(val*37795/1000+0.5);
	} else if (units=="mm") {
		return Math.floor(val*37795/10000+0.5);
	} else if (units=="in") {
		return Math.floor(val*96+0.5);
	}
	return Math.floor(val);
}

function getStyle(o, name) {
	var ret="";
	if (name>"") {
		if (detectBrowser()=="IE")
		{
			var words=name.split("-");
			var out=words[0];
			for (var i=1; i<words.length; i++)
			{
				out+=words[i].substr(0, 1).toUpperCase()+words[i].substr(1, words[i].length);
			}
			ret=o.currentStyle[out];
		} else {
			ret=document.defaultView.getComputedStyle(o, '').getPropertyValue(name);
		}
	}
	return ret;
}

function detectBrowser() {
	if (navigator.userAgent.toLowerCase().indexOf('opera')>=0) {
		return "OP";
	} else if ( navigator.userAgent.indexOf('MSIE')>=0 ) {
		return "IE";
	} else if (navigator.userAgent.indexOf('Firefox')) {
		return "FF";
	} else if (navigator.userAgent.indexOf('safari')>=0){
		return "SA";
	}else {
		return "IE";
	}
}

function getLeftTop(el){
	if((el===null||el.parentNode===null||el.offsetParent===null||getStyle(el,'display')=='none')&&el!=document.body){
		return {'x':0, 'y':0};
	}
	var top=0,left=0;
    var o;

    if (el.getBoundingClientRect){
		var box=el.getBoundingClientRect();
		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		return {'x':box.left+scrollLeft, 'y':box.top+scrollTop};
    }
	else {
	    var browser=detectBrowser();
		top=el.offsetTop, left=el.offsetLeft;
		var o=el.offsetParent;
		var abs=getStyle(el,'position')=='absolute';
		while(o) {
			top+=o.offsetTop;
			left+=o.offsetLeft;
			if (browser=='SA'&&!abs&&getStyle(o,'position')=='absolute') abs=true;
			o=o.offsetParent;
		}
		if (browser=='SA'&&abs)	top-=document.body.offsetTop, left-=document.body.offsetLeft;
	}
	o=el.parentNode;
	while(o.tagName){
		if (getStyle(o,'display')!='inline'){
			top-=o.scrollTop;
			left-=o.scrollLeft;
		}
		o=o.parentNode;
	}
	return {'x':left, 'y':top};
}

function setLeftTop(el,left,top,corr){
	var oldPos=getLeftTop(el);
	var delta={'x':parseInt(getStyle(el,'left')),'y':parseInt(getStyle(el,'top'))};
	if (isNaN(delta.x))	delta.x=el.offsetLeft;
	if (isNaN(delta.y))	delta.y=el.offsetTop;
	el.style.left=left-oldPos.x+delta.x+'px';
	el.style.top=top-oldPos.y+delta.y+'px';
	if (!corr) {
		var newPos=getLeftTop(el);
		if (newPos.x!=left||newPos.y!=top) setLeftTop(el,left,top,true);
	}        
	
}

function centerObject(o){
	var clientHeight, clientWidth;
	o.style.position='absolute';	
	if (detectBrowser()=="IE") {
		clientHeight=document.body.clientHeight;
		clientWidth=document.body.clientWidth;
	} else {
		clientHeight=window.innerHeight;
		clientWidth=window.innerWidth;
	}
	var y=Math.floor((clientHeight-o.offsetHeight)/2);
	var x=Math.floor((clientWidth-o.offsetWidth)/2);
	o.style.top=y+"px";
	o.style.left=x+"px";
}

function centerObjectInScreen1(o){
	var clientHeight, clientWidth;
	alert(document.documentElement.scrollTop+'='+document.body.scrollTop+'='+document.body.clientHeight);
	o.style.position='absolute';	
	if (detectBrowser()=="IE") {
		clientHeight=document.body.clientHeight;
		clientWidth=document.body.clientWidth;
	} else {
		clientHeight=window.innerHeight;
		clientWidth=window.innerWidth;
	}
	var y=Math.floor((clientHeight-o.offsetHeight)/2);
	var x=Math.floor((clientWidth-o.offsetWidth)/2);
	o.style.top=y+"px";
	o.style.left=x+"px";
}

function centerObjectInScreen(o){
	var clientHeight, clientWidth;
	o.style.position='absolute';
	var obj;
	if ( (document.body.scrollTop < document.documentElement.scrollTop) || (document.body.scrollLeft < document.documentElement.scrollLeft)) {
		obj=document.documentElement;
	} else {
		obj=document.body;
	}
	clientHeight=Math.floor((obj.clientHeight-o.offsetHeight)/2);
	clientWidth=Math.floor((obj.clientWidth-o.offsetWidth)/2);
	if (clientHeight<0) clientHeight=0;
	if (clientWidth<0) clientWidth=0;
	var y=clientHeight+obj.scrollTop;
	var x=clientWidth+obj.scrollLeft;
	o.style.top=y+"px";
	o.style.left=x+"px";
}

function getWindowSize() {
	var w=0;
	var h=0;
	if( document.documentElement && ( document.documentElement.scrollWidth || document.documentElement.scrollHeight )) {
		if ((document.body.scrollHeight>document.documentElement.scrollHeight) || (document.body.scrollWidth>document.documentElement.scrollWidth)) {
			return {w:document.body.scrollWidth, h:document.body.scrollHeight};
		}
		return {w:document.documentElement.scrollWidth, h:document.documentElement.scrollHeight};
	} else if( typeof( window.innerWidth ) == 'number' ) {
		return {w:window.innerWidth, h:window.innerHeight};
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		return {w:document.body.clientWidth, h:document.body.clientHeight};
	}
	return {w:0, h:0};
}

function getInt(val){
	var num=0;
	var dec='';
	var reg=/\d/;
	var float_=false;
	for (var i=0; i<val.length; i++) {
		if (!float_&&val.charAt(i)=='.') {float_=true;}
		if (reg.test(val.charAt(i))) {
			if (!float_) {num=num*10+parseInt(val.charAt(i));}
			else {dec+=val.charAt(i);}
		}
	}
	if (float_&&dec>'') {
		num=Math.round(num+parseFloat('0.'+dec));
	}
	return num;
}

function copyToClipboard(text) {
	if( window.clipboardData && clipboardData.setData ) {
		clipboardData.setData("Text", text);
	} else {

		var c, t, o, i;
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
		try {
			c=Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard)
		} catch(e){return false}
		try {
			t=Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable)
		} catch(e){return false}
		
		t.addDataFlavor("text/unicode");
		o=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		o.data=text;
		t.setTransferData("text/unicode",o,text.length*2);
		try {
			i=Components.interfaces.nsIClipboard
		} catch(e){return false}
		c.setData(t,null,i.kGlobalClipboard);
	
	}
}

function setChecked(obj, val) {
	for (var i=0; i<obj.length; i++)
		if (obj[i].value==val) obj[i].checked=true;
		else obj[i].checked=false;
}

function Show(obj) {
	getObj(obj).style.display='';
}

function Close(obj) {
	getObj(obj).style.display='none';
}

function redirect(url) {
	var i=url.indexOf('&tmpId');
	if (i>0) {
		url=url.substr(0,i);
	} else {
		i=url.indexOf('#');
		if (i>0) {
			url=url.substr(0,i);
		}
	}
	window.location.href=url+"&tmpId="+getTmpTime();
}

function cloneObject(obj) {
	var out={};
	if (typeof(obj)=='object') {
		for (var t in obj) {
			out[t]=obj[t];
		}
	}
	return out;
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function startSearchByEnter(e, btn_id) {
    if (e && e.keyCode && e.keyCode == 13) {
        var btn = getObj(btn_id);
        if (btn && btn.click) btn.click();
    }
}
