// JavaScript Document
function changeVerImage(){
	var new_src ='modules/securimage/securimage_show.php?sid=' +Math.random();
	var images = document.getElementsByName("ver_image");
	for (i =0; i<images.length; i++){
		images[i].src=new_src;
	}
}
var enter_counter=0;
	/*function showComment(comment_items){

		if(document.getElementById(comment_items).style.display=='none'){
			new Effect.BlindDown(comment_items, {duration: 0.5});
			//alert(comment_items.id);
		}else
		{
			new Effect.BlindUp(comment_items, {duration: 0.5});
		}
		
	}*/
	jQuery(document).ready(function($){
	showComment = function(comment_items){
	$("#"+comment_items).slideToggle("slow");
	}
	});// end jQuery
	
	function SelText(form)
	{
	if (form.value == "Anonymous")
	{
	form.value = "";
	}
	}	
	
	function set_a_mouseOver(a_href){
	a_href.style.textDecoration='underline';
	}
	function set_a_mouseOut(a_href){
	a_href.style.textDecoration='none';
	}	
	
	function check_values(submit_form){

		customer_name = submit_form.customer_name.value;
		code_check = submit_form.code_check.value;
		comments_area = submit_form.comments.value;
		connect_tw_status = submit_form.connect_tw_status.checked;

		if(customer_name!=''){
		}else{
			alert('Please input your name');
			return false;
		}
		
		if(comments_area!=''){
		}else{
			alert('Please input comments');
			return false;
		}

		if(code_check!=''){
		}else{
			alert('Please input code');
			return false;
		}
		if(connect_tw_status){
			tw_char_count = document.getElementById('tw_counter').innerHTML;
			tw_content = document.getElementById('texts').value;
			if(tw_content.length==0){
			    alert('Please input comments');
				return false;
			}			
			if(tw_char_count<0)
				if(!confirm('You have gone over the Twitter character limit. Characters after the limit will be lost. Edit your message or proceed anyway?'))
				return false;

		}		
		if(submit_form.item_id!=undefined){
			item_id = submit_form.item_id.value;
		}else{
			item_id =0;
		}
		check_textarea(submit_form.comments, item_id );
		check_enter(submit_form.comments);
		return true;
		//alert(customer_name);
	}
	
	function scrollDown(scroll_item){
		//new Effect.ScrollTo(scroll_item); 
		//return false;
		jQuery(document).ready(function($){
		$.scrollTo($('#'+scroll_item),800);
		});
	}
	
	function check_length(txt_area){
		txt_content=txt_area.value;
		txt_area.value=txt_content.substring(0, 1000);
	}

	function check_textarea(txt_area, item_id){ 
	
		if(item_id ==0){
			space_position = 91;
			max_length = 90;
		}else{
			space_position = 76;
			max_length = 75;
		}
		txt_content=txt_area.value;
		temp_txt ="";
		newline_p = txt_content.indexOf("\n");
		space_p = txt_content.substr(0,space_position).lastIndexOf(" ");
		txt_length=txt_content.length;
		
		while (txt_length>max_length){
			if(newline_p ==-1 && space_p ==-1){//if there is no new line or space in the length
				temp_txt+=txt_content.substr(0,max_length)+"\n";
				txt_content = txt_content.substr(max_length, txt_length);
			}
			else if(newline_p>max_length && space_p ==-1){//if the line exist the length and no space 
				temp_txt+=txt_content.substr(0,max_length)+"\n";
				txt_content = txt_content.substr(max_length, txt_length);
			}
			else if(newline_p >=0 && newline_p<=max_length && space_p >=0 && space_p<=max_length){ 
				temp_txt+=txt_content.substr(0,(space_p+1));
				txt_content = txt_content.substr((space_p+1), txt_length);
			}
			else if(space_p >=0 && space_p<=max_length && newline_p==-1){ 
				temp_txt+=txt_content.substr(0,(space_p+1));
				txt_content = txt_content.substr((space_p+1), txt_length);
			}
			else if (space_p >=0 && space_p<=max_length && newline_p>max_length ){
				temp_txt+=txt_content.substr(0,(space_p+1));
				txt_content = txt_content.substr((space_p+1), txt_length);
			}
			else if(newline_p >=0 && newline_p<=max_length && space_p==-1){ 
				temp_txt+=txt_content.substr(0,(newline_p+1));
				txt_content = txt_content.substr((newline_p+1), txt_length);
			}
				
			txt_length=txt_content.length;
			newline_p = txt_content.indexOf("\n");
			space_p = txt_content.substr(0,space_position).lastIndexOf(" ");
	
		}
			temp_txt+=txt_content;
			txt_area.value=temp_txt;

	}
	
	function check_enter(txt_area){
		txt_content=txt_area.value;
		ie_enter_patt = /(\r\n){3,}/g;	
		ff_enter_partt= /(\n){3,}/g;		
		
		//alert(txt_content.replace(ie_enter_patt,"aaa"));
		//alert(ff_enter_partt.test(txt_content)+"FF");
		
		if(ie_enter_patt.test(txt_content)){
			txt_area.value=txt_content.replace(/(\r\n){3,}/g,"\r\n\r\n\r\n");
		}else{
			txt_area.value=txt_content.replace(/(\n){3,}/g,"\n\n\n");
		}

	}
// for comment function use	
function SelText2()
{
	if (document.submit_form.comments.value == "Add your comment here. Comments are made public, therefore please do not include personal information such as email or phone number.")
	{
	document.submit_form.comments.value = "";
	}
	document.submit_form.comments.style.color = "#000000";
	
}
//
function SelText3()
{
	if (document.submit_form.comments.value == "Add your review here. Reviews are made public, therefore please do not include personal information such as email or phone number.")
	{
	document.submit_form.comments.value = "";
	}
	document.submit_form.comments.style.color = "#000000";
	
}

var $block_comment = jQuery.noConflict();           
$block_comment(document).ready(function(){
	$block_comment("#submit_form").submit(function(){
		var c_name = $block_comment("#customer_name").val();
		if(c_name == '') { alert('Please type in your name'); return false; }		
	});		
});	