    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...';
}

function template_reload(uri , page_number) {
    var a;
    a = uri+"?p="+page_number;

    window.location = a;
}

function show_pass() {
    var d = $('password_div');
    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 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 show_div(id) {
    var d = $(id);
//    d.style.display = "block";
    new Effect.BlindDown(d,{duration:0.5});

}
function hide_div(id) {
    var d = $(id);
    new Effect.BlindUp(d,{duration:0.5});
    
}

// 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';
}



// 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 = 'Not very interesting.';
            break;
            case '2':
                msg.innerHTML = 'Seen it before';
            
            break;
            case '3':
                msg.innerHTML = 'Good design.';
            
            break;
            case '4':
                msg.innerHTML = 'Almost perfect!';
            
            break;
            case '5':
                msg.innerHTML = 'The work of a web guru!';
            
            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    

//when ajax loading, display this
function load(id)
{
        d = $(id);
        d.innerHTML = '<div class="indicator"><img src="/public/images/indicator.gif" /></div>';
    return false;
    
}

function clear_template_author_buttons() {
	var template_author = document.template_form.template_author;
	template_author[0].checked = false;
	template_author[1].checked = false;
}

// JAVASCRIPT VALIDATION //
function validate_template_form() {
				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>';

    var title = document.template_form.title;
    		if ( title.value.length < 4 ) {
				errorNum++;
                msg = msg + '<ul> - Template title is too short (4 character minimum). </ul>'
			}
			
	var template_author = document.template_form.template_author;
    		if ( template_author[1].checked == false && template_author[0].checked == false) {
				errorNum++;
                msg = msg + '<ul> - Please select the author of the template. </ul>'
			}

	
	var author = document.template_form.author;
    		if ( template_author[1].checked == true && author.value.length < 1 ) {
				errorNum++;
                msg = msg + '<ul> - Please provide the name of the template author. </ul>'
			}

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

	var checked_common_tag_count = 0;
	var c_tag;
	var common_tag_count = 18;
	for (i=0;i<common_tag_count;i++) {
    	c_tag = "common_tag_"+i;
		if(document.template_form.elements[c_tag].checked == true){
			checked_common_tag_count++;
		}
    
    }

    var tags = document.template_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 < 4 && checked_common_tag_count == 0) {
				errorNum++;
                msg = msg + '<ul> - Please include at least one tag of at least 4 characters. </ul>'
			}

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

    var uploaded = document.template_form.uploaded.value.toLowerCase();
    		if ( uploaded.search('zip') == '-1' ) {
				errorNum++;
                msg = msg + '<ul> - Please upload a .zip file. </ul>'
			}


	if (errorNum > 0) {
                d.style.display     ='block';
				d.style.borderWidth = '4px';
				d.style.borderStyle = 'solid';
				d.style.borderColor = 'red';
				d.style.width = '80%';
				d.style.padding = '10px';
				d.style.margin = '10px';
				d.innerHTML =  msg;
    
    window.location.hash="errors"; 
    return false;
    }
}

function enable_upload() {
    document.template_form.uploaded.disabled=false;
    document.template_form.screenshot.disabled=false;
    $('up_en').innerHTML='';
}


//// 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 );
    }
    
    
