    document.write('<script type="text/javascript" src="/public/scripts/uencode.js"></script>');
function ax_submit_comment() { 

    c = $('add_comment');
    c.disabled=true;
    d = $('comment_text');
    d.disabled=true;

    comment_txt = Url.encode(d.value);
    xajax_ajx_comment_post(xajax.getFormValues('_comment_form'),comment_txt ,'comments') ;
    c.value = 'posting...';
    
    show_div('comment_title');
}


function enable_upload() {
    document.video_form.uploaded.disabled=false;
    document.video_form.uploaded.value="";
    $('up_en').innerHTML='';
}
function disable_upload() {
    document.video_form.uploaded.disabled=true;
    document.video_form.uploaded.value="";
    $('up_en').innerHTML='';
}
function enable_upload_ss() {
    document.video_form.thumbnail.disabled=false;
    document.video_form.thumbnail.value="";
    $('up_ss').innerHTML='<small>must be 160 x 120px (jpg) &nbsp;</small>';
}
function disable_upload_ss() {
    document.video_form.thumbnail.disabled=true;
    document.video_form.thumbnail.value="";
    $('up_ss').innerHTML='';
}
function enable_upload_ss_course() {
    document.course_form.thumbnail.disabled=false;
    document.course_form.thumbnail.value="";
    $('up_ss').innerHTML='<small>must be 160 x 120px (jpg) &nbsp;</small>';
}
function disable_upload_ss_course() {
    document.course_form.thumbnail.disabled=true;
    document.course_form.thumbnail.value="";
    $('up_ss').innerHTML='';
}
function enable_upload_attachment() {
    document.attachment_form.attachment.disabled=false;
    $('up_ss').innerHTML='<small>must be a zip, doc, pdf, etc..  &nbsp;</small>';
}


function video_reload(uri , page_number) {
    var a;
    a = uri+"/p/"+page_number;

    window.location = a;
}

function show_pass() {
    var d = $('password_div');
    document.user_form.password.disabled=false;
    document.user_form.password2.disabled=false;
    new Effect.Appear(d);
    $('password_description').innerHTML = '<label>new password: </label><br/><small>(twice)</small>';
}

function show_avatar() {
    var d = $('avatar_div');
    new Effect.Appear(d);
    var e = $('f_avatar_description');
    new Effect.Appear(e);
    $('avatar_description').innerHTML = '';
}

function show_div(id) {
    var d = $(id);
    d.style.display = "block";
//    new Effect.BlindDown(d,{duration:0.5});

}
function hide_div(id) {
    var d = $(id);
    d.style.display = "none";

//    new Effect.BlindUp(d,{duration:0.5});
    
}
function quick_toggle_div(id) {
	var d = $(id);
    if (d.style.display == 'none')
    {
       d.style.display = "block";
    } else { 
 	   d.style.display = "none";
    }
}

function toggle_div(id) {
    var d = $(id);
      if (d.style.display == 'none')
      {
        new Effect.BlindDown(d,{duration:0.5});
      } else { 
        new Effect.BlindUp(d,{duration:0.5});
      d.style.display == 'none';
      }
}

function toggle_attachment_form() {

    var d = $('attachment_form');
      if (d.style.display == 'none')
      {
        new Effect.Appear(d,{duration:0.5});
      } else { 
        new Effect.Fade(d,{duration:0.5});
      d.style.display == 'none';
      }
}


