function add_embedded_video(){
	newwindow=window.open(wgScriptPath + '/index.php?title=' + wgTitle + '&opt=add_embedded_video','name','height=670,width=300,scrollbars=no, location=no, maximize=no');
}       

function add_video_link(){
	newwindow=window.open(wgScriptPath + '/index.php?title=' + wgTitle + '&opt=add_video_link','name','height=670,width=300,scrollbars=no, location=no, maximize=no');
}      

function add_photo(){
	newwindow=window.open(wgScriptPath + '/index.php?title=' + wgTitle + '&opt=add_photo','name','height=670,width=300,scrollbars=no, location=no, maximize=no');
}

function add_new_babe(){
	newwindow=window.open(wgScriptPath + '/index.php?title=' + wgTitle + '&opt=add_babe','name','height=300,width=300,scrollbars=no, location=no, maximize=no');
}

function change_thumb_source(v){
	switch(v)
	{
		case('thumburl_content'):
		   $(v).setStyle('display','block');
		   $('thumbupl_content').setStyle('display','none');   
		   $('thumbnail_upl').disabled = true;
		   $('thumbnail_url').disabled = false;
		break;
		case('thumbupl_content'):
		   $(v).setStyle('display','block');
		   $('thumburl_content').setStyle('display','none');  
		   $('thumbnail_upl').disabled = false;
		   $('thumbnail_url').disabled = true;
		break;
	}
}                                                            

function embed_video_post(){       
	if($('video_url').value == "")
	{
	   alert('Video URL is empty'); 
	}
	else if($('thumbnail_url').value == "")  
	{
	   alert('Thumbnail URL is empty'); 
	}
	else if($('video_title').value == "")  
	{
	   alert('Video title is Empty'); 
	}
	else
	{   
	   opener.name = "parentwin";
	   $('embed_video_form').target = opener.name; 
	   $('embed_video_form').submit();  
	   setTimeout('self.close()',1000);
	}
}  

function video_link_post(){       
	if($('video_link').value == "")
	{
	   alert('Video Link is empty'); 
	}
	else if($('thumbnail_url').value == "" && $('thumbnail_upl').disabled==true  )  
	{
	   alert('Thumbnail URL is empty'); 
	}
	else if($('thumbnail_upl').value == "" && $('thumbnail_upl').disabled==false )  
	{
	   alert('Thumbnail Upload is empty'); 
	}
	else if($('vl_title').value == "")  
	{
	   alert('Title is Empty'); 
	}
	else
	{  
	   opener.name = "parentwin";
	   $('video_link_form').target = opener.name; 
	   $('video_link_form').submit();  
	   setTimeout('self.close()',1000);
	}
}

function photo_post(){       
   if($('thumbnail_url').value == "" && $('thumbnail_url').disabled==false)  
	{
	   alert('Photo URL is empty'); 
	}  
	else if($('thumbnail_upl').value == "" && $('thumbnail_upl').disabled==false )  
	{
	   alert('Photo Upload is empty'); 
	}
	else
	{  
	   opener.name = "parentwin";
	   $('add_photo_form').target = opener.name;
	   $('add_photo_form').submit();  
	   setTimeout('self.close()',1000);
	}
} 

function new_babe_post(){       
	if($('firstname').value == "")
	{
	   alert('Babe First name is empty'); 
	}
	else if($('lastname').value == "")
	{
	   alert('Babe Lastname is empty'); 
	}
	else if($('brasize').value == "")  
	{
	   alert('Bra Size is empty'); 
	}
	else if($('occupation').value == "")  
	{
	   alert('Occupation is Empty'); 
	}
	else
	{  
	   opener.name = "parentwin";
	   $('add_babe_form').target = opener.name;       
	   $('add_babe_form').submit();  
	   setTimeout('self.close()',1000);
	}
}

function get_title_and_video_id(url){  
   get_title(url);
   get_video_id(url);
} 

function get_thumb_image_from_url(url){ 
	 $('thumburl').innerHTML = 'Loading Image Thumbnail...';
	 new Ajax(wgScriptPath + '/', {
        method: 'post',
        onComplete: function(res){
              $('thumburl').innerHTML = '<img src="' + this.response.text + '" width="100%" height="100%" />';  
        }
    }).request( 'action=ajax&rs=waGetThumImgFromUrl&rsargs=' + escape(url));
} 

function inputFileOnChange(id,actionurl,targetframe,realaction,realframe,callback) {  
	
	 var form = document.getElementById(id);
	 form.action = actionurl;
	 form.target = targetframe;   
	 form.onsubmit = '';
	 form.wpDestFile.value = form.wpUploadFile.value;
	 $('form1_iframe').addEvent('load',function(el){
     	form.action = realaction;
		form.target = realframe;   
		form.onsubmit = callback; 
		if(id == 'video_link_form'){
			video_link_post();          
		}else if(id == 'add_photo_form'){
			photo_post();
		}
	 });
}



function get_title(url){
    $('video_title').value = 'Loading';
	$('video_title').disabled = true;  
	$('btn_submit').disabled = true;
	new Ajax(wgScriptPath + '/', {
        method: 'post',
        onComplete: function(res){
              $('video_title').value = this.response.text;  
			  $('video_title').disabled = false; 
			  $('btn_submit').disabled = false;
        }
    }).request( 'action=ajax&rs=waGetTitle&rsargs=' + escape(url)); 
}

function get_video_id(url){ 
	$('thumbvideo').innerHTML = 'Loading Video Thumbnail....'; 
	$('thumburl').innerHTML = 'Loading Image Thumbnail....';   
	$('thumbnail_url').disabled = true;
	$('btn_submit').disabled = true;
	new Ajax(wgScriptPath + '/', {
        method: 'post',
        onComplete: function(res){
	  		  var o = Json.evaluate(this.response.text);
			  if(o.errors=='no')
			  {
			  	$('thumbvideo').innerHTML = '<embed src="' + unescape(o.url) +'" type="application/x-shockwave-flash" width="100%" height="100%" allowFullScreen="true" allowScriptAccess="always"></embed>';
    	  	    $('video_id').value = o.id;
				$('code').value = o.code; 
				$('thumbnail_url').value = unescape(o.img);
				$('thumburl').innerHTML = '<img src="' +  unescape(o.img) + '" width="100%" height="100%" />';  
			  }
			  else
			  {
				$('thumbvideo').innerHTML = 'Error While Loading Video....' 
				$('video_id').value = ''; 
				$('thumbnail_url').value = '';  
				$('thumburl').innerHTML = '';
				$('code').value = '';
			  }    
			  $('btn_submit').disabled = false;   
			$('thumbnail_url').disabled = false;
		}
    }).request( 'action=ajax&rs=waGetVideoId&rsargs=' + escape(url));
} 

