var chkBoxesChanged = false;
	function doSearch()
	{
		if (int__web_code_flag==0)
			document.getElementById('webcode').value='';
		
		var chkBoxesSt = "";
		if (document.ChildListForm.chkChild)
		{
			for (i = 0; i < document.ChildListForm.chkChild.length; i++)
			{
				if (document.ChildListForm.chkChild[i].checked)
					chkBoxesSt += "&chkChild=" + document.ChildListForm.chkChild[i].value;
			}
		}
		jQuery.ajax({
				data: "sex=" + $("#sex").val() +
					 "&fromAge=" + $("#fromAge").val() +
					 "&toAge=" + $("#toAge").val() +
					 "&webcode=" + $("#webcode").val() + chkBoxesSt + "&chkBoxesChanged=" + chkBoxesChanged,
				type: "POST",
				url: "./search_result.jsp",
				dataType: "json",
				timeout: 10000,
				error: function(err) {
					alert("Ошибка запроса:" + err);
				},
				success: function(json) {
					//alert(json.data[0].webcode);
					if ( json.err != null ){
						alert( json.err );
                        SwitchSearchBarVisibility();
					}
					else
						buildResultView(json.data);
				}
			  });
	}
	function buildResultView(data)
	{

		var res = "<table class='css__search_result' cellspacing='0' cellpadding='0'>";

		for(var i=0;i<data.length;i++)
		{
			var line = data[i];
			var clr = i % 2 == 0 ? "#ffffff":"#ebf3fb";
			var sex_color = line.sex == "Мужской" ? "#1f8ad5" : "#de1979";
			var varchar__class_temp=(i==(data.length-1))?'css__last_row':'';
			/*var isChecked = false;
			if (document.chosenChild)
			{
				for (j = 0; j < document.chosenChild.length; j++)
				{
					if (document.chosenChild[j].value == line.childId)
					{
						isChecked = true;
						break;
					}
				}
			}*/
			res += "<tr align='center' style='background-color:" + clr + ";color:"+sex_color +"'>" +
				"<td class='tdResult "+varchar__class_temp+"' width='89px'>" + line.sex + "</td>" +
				"<td class='tdResult "+varchar__class_temp+"' width='140px'>" + line.name + "</td>" +
				"<td class='tdResult "+varchar__class_temp+"' width='120px'>" + line.year + "</td>" +
				"<td class='tdResult "+varchar__class_temp+"' width='155px'>" + line.webcode + "</td>" +
				"<td class='tdResult "+varchar__class_temp+"' width='80px'><input type='checkbox' id = 'chkChild' name='chkChild' value='" + line.childId + "'" +  (line.isChecked == "true" ? " checked='true'" : "") + " onchange='chkBoxesChanged=true'/></td>" +
				"<td class='tdResult "+varchar__class_temp+"' width='153px'><div onclick=\"gotoViewChildPage('"+ line.url + "', " + line.childId + ")\" style='width:100px;height:18px;cursor:pointer;background:url(../images/search_result/view_button.jpg) no-repeat'></div></td>" +
				"<td></td></tr>";
		}
		res +=   "</table>";

		$("#searchContent").html(res);
		$("#searchContainer").show();
		$("#textContent").hide();
	}

	function doSendMail()
	{
		if (isValidEmail(document.ChildListForm.sendEmail.value))
		{
			document.ChildListForm.submit();
		}
		else
		{
			alert("Неправильный e-mail");
		}
	}

	function doSubmit()
	{
		if (isValidEmail(document.ChildListForm.subscribeEmail.value))
		{
			document.ChildListForm.subscribeAction.value = "subscribe";
			document.ChildListForm.submit();
		}
		else
		{
			alert("Неправильный e-mail");
		}
	}

	function doUSubmit()
	{
		if (isValidEmail(document.ChildListForm.subscribeEmail.value))
		{
			document.ChildListForm.subscribeAction.value = "unsubscribe";
			document.ChildListForm.submit();
		}
		else
		{
			alert("Неправильный e-mail");
		}
	}