// RATING STUFF
var rating_timer = null;
	function rating_clear_timer() {
		if (rating_timer) {
			clearTimeout(rating_timer);

			rating_timer = null;
		}
    }

    function rating_mouse_over(id) { 

        var prefix  = 'star_';
        var d       = $(prefix+id);
        var msg     = $('stars_message');
    
        switch(id) {
            case '1':
                msg.innerHTML = 'Boring & uninformative';
            break;
            case '2':
                msg.innerHTML = 'Redundant';
            
            break;
            case '3':
                msg.innerHTML = 'Informative';
            
            break;
            case '4':
                msg.innerHTML = 'Outstanding!';
            
            break;
            case '5':
                msg.innerHTML = 'Incredible instructions!';
            
            break;
            
        
        }

          var total = 5;
          // pre-fetch image
          var off = '/public/images/stars/off.gif';
          var on = '/public/images/stars/full.gif';
          (new Image()).src = off;
          (new Image()).src = on;

            for (i=id;i<total + 1;i++) {
                c = $(prefix+i);
                c.src = off;
    
            }
            on_limit = parseInt(id);
            on_limit++;

            for (i=1;i < on_limit ;i++) {
                l = $(prefix+i);
                l.src = on;
    
            }
		rating_clear_timer();

    }
	function rating_clear(rating) {
		rating_timer = setTimeout("rating_reset("+rating+")", 300);
	}    
	function rating_reset(rating) {
		rating_clear_timer();
        xajax_ajx_get_rating(rating);

    }    
    
//// END RATING STUFF    


// for my_ws
function select_me(id) {
    total = 5;
    
    for (i=1;i<total + 1;i++) {
     d = $('sel_'+i);
     d.style.background='#EFEFEF';
     d.style.color='#555';
    
    }
    $(id).style.background='#DDD';
    $(id).style.color='#FFF';
}


progress = function() {

    d = $('progress');
//    d.style.background="transparent";
//    image = "/public/images/progress.gif";
//    d.style.backgroundImage ="url('"+image+"')";
    d.className = 'progress_on';
    d.innerHTML = 'uploading...';
    e = $('progress_text');
    e.innerHTML = '';
}

//when ajax loading, display this
function load(id)
{
        d = $(id);
        d.innerHTML = '<div class="indicator"><img src="/public/images/indicator.gif" /></div>';
    return false;
    
}
// load attachment details in video index:
function load_details(vid , div) {
toggle_div(div);

c = $(div);
c.innerHTML = '<img src="/public/images/indicator.gif" />';
xajax_ajx_load_attachment_details(vid , div);

}

