function view_comments(type, page)
{
	var str = '';
	switch (type){
		case 'all':{
			str = '<li id="active-tab"><a href="javascript:view_comments('+"'all'"+' ,1)">All</a></li><li><a href="javascript:view_comments('+"'question'"+', 1)">Questions</a></li><li><a href="javascript:view_comments('+"'comment'"+', 1)">Comments</a></li><li><a href="javascript:view_comments('+"'review'"+', 1)">Reviews</a></li>';
			//str = '<li id="active-tab"><a href="#">All</a></li><li><a href="javascript:view_comments('question', 1)">Questions</a></li><li><a href="javascript:view_comments('comment', 1)">Comments</a></li><li><a href="javascript:view_comments('review', 1)">Reviews</a></li>';
			break;
		}
		case 'question':{
			str = '<li><a href="javascript:view_comments('+"'all'"+' ,1)">All</a></li><li id="active-tab"><a href="javascript:view_comments('+"'question'"+', 1)">Questions</a></li><li><a href="javascript:view_comments('+"'comment'"+', 1)"><span>Comments</span></a></li><li><a href="javascript:view_comments('+"'review'"+', 1)">Reviews</a></li>';
			//str = '<li ><a href="javascript:view_comments('+"'all'"+' ,1)">All</a></li><li><a href="#" id="active-tab">Questions</a></li><li><a href="javascript:view_comments('comment', 1)">Comments</a></li><li><a href="javascript:view_comments('review', 1)">Reviews</a></li>';
			break;
		}
		case 'comment':{
			str = '<li ><a href="javascript:view_comments('+"'all'"+' ,1)">All</a></li><li><a href="javascript:view_comments('+"'question'"+', 1)"><span>Questions</span></a></li><li id="active-tab"><a href="javascript:view_comments('+"'comment'"+', 1)">Comments</a></li><li><a href="javascript:view_comments('+"'review'"+', 1)">Reviews</a></li>'
			break;
		}
		case 'review':{
			str = '<li ><a href="javascript:view_comments('+"'all'"+' ,1)">All</a></li><li><a href="javascript:view_comments('+"'question'"+', 1)"><span>Questions</span></a></li><li><a href="javascript:view_comments('+"'comment'"+', 1)"><span>Comments</span></a></li><li id="active-tab"><a href="javascript:view_comments('+"'review'"+', 1)">Reviews</a></li>'
			break;
		}
	}

	byid("curr_type").value = type;

	byid("miniTabs").innerHTML = str;
//    var id_listing_info=byid("id_listing_info").value;    
    var id_product=byid("id_product").value;    
    ajax("../ajax/comments.php?id_product="+id_product+"&type="+type+"&action=view" + "&pg=" + page, on_comments_add);
//    ajax("../ajax/comments.php?listing_id=66&type="+type+"&action=view" + "&pg=" + page, on_comments_add);
}

//comment system
function on_comments_add(result)
{
    if (comment = byid('txtComments'))
        comment.value = "";
    byid('comments_block').innerHTML = result.str;
    byid('high_com_count').innerHTML = result.com_num;
    //byid('question_num').innerHTML = result.question_num;
    //byid('all_num').innerHTML = result.all_num;
}