function gotoViewChildPage(url, childId)
{
	document.ChildListForm.action = url;
	document.ChildListForm.child_id.value = childId;
	document.ChildListForm.submit();
}
function showFriends()
{
    var url = '/videopassport/friends.html';
    open(url);
}

function showContacts(id)
{
	var url = '/videopassport/upload_files/region_files/contacts';
	if (id)
	{
		url += "_" + id;
	}
	url += '.jpg';
//	document.open(url,'Контакты','width=720,height=576');
	ShowPopupLayer('-contacts',[720,576]);
	document.getElementById('id__popup_layer-contacts').innerHTML='<img src="'+url+'" title="Кликните для закрытия" onclick="HidePopupLayer(\'-contacts\')" />';
}

	function SetRegion(var__region_id)
	{
		document.getElementById('id__region_id').value=var__region_id;
		document.getElementById('id__region_list_form').submit();
	}


	function __IdentifyBrowser()
	{
		var string__user_agent=new String();
		var varchar__user_agent_pntr='';
		string__user_agent=window.navigator.userAgent;
		if (string__user_agent.indexOf("MSIE 6.0")>0) // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; Data Center; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)
			varchar__user_agent_pntr='ie6';
		else if (string__user_agent.indexOf("MSIE 7.0")>0) // Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
			varchar__user_agent_pntr='ie7';
		else if (string__user_agent.indexOf("MSIE 8.0")>0) // Mozilla4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident4.0; .NET CLR 1.1.4322)
			varchar__user_agent_pntr='ie8';
		else if (string__user_agent.indexOf("Firefox")>0) // Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8
			varchar__user_agent_pntr='ff';
		else if (string__user_agent.indexOf("Opera")>=0) // Opera/9.63 (Windows NT 5.2; U; en) Presto/2.1.1
			varchar__user_agent_pntr='opera';
		else if (string__user_agent.indexOf("Safari")>=0 && string__user_agent.indexOf("Chrome")==-1) // Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1
			varchar__user_agent_pntr='safari';
		else if (string__user_agent.indexOf("Chrome")>=0 && string__user_agent.indexOf("Safari")>=0) // Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.46 Safari/525.19
			varchar__user_agent_pntr='chrome';
		return varchar__user_agent_pntr;
	}

	function getFlashMovieObject(movieName,object_dom__window)
	{
		if (!object_dom__window)
			object_dom__window=window;
		if (object_dom__window.document[movieName])
		{
			return object_dom__window.document[movieName];
		}
		if (object_dom__window.navigator.appName.indexOf("Microsoft Internet")==-1)
		{
			if (object_dom__window.document.embeds && object_dom__window.document.embeds[movieName])
				return object_dom__window.document.embeds[movieName];
		}
		else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		{
			return object_dom__window.document.getElementById(movieName);
		}

	}

	function StopFlashMovie(flash_pointer,object_dom__window)
	{
		var flashMovie=getFlashMovieObject(flash_pointer,object_dom__window);
		flashMovie.StopPlay();
	}

	function PlayFlashMovie(flash_pointer,object_dom__window)
	{
		var flashMovie=getFlashMovieObject(flash_pointer,object_dom__window);
		flashMovie.Play();
		//embed.nativeProperty.anotherNativeMethod();
	}

	function GotoFrame(flash_pointer,int__frame_index,object_dom__window)
	{
		var flashMovie=getFlashMovieObject(flash_pointer,object_dom__window);
		flashMovie.GotoFrame(int__frame_index);
		//embed.nativeProperty.anotherNativeMethod();
	}
	var int__sound_state_flag=0;
	function SwitchSound(string__element_id,string__img_path_prefix)
	{
		if (typeof(object_dom__element=document.getElementById(string__element_id))=='object')
		{
			if (int__sound_state_flag==0)
			{
				object_dom__element.style.backgroundImage='url('+string__img_path_prefix+'images/play_sound_icon.jpg)';
				GotoFrame('sound_object',1);
				int__sound_state_flag=1;
//				setSoundState(0);
			}
			else
			{
				object_dom__element.style.backgroundImage='url('+string__img_path_prefix+'images/stop_sound_icon.jpg)';
				GotoFrame('sound_object',0);
				int__sound_state_flag=0;
//				setSoundState(1);
			}
		}
	}
	function StopSound(string__element_id,string__img_path_prefix)
	{
		if (typeof(object_dom__element=document.getElementById(string__element_id))=='object')
		{
			object_dom__element.style.backgroundImage='url('+string__img_path_prefix+'images/play_sound_icon.jpg)';
			int__sound_state_flag=1;
			GotoFrame('sound_object',1);

//			setSoundState(0);
		}
	}
	function GetIFrameByName(varchar__element_name)
	{
		for (var int__index=0;int__index<window.frames.length;int__index++)
			if (window.frames[int__index].name==varchar__element_name)
				return window.frames[int__index];
		return false;
	}
	function InitializeIFrame(object_dom__window,string_html__document_content)
	{
		object_dom__window.document.open();
		object_dom__window.document.write(string_html__document_content);
		object_dom__window.document.close();
	}
	function InitFlashObject(string__element_name,string_html__document_content)
	{
		InitializeIFrame(GetIFrameByName(string__element_name),string_html__document_content);
	}
	function ResetFlashObject(string__element_name,string_html__document_content)
	{
		InitializeIFrame(GetIFrameByName(string__element_name),string_html__document_content);
	}

	function InitPageSound()
	{
//		if (getSoundState())
			document.getElementById('id_div__sound_source').innerHTML=
				'<object id="sound_object" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="1" height="1" align="middle">'
					+'<param name="allowScriptAccess" value="sameDomain"/>'
					+'<param name="allowFullScreen" value="false"/>'
					+'<param name="movie" value="/videopassport/audio/sound_control_bar.swf"/>'
					+'<param name="quality" value="high"/>'
					+'<param name="bgcolor" value="#8db61c"/>'
					+'<param name="wmode" value="transparent" />'
					+'<embed name="sound_object" src="/videopassport/audio/sound_control_bar.swf" quality="high" bgcolor="#8db61c" width="1" height="1" wmode="transparent" align="middle" swliveconnect="true" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"/>'
				+'</object>';
	}



	function LoadFLV(string__video_file_path)
	{
		document.getElementById('id_div__flash_player').innerHTML='<div id="id_div__flv_place_holder"></div>';
//		alert(document.getElementsByName('name__child_category_video')[0].);
//		document.getElementsByName('FlashVars')[0].value="way="+string__video_file_path+".flv&amp;swf=/videopassport/upload_files/uflvplayer_500x375.swf&amp;w=400&amp;h=300&amp;pic="+string__video_file_path+"1.jpeg&amp;autoplay=0&amp;tools=2&amp;skin=white&amp;volume=70&amp;q=&amp;comment=";
//		getFlashMovieObject
		var flashvars=
		{
			way:string__video_file_path+".flv",
			swf:"/videopassport/upload_files/uflvplayer_500x375.swf",
			w:"400",
			h:"300",
			skin:"white",
			pic:string__video_file_path+'1.jpeg',
			autoplay:"0",
			tools:"2",
			q:"",
			volume:"70",
			comment:""
		};
		var params=
		{
			bgcolor:"#ffffff",
			allowFullScreen:"false"
		};
		var attributes=
		{
			id:"uplayer_flv",name:"uplayer_flv"
		};

		swfobject.embedSWF("/videopassport/upload_files/uflvplayer_500x375.swf", "id_div__flv_place_holder", "400", "300", "9.0.0", "/videopassport/js/expressInstall.swf", flashvars, params, attributes);
	}











	
	
	
	
	
