//Javascript document general.js

function refreshbox(ourform, box) {
	doform = document.getElementById(ourform); if ( !doform ) alert( "error" );
	jsAjaxUtil.InsertFormDataToNode(doform, box, true);
	doform.submit();
}

//Javascript Document

var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

function fix_png ( img_obj ) {
		if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
				var imgID = ( img_obj.id ) ? "id='" + img_obj.id + "' " : "";
				var imgClass = ( img_obj.className ) ? "class='" + img_obj.className + "' " : "";
				var imgTitle = ( img_obj.title ) ? "title='" + img_obj.title + "' " : "title='" + img_obj.alt + "' ";
				var imgStyle = "display:inline-block;" + img_obj.style.cssText;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + 
									"width:" + img_obj.width + 
									"px; height:" + img_obj.height + "px;" + 
									imgStyle + ";" + 
									"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + 
									"(src=\'" + img_obj.src + "\', sizingMethod='scale');\"></span>";
				img_obj.outerHTML = strNewHTML;
		}
}

//window.addOnLoadListener( recollectPNG );
window.onload= recollectPNG;
//jsEvent.addEvent(window, 'load', recollectPNG);
//alert( "" );

function recollectPNG () {
	//alert( "start"+version );
	//var statistic_container_obj= document.getElementById( "statistic_container" ); if ( !statistic_container_obj ) return;
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		var stat_temp= "here";
		var collectedPng= new Array();
		var candidates= document.getElementsByTagName( "img" );
		
		//alert( candidates.length );
		
		for ( var c in candidates ) {
			if ( typeof( candidates[ c ].src ) == "undefined" || !candidates[ c ].src ) continue;
			//stat_temp+= "Looking src: "+candidates[ c ].src+"<br />";
			if ( candidates[c].src.indexOf( ".png" ) < 0 ) continue;
			//stat_temp+= "founded<br /><br /> ";
			collectedPng[ collectedPng.length ]= candidates[ c ];
			//fix_png( candidates[ c ] );
		} //end for
		//statistic_container_obj.innerHTML= stat_temp;
		if ( collectedPng.length > 0 ) {
			for ( var cP= 0; cP < collectedPng.length; cP++ ) {
				fix_png( collectedPng[ cP ] );
			} //end for
		}
	} //end if
}

//Javascript Document cabinetts.js

function send_pic_to_disable ( img_id ) {
	var pic_obj= document.getElementById( "picture_"+img_id ); if ( !pic_obj ) return;
	var pic_control= document.getElementById( "piccontrol_"+img_id ); if ( !pic_control ) return;
	var pic_deny= document.getElementById( "pcimage_"+img_id+"_deny" ); if ( !pic_deny ) return;
	var pic_allow= document.getElementById( "pcimage_"+img_id+"_allow" ); if ( !pic_allow ) return;
	var pic_del= document.getElementById( "pcimage_"+img_id+"_del" ); if ( !pic_del ) return;
	var pic_one= document.getElementById( "pcimage_"+img_id+"_one" ); 
	
	pic_control.value= ( pic_control.value == "X" ) ? (( pic_one ) ? "" : "1") : "X";
	pic_obj.className= ( pic_control.value == "X" ) ? "picture_not_active" : "";
	
	if ( pic_control.value == "X" ) {
		pic_deny.style.display= "none";
		if ( pic_one ) pic_one.style.display= "none";
		pic_allow.style.display= "inline";
		pic_del.style.display= "inline";
		
	} else {
		pic_deny.style.display= "inline";
		if ( pic_one ) pic_one.style.display= "inline";
		pic_allow.style.display= "none";
		pic_del.style.display= "none";
	}
}

function send_pic_to_delete ( img_id ) {
	var del_obj= document.getElementById( "adv_picture_to_del" ); if ( !del_obj ) return;
	var save_obj= document.getElementById( "alternative_save" ); if ( !save_obj ) return;
	
	if ( confirm( "Вы действительно хотите удалить фотографию из карточки объекта?" ) ) {
		del_obj.value= img_id;
		save_obj.value= "1";
		refresh_detail_object();
	}
}

function send_pic_to_one ( img_id, deny_one ) {
	var pic_control= document.getElementById( "piccontrol_"+img_id ); if ( !pic_control ) return;
	var stop_one= document.getElementById( "piccontrol_"+deny_one ); if ( !stop_one ) return;
	var save_obj= document.getElementById( "alternative_save" ); if ( !save_obj ) return;
	
	stop_one.value= "";
	save_obj.value= "1";
	pic_control.value= "1";
	refresh_detail_object();
}

function send_v_photo_to_del () {
	var del_obj= document.getElementById( "PERSONAL_PHOTO_TO_DEL" ); if ( !del_obj ) return;
	var save_obj= document.getElementById( "visitka_alternative_save" ); if ( !save_obj ) return;
	
	if ( confirm ( "Вы действительно хотите удалить фото?" ) ) {
		del_obj.value= "1";
		save_obj.value= "1";
		refresh_visitka();
	}
	
}

function refresh_visitka() {
	var no_ajax= document.getElementById( "visitka_form_ajaxid" ); if ( !no_ajax ) return;
	refreshbox('visitka_form', no_ajax.value);
}

function ya_map_enable( value ) {
	var map_obj= document.getElementById( "r_map_active" ); if ( !map_obj ) return; 
	var save_obj= document.getElementById( "alternative_save" ); if ( !save_obj ) return;
	save_obj.value= "1";
	map_obj.value= value; 
	
	refresh_detail_object();
}

function ya_map_open_for_edit() {
	var me_control= document.getElementById( "me_controller" ); if ( !me_control ) return; 
	me_control.value= '1';
	
	refresh_map_editor();
}

function createCookie( name, value, days ) {
	if ( days ) {
		var date= new Date();
		date.setTime( date.getTime()+( days*24*60*60*1000 ) );
		var expires= "; expires="+ date.toGMTString();
	}
	else var expires = "";
	document.cookie= name+ "="+ value+ expires+ "; path=/; domain=volne.ru";
}