function GetObj(objId){
	if (navigator.appName.substring(0,2) !="Mi")
		return document.getElementById(objId);
	else
		return document.all[objId];
}
			
function ShowPhoto(url, width, height){
	var scroll = (screen.width < 1000) ? "yes" : "no";
	if(screen.height < 600 || height > 600){
		scroll = "yes";
	}
	var left = (self.screen.width >> 1) - (width >> 1);
	var top = (self.screen.height >> 1) - (height >> 1);
	var param = 'left='+left+',top='+top+',width='+width+',height='+height+',';
	window.open(url, '_blank', param+'menubar=no,scrollbars=' + scroll + ',status=no');
}

function ShowListenWindowL(link,url, id_lnk, type){
	link.style.color = '#a47604';

	width = 650;
	height = 500;
	var left = (self.screen.width >> 1) - (width >> 1);
	var top = (self.screen.height >> 1) - (height >> 1);	
	var param = 'left='+left+',top='+top+',width='+width+',height='+height+',';
	new_w = window.open(url, type, param+'menubar=no,scrollbars=yes,status=no');
	new_w.window.focus();	
}

function ShowListenWindow(url, id_lnk, type){
	width = 650;
	height = 500;
	var left = (self.screen.width >> 1) - (width >> 1);
	var top = (self.screen.height >> 1) - (height >> 1);	
	var param = 'left='+left+',top='+top+',width='+width+',height='+height+',';
	new_w = window.open(url, type, param+'menubar=no,scrollbars=yes,status=no');
	new_w.window.focus();
	
	SetVisitedImg(id_lnk, type);
}

function SetVisitedImg(id_lnk, type){
	obj = GetObj('lnkl_'+id_lnk);

	if(obj){
		weeks=12;
		var today = new Date();
		expires = new Date(today.getTime() + weeks*7*24*60*60*1000);
		
		obj.src = '/templates/12format/images/listened.gif';
		document.cookie = type + "["+id_lnk+"]=" + id_lnk+"; expires="+ expires.toGMTString() +";";
	}
}

function ShowDjWindow(url){
	width = 500;
	height = 500;
	var left = (self.screen.width >> 1) - (width >> 1);
	var top = (self.screen.height >> 1) - (height >> 1);	
	var param = 'left='+left+',top='+top+',width='+width+',height='+height+',';
	window.open(url, '_blank', param+'menubar=no,scrollbars=yes,status=no');
}

function ShowBasketWindow(url){
	width = 670;
	height = 500;
	var left = (self.screen.width >> 1) - (width >> 1);
	var top = (self.screen.height >> 1) - (height >> 1);	
	var param = 'left='+left+',top='+top+',width='+width+',height='+height+',';
	window.open(url, '_blank', param+'menubar=no,scrollbars=yes,status=no');
}

function SetOperation(value){
	obj = GetObj('operation');
	obj.value = value;
}

function GetFlash(path, width, height, link, parametr){
	if(link){
		if(parametr != ''){parametr += '&';}
		parametr += 'link='+link;
	}	
	document.open();
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="6,0,0,0" WIDTH="'+width+'" HEIGHT="'+height+'">');
	document.write('<PARAM NAME="wmode" VALUE="transparent">');	
	document.write('<PARAM NAME="movie" VALUE="' + path + '">');
	document.write('<PARAM NAME="quality" VALUE="high">');
	document.write('<PARAM NAME="FlashVars" VALUE="' + parametr + '">');
	document.write('<EMBED src="' + path + '" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" WIDTH="' + width + '" HEIGHT="' + height + '" FlashVars="' + parametr + '" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>');
	document.write('</OBJECT>');
	document.close();
}

function StartDownload(form){
	sel = form.elements.item(0);
	window.location = '/data/record_comp_price/' + sel.value;
	return false;
}

var all_checked = null;

function SelectAll(check_box){
	form = GetObj('group_del');	

	if(all_checked != null){
		//if not chenged - return
		if(check_box.checked == all_checked) return;
	}
	
	for(i=0; i<form.elements.length; i++){
		if(form.elements.item(i).type != 'checkbox') continue;
		
		if(form.elements.item(i).name.substr(0,3) == 'rm_'){
			form.elements.item(i).checked = check_box.checked;
		}
	}
	
	all_checked = check_box.checked;
}

function CheckAllChecked(check_box){
	if(!check_box.checked){
		a_obj = GetObj('checked_all');
		
		if(!a_obj) return;
		
		a_obj.checked = false;
		all_checked = false;
	}
} 

function ChgClrImage(list){
	if(list.value == 0) return;

	args = list.value.split(';');
	
	ChangeImage(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
	
	return;
}

function execute(handler) {
  switch (typeof(handler)) {
    case "string":
      execScript(handler); break;
    case "function":
      handler(); break;
  }
}

function ChangeImage(path, id_big, b_path, b_width, b_height, alias, id){
	lnk = GetObj('bigi_' + id_big);
	
	if(!lnk) return;
	
	list = lnk.childNodes;
	big_img = list[0];	

//	var img = new Image;
//    img.src=path;	

    big_img.src=path;
//    big_img.width=img.width;
//    big_img.hieght=img.height;

	lnk.onclick=function(){
		ShowPhoto('/viewphoto/type/local/calias/' + alias +'/id/' + id + '/', b_width, b_height);
		return false;			
	}
}