function add_comments(type, page)
{
    var id_product=byid("id_product").value;    
//    var id_listing_info=66;//byid("id_listing_info").value;
    var addcomment=byid("txtComments").value;
    var name=byid("comment_name").value;
    var email=byid("comment_email").value;
    var website=byid("comment_website").value;
    var img_src=byid("comment_img_src").src;
//alert(img_src);
    var rating=byid("comment_rating").value;
    var curr_type=byid("curr_type").value;

    if (addcomment.replace(/^\s+|\s+$/g,'') == '') {
        alert('You must fill in the comment box!');
        return false;
    }
   var args="&name="+name+"&email="+email+"&website="+website+"&img_src="+img_src;
       	args=args+'&rating='+rating+'&curr_type='+curr_type;

	if (type=='review')
	{
	Element.hide('submit_review');
	}
    //var user_id=byid("user_id").value;
    //var url = 'view_video.php?action=checkfavour&id_listing='+id_listing_info;
    added_com=escape(addcomment);
//    ajax("../ajax/comments.php?listing_id="+id_listing_info+"&added_com="+added_com+args+"&type="+type + "&pg=" + page, on_comments_add);
    ajax("../ajax/comments.php?id_product="+id_product+"&added_com="+added_com+args+"&type="+type + "&pg=" + page, on_comments_add);

}
function on_comments_add(result)
{

byid("comment_name").value="";
byid("comment_email").value="";
byid("comment_website").value="";
byid("comment_img_src").src="";
byid("comment_rating").value="";
byid("progress").innerHTML="Upload Progress: Please Select File";
//reset rating by default
reset_rating();
    if (comment = byid('txtComments'))
        comment.value = "";
    byid('comments_block').innerHTML = result.str;
    //byid('com_num').innerHTML = result.com_num;
    //byid('question_num').innerHTML = result.question_num;
    //byid('all_num').innerHTML = result.all_num;
}
function showReply(comment_id)
{
    byid('replink[' + comment_id + ']').innerHTML = '<strong>Type your answer in the following box: </strong>';
    layerShow('reply_comid[' + comment_id + ']');
}

function post_reply_comid(comment_id, active_comment_type, page)
{
//    var id_listing_info=byid("id_listing_info").value;
    var id_product=byid("id_product").value;
    answer = escape(byid('answer[' + comment_id + ']').value);
//    ajax("../ajax/comments.php?listing_id=" + id_listing_info + "&action=answer&comment_id=" + comment_id + "&answer=" + answer + "&type=" + active_comment_type + "&pg=" + page, on_comments_add);
    ajax("../ajax/comments.php?id_product=" + id_product + "&action=answer&comment_id=" + comment_id + "&answer=" + answer + "&type=" + active_comment_type + "&pg=" + page, on_comments_add);
}

function removeClass(obj)
{new Element.removeClassName(obj,"error");	}

function addClass(obj)
{new Element.addClassName(obj,"error");	}

//tell a colleague form (on product page)
function tell_a_colleague()
{
var product_id=byid("product_id").value;
var name=byid("colleague_name").value;
var email=byid("colleague_email").value;
var subject=byid("colleague_subject").value;
var message=byid("colleague_message").value;
var err="";
var str;

	if (name =="")
		{addClass("tr_col_name_1");addClass("tr_col_name");err="1";}
	else
		{removeClass("tr_col_name");removeClass("tr_col_name_1");}
	if ((email =="")||(!IsValidEmail(email)))
		{addClass("tr_col_email");addClass("tr_col_email_1");err="1";}
	else
		{removeClass("tr_col_email");removeClass("tr_col_email_1");}
	if (err=="")
	{
	    ajax("../ajax/organic.php?action=tell_a_colleague&name="+name+"&email="+email+'&subject='+subject+'&message='+message+'&product_id='+product_id, on_tell_a_colleague);
	}
}

function on_tell_a_colleague(result)
{
byid("tell_a_colleague").innerHTML="Your message has been sent.<br><a href='javascript:new_form_tell_a_golleague();'>Send new one</a>";
}

function new_form_tell_a_golleague()
{
    ajax("../ajax/organic.php?action=new_form_tell_a_colleague", on_new_form_tell_a_colleague);
}

function on_new_form_tell_a_colleague(result)
{
byid("tell_a_colleague").innerHTML=result.str;
}


function set_tab_content(id)
{
	ajax("../ajax/organic.php?action=set_tab_content&subtab_id="+id, on_set_tab_content);
}
function on_set_tab_content(result)
{
byid("headingBlock").innerHTML=result.str;
byid("detailBlock").innerHTML=result.section_data;
}