// JavaScript Document
function getsize(element) {  
	return {w: element.offsetWidth, h: element.offsetHeight}; 
} 
function GetPosition(element) {
    var offsetLeft = 0, offsetTop = 0;
    do {
        offsetLeft += element.offsetLeft;
        offsetTop  += element.offsetTop;
    } while (element = element.offsetParent);
	//alert("x:" + offsetLeft +"y"+ offsetTop); 
    return {x:offsetLeft, y:offsetTop};
}
function SetPosition(obj, x, y){
    with(obj.style) {
    	position = 'absolute';
    	top = y + 'px';
    	left = x + 'px';
    }
} 
function PlaceOnScreenCenter(obj){
	viewportH = document.documentElement.clientHeight;
	viewportW = document.documentElement.clientWidth;
	//alert(viewportW);
	ALheight = obj.offsetHeight;
	ALwidth = obj.offsetWidth;
	//alert(obj.id+" - "+ALwidth);
	if(ALheight<viewportH){
		var topPos = Math.abs((viewportH/2)-(ALheight/2))+document.documentElement.scrollTop;
	} else {
		var topPos = Math.abs((viewportH/2)-(ALheight/2))+document.documentElement.scrollTop-(ALheight-viewportH)/2;
	}
	var leftPos = Math.abs((viewportW/2)-(ALwidth/2))+document.documentElement.scrollLeft;
	if (navigator.userAgent.match('MSIE') ) {
		obj.style.position = 'absolute';
		obj.style.top = topPos;
		obj.style.left = leftPos;
		obj.style.visibility = 'visible';
	} 
		else 
	{
		obj.style.position = 'absolute';
		obj.style.top = topPos+"px";
		obj.style.left = leftPos+"px";
		obj.style.visibility = 'visible';
	}
	//alert(obj);
}

function SetSize(obj, x, y){
    with(obj.style) {
		if(y!=""){
    		width = y + 'px';
		}
		if(x!=""){
    		height = x + 'px';
		}
    }
}
function point(obj, PointColor, DefoultColor, Cursor){
	if (navigator.userAgent.match('MSIE') ) {
		with(obj.style) {
			if(background!=PointColor){
				background = PointColor;
				cursor = Cursor;
			} else {
				background = DefoultColor;
			}
		}
	}
}
function Collapse(obj){
    with(obj.style) {
    	width = '';
    	height ='';
    }	
}
/*
function correctPNG() {
		for (var i=0; i<document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
		var imgID = (img.id) ? "id=\"" + img.id + "\" " : "";
		var imgClass = (img.className) ? "class=\""+img.className+"\" " : "";
		var imgTitle = (img.title) ? "title=\""+img.title+"\" " : "title=\"" + img.alt + "\" ";
		var imgStyle = "display:inline-block;"+img.style.cssText;
		if (img.align == "left") imgStyle = "float:left;" + imgStyle;
		if (img.align == "right") imgStyle = "float:right;" + imgStyle;
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
		var strNewHTML = "<span "+imgID+imgClass+imgTitle+" style=\"width: "+img.width+"px; height: "+img.height+"px;"+imgStyle+";"    + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+img.src+"\', sizingMethod='scale');\"><img src=\"images\/blank.gif\" width=\"1\" height=\"1\" /></span>";
		img.outerHTML = strNewHTML;
		i = i-1;
		}
		}
}*/
		//if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1)   window.attachEvent("onload", correctPNG); 

