/*___ Support functions ___*/

// flash-player: createPlayer(1,'/video/1.flv',640,500,'false','bottom','/player/wallpaper.jpg');
function createPlayer(i,f,w,h,auto,ctrl,wp){
	if(!auto)auto='false';
	if(!ctrl)ctrl='bottom';
	var flashvars = {
		file:f, 
		controlbar:ctrl,
		autostart:auto,
		stretching:"fill",
		image:wp
	}
	var params={allowfullscreen:"true",allowscriptaccess:"always"}
	var attrib={id:"player"+i,name:"player"+i}
	swfobject.embedSWF("player/player.swf", "placeholder"+i, w, h, "8", false, flashvars, params, attrib);
	return false;
}

// flash-player: load the video on the fly
function loadflv(flv,player){
	if(flv){
		if(flv.indexOf('/')<0) flv='/video/'+flv;
		else if(flv.charAt(0)!='/') flv='/'+flv;
		if(!player) player='player1';
		var pl=document.getElementById(player);
		if(pl && pl.sendEvent) {pl.sendEvent("LOAD",flv);pl.sendEvent("PLAY");}
		else if(pl){
			var u,l=location.href.indexOf('?flv=');
			u=l>0 ? location.href.substring(0,l):location.href;
			location.href=u+'?flv='+flv
		}
	}
	return false;
}

// show big image
function popupBigImage(img) {
	var l=1024, t=768, w=320, h=240;
	if(self.screen) { l=screen.width; t=screen.height; }
	l=Math.floor((l-w)/2);
	t=Math.floor((t-h)/2);
	window.open('/viewimg.php?bigImg='+img,'',"left="+l+",top="+t+",width="+w+",height="+h+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");
	return false;
}

// проверить пустая ли строка
function isEmpty(x) {
	var filter=/[^\s]+/;
	return !filter.test(x);
}

// check email
function checkMail(x) {
	var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(x);
}

// проверка формы sendmail
function checkForm(f) {
	var s='Пожалуйста заполните';
	if(isEmpty(f.uname.value)||f.uname.value.length<3) alert(s+': Ваше имя');
	else if(isEmpty(f.email.value)||f.email.value.length<6) alert(s+': Ваш e-mail');
	else if(!checkMail(f.email.value)) alert(s+' правильно Ваш e-mail');
	else if((f.interest.tagName.toLowerCase()=='select'&&!f.interest.selectedIndex)||isEmpty(f.interest.value)) alert(s+': Вас интересует');
	else return true;
	return false;
}

