var q_response;
function valid_filename(str) {


   if (/^[^\\\/\:\*\?\"\<\>\|\.]+(\.[^\\\/\:\*\?\"\<\>\|\.]+)+$/.test(str)) {
      //alert("valid file name");
	  return true;
   }
   else {
      //alert("this file name is invalid");
	  return false;
   }
}

extArray = new Array(".avi", ".mov", ".mpg", ".AVI", ".MOV", ".wmv", ".jpg");
function LimitAttach(form, file) {

allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
//alert(ext);
var to_return;
for (var i = 0; i < extArray.length; i++) 
{
	//alert(extArray[i]);
	if (extArray[i] == ext) 
	{ 
		//alert("ok!");
		to_return=true;
	 }
	
}
//alert(to_return);
return to_return;
}

function doUpload(file)
{

	//alert("Uploading...");
	/*
	document.getElementById("uploadForm").submit();
	document.getElementById("placeholder").innerHTML='<img src="templates/images/loading.gif">';
	*/
	/*
	if(valid_filename(document.getElementById('upload_file').value))
	{
	//submit
	alert("ok!");
	}
	else
	{
	alert("Wrong filename!");
	}
	*/
	//$('upload_file').value=file;
	
	//var frmWin=window.frames["ifrm"];
	//alert(frmWin.document.forms['uploadForm'].elements[ "upload_file" ].value);
	//frmWin.document.forms['uploadForm'].elements[ "upload_file" ].value=file;
	
	
if(	LimitAttach(this.form,file))
{
	//document.getElementById("uploadForm").submit();
	var frmWin=window.frames["ifrm"];
	
	//frmWin.document.forms['uploadForm'].elements["placeholder"].innerHTML='<img src="templates/images/loading.gif">';
	//showProgress();
	frmWin.document.forms['uploadForm'].submit();
	frmWin.document.getElementById("placeholder").innerHTML='<p><img src="templates/images/loading_circle.gif"></p><p style="font-size:10px;">Your movie is uploading now. Please wait until the progress indicator has completed it\'s cycles.</p>';
	
}

else
	{
		showError("Wrong filename!");
	}

}

function showError(errortext)
{
	
	//myLightWindow.activateWindow({href: 'error.php?code='+code, title: 'Error!',  left:700, width:250, height:80});
	/*
	var ie=document.all && !window.opera;
	var tttt=(ie)? this.standardbody.scrollTop : window.pageYOffset;
	*/
	self.scrollTo(0,0);
	var tttt=0;
	tttt=tttt+100;

    new Popup('popup_8','popup_link_8',{modal:true,position: "40%,"+tttt})
	$('error_text').innerHTML=errortext;
	//window.moveTo(0,0);
	
	$('popup_8').popup.show();
	$('popup_8').popup.getviewpoint;
//	$('popup_8').moveTo(this, 300, 300);
	
}
function showOk(errortext)
{
	//alert(errortext);
	//myLightWindow.activateWindow({href: 'error.php?code='+code, title: 'Error!',  left:700, width:250, height:80});
	/*
	var ie=document.all && !window.opera;
	var tttt=(ie)? this.standardbody.scrollTop : window.pageYOffset;
	*/
	
	self.scrollTo(0,0);
	var tttt=0;
	tttt=tttt+100;

    new Popup('popup_ok','popup_link_8',{modal:true,position: "40%,"+tttt})
	$('ok_text').innerHTML=errortext;
	//window.moveTo(0,0);
	if($('popup_progress').popup)
	{
		$('popup_progress').popup.hide();
	}
	$('popup_ok').popup.show();
	$('popup_ok').popup.getviewpoint;
//	$('popup_8').moveTo(this, 300, 300);
	
}

function showNotify(errortext)
{
	self.scrollTo(0,0);
	var tttt=0;
	tttt=tttt+100;

    new Popup('popup_notify','popup_link_8',{modal:true,position: "40%,"+tttt})
	$('notify_text').innerHTML=errortext;
	//window.moveTo(0,0);
	if($('popup_progress').popup)
	{
		$('popup_progress').popup.hide();
	}
	$('popup_notify').popup.show();
	$('popup_notify').popup.getviewpoint;
//	$('popup_8').moveTo(this, 300, 300);
	
}

function reportError()
{
alert ("Error in ajax request");
}
function handlerFunc()
{

	//toggle("save_place");
	//toggle("img_place");
	
  $('popup_progress').popup.hide();
}

function ajaxUpdate(pars, placeholder, url, toggleit)
{
/*
	if(toggleit==true)
	{
		toggle('img_place');
		
		toggle("save_place");
	}
*/
if(toggleit==true)
	{

	handlerFunc=showOk('Done');
	}
	var myAjax = new Ajax.Updater(
	
	{success: placeholder},
	url,
	{method: 'post', parameters: pars, evalScripts:true, onFailure: reportError, onSuccess:handlerFunc	
		});
}

function placeCircle(place)
{
	$(place).innerHTML='<img src="templates/images/loading_circle.gif">';
}

function toggle(obj) {

        var el = document.getElementById(obj);
//        alert(el.style.display);
        if ( el.style.display != 'none' ) {
                el.style.display = 'none';
        }
        else {

                el.style.display = 'inline';
        }
}
function addTag(tag)
{
if(tag!="") {
var all_tags=$("all_tags");
var i=0;
var add=true;
	for (i=0; i<all_tags.length; i++ )
	{
		if (all_tags.options[i].text==tag)
		{
		showError("This tag already exists");
		add=false;
		}
	}
	if(add==true)
	{
		all_tags.options[all_tags.length]=new Option(tag,tag);
	}

}

}


function getMultiple(ob) 
{
var arSelected = new Array(); 
var i=0;
for(i=0; i<ob.options.length; i++)
// while (ob.selectedIndex != -1) 
 	{ 
 	//alert(ob.selectedIndex);
 	if (ob.options[i].selected == true) 
 	{
 		arSelected.push(ob.options[i].text);
 	}
  	//ob.options[ob.selectedIndex].selected = false; 
  }
	return arSelected;
  } 
  // You can use the arSelected array for further processing. }
  
  
  function isLoged(ajax_key)
  {
  
 var qqq= new Ajax.Request('return.php', {
      method: 'post',
	  asynchronous:false,
      parameters: {ajax_key:ajax_key, action:'isLoged'},
      onSuccess:  
	  function(transport) {
		s_response=transport.responseText;
          	

    
	 }
    });
	return(s_response);
  }
  function isOwner(vid, ajax_key)
  {
   var qqq= new Ajax.Request('return.php', {
      method: 'post',
	  asynchronous:false,
      parameters: {ajax_key:ajax_key,  vid:vid, action:'isOwner'},
      onSuccess:  
	  function(transport) {
		s_response=transport.responseText;
          	alert(s_response);

    
	 }
    });
	return(s_response);
  }
  
  function showProgress()
{
	var ie=document.all && !window.opera;
	//alert(window.pageYOffset);
	//var tttt=(ie)? this.standardbody.scrollTop : window.pageYOffset;
	//var tttt=window.pageYOffset;
	//tttt=tttt+100;
	self.scrollTo(0,0);
	var tttt=100;

    new Popup('popup_progress','popup_link_8',{modal:true,position: "40%,"+tttt})
	$('popup_progress').popup.show();
	$('popup_progress').popup.getviewpoint;

	
}
function prototypeInit()
{


	init_rating();
    $$('.rating').each(function(n){
                        n.immediateDescendants().each(function(c){
                            Event.observe(c, 'click', submitRating);
                        });
                    });
}
function prototypeInit_sm()
{


	init_rating();

}
function showInline(elName){
var theElemenet=document.getElementById(elName);
if(theElemenet){
theElemenet.style.display="inline";
}
}
function hideInline(elName){
var theElemenet=document.getElementById(elName);
if(theElemenet){
theElemenet.style.display="none";
}
}