// JAVASCRIPT VALIDATION //
function validate_attachment_form() { 

	var form = document.attachment_form;

				d = $('attachment_errors');
                d.innerHTML ='';   
                d.style.display ='none';
    errorNum = 0;
    msg = '<div style="color:#AAA; font-size: 16pt; text-align: left;"><strong>Oops... something\'s not right:</strong></div>';

    var title = form.title;
    		if ( title.value.length < 4 ) {
				errorNum++;
                msg = msg + '<ul> - Attachment title is too short (4 character minimum). </ul>'
			}

    var description = form.description;
    		if ( description.value.length < 2 ) {
				errorNum++;
                msg = msg + '<ul> - Please provide a short description of your attachment. </ul>'
			}


    var certify = form.certify;
    		if ( ! certify.checked) {
				errorNum++;
                msg = msg + '<ul> - Please accept the agreement before posting. </ul>'
			}

    var uploaded = form.attachment.value.toLowerCase();
    		if ( uploaded.search('pdf') == '-1' &&  
                 uploaded.search('doc') == '-1' &&    		
                 uploaded.search('zip') == '-1' &&    		
                 uploaded.search('jpg') == '-1' &&    		
                 uploaded.search('jpeg') == '-1' &&    		
                 uploaded.search('gif') == '-1' &&    		
                 uploaded.search('png') == '-1'
    		    ) {
				errorNum++;
                msg = msg + '<ul> - Attachments must be pdf, doc, zip, jpg, png or gif format</ul>'
			}


	if (errorNum > 0) {
                d.style.display     = 'block';
				d.style.borderWidth = '2px';
				d.style.borderStyle = 'solid';
				d.style.borderColor = 'red';
				d.style.width       = '350px';
				d.style.padding     = '5px';
				d.style.margin      = '5px';
				d.innerHTML         =  msg;
    
    window.location.hash="attachment_errors"; 
    return false;
    } else {
    
    	msg = '    <h3> Currently uploading attachment ... this could take awhile. </h3><div class="indicator"><img src="/public/images/indicator.gif" /></div><p> Please don\'t close your browser until the page reloads in order to allow the video to fully upload.</p>';
                d.style.display     = 'block';
				d.style.borderWidth = '2px';
				d.style.borderStyle = 'solid';
				d.style.borderColor = 'blue';
				d.style.width       = '350px';
				d.style.padding     = '5px';
				d.style.margin      = '5px';
				d.innerHTML         =  msg;        
    }



}
function validate_video_form() {

Event.observe(window, 'load', getBrowserInfo, false);
Event.observe(window, 'load', initialize, false);
Event.observe(window, 'unload', Event.unloadCache, false);
				d = $('errors');
                d.innerHTML ='';   
                d.style.display ='none';
    errorNum = 0;
    msg = '<div style="color:#AAA; font-size: 16pt;"><strong>Oops... something\'s not right:</strong></div><br/>';

    var title = document.video_form.title;
    		if ( title.value.length < 4 ) {
				errorNum++;
                msg = msg + '<ul> - Video title is too short (4 character minimum). </ul>'
			}

    var description = document.video_form.description;
    		if ( description.value.length < 2 ) {
				errorNum++;
                msg = msg + '<ul> - Please provide a short description of your video. </ul>'
			}

    var tags = document.video_form.tags;
    var tags_test = tags.value;
    tags_test_a = tags_test.replaceAll(",","");
    tags_test_b = tags_test_a.replaceAll(" ","");

    		if ( tags_test_b.length < 3 ) {
				errorNum++;
                msg = msg + '<ul> - Please include at least one tag of at least 3 characters. </ul>'
			}

    var certify = document.video_form.certify;

    //check certification only if form action is add OR form action is edit and video is being updated.
    if ((document.video_form.action.search("add") !== -1) || ((document.video_form.action.search("edit") !== -1) &&(document.video_form.uploaded.value !== ""))){

    		if ( ! certify.checked) {
				errorNum++;
                msg = msg + '<ul> - Please accept the agreement before posting. </ul>'
			}
	}
	
	var thumbnail = document.video_form.thumbnail.value.toLowerCase();
   	
   	//check thumbnail file type only if form action is add and thumbnail is being uploaded OR form action is edit and thumbnail is being uploaded.
   	if (thumbnail.length > 0)
   	{
   	if ((document.video_form.action.search("add") !== -1) || ((document.video_form.action.search("edit") !== -1) &&(document.video_form.uploaded.value !== ""))){
   		 if ( thumbnail.search('jpg') == '-1' && thumbnail.search('jpeg') == '-1') {
			errorNum++;
            msg = msg + '<ul> - Please upload your thumbnail image video in .jpg format. </ul>'
		 }   		
   	}
   	}
	
	var pv = document.video_form.pv.value;
   	var uploaded = document.video_form.uploaded.value.toLowerCase();
   	
   	//check video file type only if form action is add OR form action is edit and video is being updated.
    if ((document.video_form.action.search("add") !== -1) || ((document.video_form.action.search("edit") !== -1) &&(document.video_form.uploaded.value !== ""))){
    
        		if(pv === "1"){
    		    if ( uploaded.search('mpg') == '-1' &&  
                 uploaded.search('mp4') == '-1' &&    		
                 uploaded.search('mov') == '-1' &&    		
                 uploaded.search('avi') == '-1' &&    		
                 uploaded.search('flv') == '-1' &&    	
                 uploaded.search('mswmm') == '-1' &&    	
                 uploaded.search('swf') == '-1' &&    	
                 uploaded.search('wmv') == '-1'
    		    ) {
					errorNum++;
                	msg = msg + '<ul> - Please upload your Live Action video in .mov , .avi , .mp4 , .wmv , .mswmm , .mpg, .swf or .flv format. </ul>'
				}

    		}else{
    		    if ( uploaded.search('mpg') == '-1' &&  
                 uploaded.search('mp4') == '-1' &&    		
                 uploaded.search('mov') == '-1' &&    		
                 uploaded.search('avi') == '-1' &&    		
                 uploaded.search('flv') == '-1' &&    	
                 uploaded.search('mswmm') == '-1' &&    	  	
                 uploaded.search('wmv') == '-1'
    		    ) {
					errorNum++;
                	msg = msg + '<ul> - Please upload your Live Action video in .mov , .avi , .mp4 , .wmv , .mswmm , .mpg or .flv format. </ul>'
				}   		
    		}  		
    		
    }

	if (errorNum > 0) {
                d.style.display     ='block';
				d.style.borderWidth = '1px';
				d.style.borderStyle = 'solid';
				d.style.borderColor = 'red';
				d.style.width       = '80%';
				d.style.padding     = '10px';
				d.style.margin      = '3px';
				d.innerHTML         =  msg;
    
    window.location.hash="errors"; 
    return false;
    } else {
        lb = document.createElement("a");
        lb.content= '../../public/files/uploading.html';
        lb.lbAction="index.php";
        pop = new lightbox(lb);
        pop.activate();
    
    }
}