mtTails = new Array();
function ControlMainFrame(){
	
	//document.getElementById("avantalink").style.top = 50+"px";
	setInterval(
				function (){
					
	viewportW = document.documentElement.clientWidth;
	viewportH = document.documentElement.clientHeight;
	mhPos = GetPosition(document.getElementById("mainLogo")); 
 	SetPosition(document.getElementById("SiteTitle"), mhPos.x+640, 72);

	MainFrameSize = getsize(document.getElementById("MainFrame"));
	MainFramePos = GetPosition(document.getElementById("MainFrame")); 
	BottomFrameSize = getsize(document.getElementById("BottomFrame"));
	
	

	SetSize(document.getElementById("BottomFrame"), "", viewportW);
	
	MainFSize = getsize(document.getElementById("MainF"));
	if(MainFSize.h<=viewportH){
		SetSize(document.getElementById("MainF"), viewportH, "");
	}
	
	
	SetPosition(document.getElementById("BottomFrame"), 0, MainFrameSize.h+MainFramePos.y+15);
	
	
	if(MainFrameSize.h<viewportH){
		
		if(viewportH-BottomFrameSize.h< MainFrameSize.h+MainFramePos.y+15){
			SetPosition(document.getElementById("BottomFrame"), 0, MainFrameSize.h+MainFramePos.y+15);
		} else {
			SetPosition(document.getElementById("BottomFrame"), 0, viewportH-BottomFrameSize.h) ;
		}
		

	}
	//alert("Размер документа: "+ MainFrameSize.h +"x"+ viewportH);
		//alert(documentH);
	}, 1);
	//documentH = document.body.offsetHeight;
	Createfullscreenimage();
	//alert("Размер документа: "+ document.body.offsetWidth +"x"+ document.body.offsetHeight);
}
PreloadedImages = new Array();
function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}
function PreloadImage(URL){
	var PreloadedImage = new Image();
	var name = str_replace("/", "_", URL);
	PreloadedImage.src= URL;
	PreloadedImages[name] = PreloadedImage;
}
function Pimage(URL){
	var name = str_replace("/", "_", URL);
	//alert(name);
	return PreloadedImages[name].src;
}
var GlobalDark = 0;
function DisplayDark(obj){
	 var DarkField = document.createElement('div');
	 DarkField.id = "DarkField";
	 //DarkField.style.backgroundImage = "img/avanta/50_gray.png";
    with(DarkField.style) {
		//backgroundColor = 'red' ;
		zIndex = obj.style.zIndex-1;
		backgroundImage = "url(img/avanta/50_gray.png)";
    	position = 'absolute';
    	top = 0 + 'px';
    	left = 0 + 'px';
    }
	 document.body.appendChild(DarkField);
	 SetSize(DarkField, document.body.offsetHeight, document.body.offsetWidth);
	 GlobalDark = 1;
}
function UnDark(){
	if(GlobalDark == 1){
		document.body.removeChild(document.getElementById("DarkField"));
	}
	GlobalDark = 0;
}
function Createfullscreenimage(){
	var fsi = document.createElement('div');
	fsi.id = "fullscreenimage";
	document.body.appendChild(fsi);
	//document.getElementById("fullscreenimage").innerHTML = "asdasdasdasdasdasd";
	// alert(document.getElementById(fullscreenimage.id));
}
function validate_input(num){
	//alert(num);
	var Submit = "<p><input name='submit' id='SubmitInput' disabled='disabled' type='submit' value='"+$("#ValidateInputCell").attr("name")+"' class='searchbutton' /></p>";
	var ValidateInputCell = "<p><input name='ValidateNum' id='ValidateNumField' type='text' value='' size='6' maxlength='6' class='item' /></p>";
	
	if($("#SubmitInput").attr("value")!=$("#ValidateInputCell").attr("name")){
		$("#ValidateInputCell").html(ValidateInputCell);
		$("#inputvalidator").after(Submit);
	}

	
	$("#SubmitInput").attr("disabled", "disabled");
	if($("#ValidateNumField").attr("value") == num & $("#InputOwner").attr("value")!="" & $("#InputText").attr("value")!="" & $("#InputMail").attr("value")!=""){
		$("#SubmitInput").attr("disabled", "");	
	}

}
function TextFieldDoBigger(id, multipler){
	var Ow = $("#"+id).attr("cols");
	var Oh = $("#"+id).attr("rows");
	$("#"+id).attr("cols", Ow*multipler);
	$("#"+id).attr("rows", Oh*multipler);
}

function explode( delimiter, string ) { // Split a string by string  
    //   
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
    // +   improved by: kenneth  
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
    var emptyArray = { 0: '' };  
    if ( arguments.length != 2  
        || typeof arguments[0] == 'undefined' 
        || typeof arguments[1] == 'undefined' )  
    {  
        return null;  
    }  
    if ( delimiter === '' 
        || delimiter === false 
        || delimiter === null )  
    {  
        return false;  
    }  
    if ( typeof delimiter == 'function' 
        || typeof delimiter == 'object' 
        || typeof string == 'function' 
        || typeof string == 'object' )  
    {  
        return emptyArray;  
    }  
    if ( delimiter === true ) {  
        delimiter = '1';  
    }  
    return string.toString().split ( delimiter.toString() );  
} 
function implode( glue, pieces ) {	// Join array elements with a string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: _argos

	return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
}
function clearArray(ar){
	var c = 0;
	var nar = [];
	for(i=0; i<ar.length; i++){
		if(ar[i]!=""){
			nar[c] = ar[i];
			c++;
		}
	}
	return nar;
}
//alert("Размер документа: "+ document.body.offsetWidth +"x"+ document.body.offsetHeight);
function screenSize() {
      var w, h; // Объявляем переменные, w - длина, h - высота
      w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
      h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
      return {w:w, h:h};
}
function ModifyRequestVars(Url, Var, Value){
	var found = 0;
	var it = explode("#", Url);
	if(it.length > 1){ 
		var Anchor = Value;
		
	}
	var a = explode("?", it[0]);
	var r = explode("&", a[1]);
	for(i=0; i<r.length; i++){
		r[i] = explode("=", r[i]);
		if(r[i][0]==Var){ r[i][1] = Value; found = 1;}
		r[i] = implode("=", r[i]);
	}
	if(found == 0){
		if(Var!="#"){r[r.length] = Var+"="+Value;}
	}
	r = implode("&", r);
	//if(Anchor!=null){r=r+"#"+Anchor;}
	r=r+"#"+Anchor;
	return a[0]+"?"+r;
}