function powerFormOn() {
            document.video_form.pv.value = "1";
            e = $('format_spec');            
            e.innerHTML = '.swf/.mswmm/.mov/.dv/.mpg /.avi/.wmv/.flv/.mp4 &nbsp;';
}
    
function powerFormOff() {
             document.video_form.pv.value = "0";
            e = $('format_spec');            
            e.innerHTML = '.mswmm/.mov/.dv/.mpg/.avi/.wmv/.flv/ .mp4 &nbsp;';
}
/// COURSE BUILDER

function vn_load_videos() { 
	var form = document.vn_form;
	
	
//	alert(form.g_param.value + form.g_value.value);


	xajax_ajx_video_pag_ext('load',[form.g_param.value,form.g_value.value, 'video_navigator'] ,[ '0','13'] ,'vn_box' );
}
function vn_details(vid) {

    var d = $(vid);
      if (d.style.display == 'none')
      {
		xajax_ajx_vn_details(vid , vid);
		d.style.display =  'block';
      } else { 
      
		 d.innerHTML = "";	
     	 d.style.display = 'none';
     	 
      }
	

}
function cb_add_to_course(vid)
{
	var form = document.course_form;	
	cid = form.cid.value;
	xajax_ajx_vn_add_course(cid , vid , 'video_course_listing');
	
}
function cb_up(vid) {
	var form = document.course_form;	
	cid = form.cid.value;

	xajax_ajx_cb_playlist_arrange("up"  , vid , cid , 'video_course_listing');

}
function cb_down(vid) {
	var form = document.course_form;	
	cid = form.cid.value;

	xajax_ajx_cb_playlist_arrange("down"  , vid , cid , 'video_course_listing');

}
function delete_from_course(vid) {
	var form = document.course_form;	
	cid = form.cid.value;

	xajax_ajx_cb_playlist_arrange("delete"  , vid , cid , 'video_course_listing');

}

//// GENERAL FUNCTIONS
    // Replaces all instances of the given substring.
    String.prototype.replaceAll = function(
    strTarget, // The substring you want to replace
    strSubString // The string you want to replace in.
    ){
    var strText = this;
    var intIndexOfMatch = strText.indexOf( strTarget );
     
    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1){
    // Relace out the current instance.
    strText = strText.replace( strTarget, strSubString )
     
    // Get the index of any next matching substring.
    intIndexOfMatch = strText.indexOf( strTarget );
    }
     
    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return( strText );
    }
    
    function openWin( windowURL, windowName, windowFeatures ) {
        return window.open( windowURL, windowName, windowFeatures );
    }     
/* used for popup forms (see comment / share form)     */
function popSubmit(form) 
{ 
    var popName = "formpopup"; 
    var popStyle = "width=300,height=300,location=yes,resizable=yes"; 
    form.action = "theOtherSubmit.php"; 
    form.target = popName; 
    window.open("about:blank",popName,popStyle); 
} 

