function validate_product_model_params(manufacturer_name,series_name,model_name,simple_name){
    if(manufacturer_name == '' || (series_name == '' && model_name == '' && simple_name == '')){
        alert('Plase input valid product model parameters (You should input manufacturer_name and one or more of series_name , model_name and simple_name)');
        return false;
    }
    else{      
        return true;
    }
}

function validator_keyword(input_id){
    var qurey_input = $(input_id);
    if (qurey_input.value == "" || qurey_input.value == "example.com"){
        alert("please input the key word");
        qurey_input.focus();
        return false;
    }
    return true;
}

function submit_email_friend_form(form){
    var first_email = $('email_friend_user_addr').value;
    var second_email = $('email_friend_addr2').value;
    var third_email = $('email_friend_addr3').value;
    var your_email = $('email_friend_user_addr').value;
    if(your_email == ''){
        alert("Please enter your email");
        return false;
    }

    if(first_email == '' && second_email == '' && third_email == ''){
        alert("Please enter at least one recipient email");
        return false;
    }

    if($('email_friend_title').value == '' && $('email_friend_content').value == ''){
        alert("Please enter title or content");
        return false;
    }

    if(!validte_email_value(your_email) || !validte_email_value(first_email) ||
        !validte_email_value(second_email) || !validte_email_value(third_email)){
        alert("Please enter a valid email");
        return false;
    }

    form.onsubmit();
    return true;
}

function validte_email_value(content){
    return content == '' || validate_email_fomat(content);
}

function validate_email_fomat(content){
    emial_exp = new RegExp('([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})', 'img');
    return emial_exp.exec(content);
}

function validator_submit_deal_form(){
    if($('submit_deal_deal_url').value == ''){
        alert('Please enter deal url');
        $('submit_deal_deal_url').focus();
        return false;
    }else if($('submit_deal_title').value == ''){
        alert('Please enter title');
        $('submit_deal_title').focus();
        return false;
    }
    return true;
}

function toggle_deal_share_form(deal_id){
    if($('full_deal_content')){
        document.getElementById('email_friend_content').value =  $('full_deal_content').innerHTML;
    }
    $('tellafriend'+deal_id).toggle();
}

//generated_form_deal_ids = [];
//function toggle_deal_share_form(deal_id){
//    Element.hide("problem"+deal_id)
//    if(generated_form_deal_ids.indexOf(deal_id) < 0){
//        var url = "/deals/"+deal_id+"/share";
//        new Ajax.Request(url,{method:'get'});
//        generated_form_deal_ids.push(deal_id);
//    }
//    Element.toggle("tellafriend"+deal_id);
//}

report_problem_form_deal_ids = [];
function toggle_report_probleme_form(deal_id){
    Element.hide("tellafriend"+deal_id);
    if(report_problem_form_deal_ids.indexOf(deal_id) < 0){
        Element.insert("problem"+deal_id, $('deal_report_problem_form').innerHTML);
        report_problem_form_deal_ids.push(deal_id);
        _form = $('problem' + deal_id).getElementsByTagName('form')[0];
        _form["problem_report[deal_id]"].value = deal_id;
        $("deal_id_for_report").value = deal_id;
    }
    Element.toggle("problem"+deal_id)
}


function vote_deal_comment(deal_id,if_good){
    if (if_good)
    {
        new Ajax.Request("/submit_valid_vote?deal_id=" +deal_id);
        var votes_span = $("votesgood");
        votes_span.innerHTML = (parseInt(votes_span.innerHTML) + 1)
    }
    else
    {
        new Ajax.Request("/submit_invalid_vote?deal_id=" +deal_id);
        var votes_span2 = $("votesbad");
        votes_span2.innerHTML = (parseInt(votes_span2.innerHTML) + 1)
    }
    var comment_div = $("deal_comment_div");
    _form = comment_div.getElementsByTagName('form')[0];
    _form["comment[comment_type]"].value = (if_good ? '1' : '2');
    comment_div.setAttribute('class','deal_vote deal_vote_gray')
    comment_div.setAttribute('className','deal_vote deal_vote_gray')
    $("valid_vote").onclick = 'return false;'
    $("invalid_vote").onclick = 'return false;'
}


function initialize_coupon_comment_form(coupon_id,comment_type){
    var _form = $('comments' + coupon_id).getElementsByTagName('form')[0];
    if(!_form){
        Element.insert('coupon_comments_from_cp'+coupon_id,$('coupon_comments_form').innerHTML);
        _form = $('comments' + coupon_id).getElementsByTagName('form')[0];
        var captcha_div = $A(_form.getElementsByTagName('div')).find(function(_div){
            return _div.className == 'for_comment_captcha'
        });
        if(captcha_div){
            captcha_div.id = "for_comment_captcha_cp" + coupon_id
        }
    }
    _form["comment[comment_type]"].value = comment_type;
    _form['comment[coupon_id]'].value = coupon_id;
    _form['cancel'].onclick=function(){
        Effect.toggle('comments'+coupon_id,'blind');
    }
}

var CommentJs = {
    has_captcha_coupon_ids : [],
    add_captcha_histories : function(coupon_id){
        this.has_captcha_coupon_ids.push(coupon_id);
    },
    remove_all_captcha : function(){
        $A(this.has_captcha_coupon_ids).each(function(coupon_id){
            var captcha_div = $('for_comment_captcha_cp'+coupon_id);
            if(captcha_div){
                captcha_div.innerHTML='';
            }
        }
    );
        $A(this.has_captcha_coupon_ids).clear();
    }
}

function vote_coupon_comment(coupon_id,if_good){
    if (if_good)
    {
        new Ajax.Request("/submit_valid_vote?coupon_id=" +coupon_id);
        var goole_span = $("votesgood"+coupon_id);
        goole_span.innerHTML = (parseInt(goole_span.innerHTML) + 1)
    }
    else
    {
        new Ajax.Request("/submit_invalid_vote?coupon_id=" +coupon_id);
        var bad_span = $("votesbad"+coupon_id);
        bad_span.innerHTML = (parseInt(bad_span.innerHTML)+1)
    }
    var comment_div = $("coupon_comments_div_" +coupon_id);
    comment_div.setAttribute('class','bk16_N_r bk16_N_gray')
    comment_div.setAttribute('className','bk16_N_r bk16_N_gray')
    $("valid_vote_" + coupon_id).onclick = 'return false;'
    $("invalid_vote_" + coupon_id).onclick = 'return false;'
    initialize_coupon_comment_form(coupon_id,if_good ? '1' : '2')
    if(!Element.visible('comments'+coupon_id) ){
        Effect.BlindDown('comments'+coupon_id);
    }
}

function toggole_coupon_comments(coupon_id,comment_type){
    initialize_coupon_comment_form(coupon_id,comment_type);
    Effect.toggle('comments'+coupon_id,'blind');
}



function submit_share_deal_form(_form){
    new Ajax.Request(_form.action,
    {
        asynchronous:true,
        evalScripts:true,
        method:'post',
        parameters:Form.serialize(_form)
    }
);
}

function submit_remote_form_without_clear(_form){
    new Ajax.Request(_form.action,
    {
        asynchronous:true,
        evalScripts:true,
        method:'post',
        parameters:Form.serialize(_form)
    }
);
}

function submit_remote_form(form){
    new Ajax.Request(form.action,
    {
        asynchronous:true,
        evalScripts:true,
        method:'post',
        parameters:Form.serialize(form)
    }
);
    $A(form.elements).each(
    function(element){
        if(element.type == 'text' || element.tagName.toLowerCase() == 'textarea'){
            element.value = '';
        }
    }
);
}


function generate_compare_price_htmls(type_id,product_id){
    var cobrand_id = '1423';
    var rating_star_type = 0;
    //var cb_limit = 6;
    var open_link_type2 = 1;
    var show_link_price2 = 1;
    var head_title_type = '1';
    document.write('<scr'+'ipt src="http://ah.pricegrabber.com/cb_table.php?'+
        type_id+'='+product_id+
        '&dw=1'+
        '&cobrand_id='+cobrand_id+
        '&rst='+rating_star_type+
        '&slp='+show_link_price2+
        '&olt='+open_link_type2+
        //'&l='+cb_limit+
    '&w=400'+
        '&htt='+head_title_type+
        '"></scr'+'ipt>');
}

function generate_width_compare_price_htmls(type_id,product_id){
    var cobrand_id = '1423';
    var rating_star_type = 1;
    //var cb_limit = 6;
    var open_link_type2 = 1;
    var show_link_price2 = 1;
    var head_title_type = '1';
    document.write('<scr'+'ipt src="http://ah.pricegrabber.com/cb_table.php?'+
        type_id+'='+product_id+
        '&dw=1'+
        '&cobrand_id='+cobrand_id+
        '&rst='+rating_star_type+
        '&slp='+show_link_price2+
        '&olt='+open_link_type2+
        //'&l='+cb_limit+
    '&w=500'+
        '&htt='+head_title_type+
        '"></scr'+'ipt>');
}

function cp_clipboard(text) {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
        var divholder = document.createElement('div');
        divholder.id = flashcopier;
        document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="http://livehotdeals.com/images/liveclipboard.swf" FlashVars="liveclipboard='+encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
}

function toggle_by_id(id1,id2)
{
    $(id1).toggle();
    $(id2).toggle();
}

function toggle_htgt(id)
{
    $('htgt_o'+id).toggle();
    $('htgt_c'+id).toggle();
}

function open_top_coupons()
{
    document.cookie = "topcoupons=true";
    $('top_coupon_o').style.display = "block";
    $('top_coupon_c').style.display = "none";
}

function close_top_coupons()
{
    var exptime = new Date();
    exptime.setDate(exptime.getDate()+70000);
    document.cookie = "topcoupons=false; expires=" + exptime.toGMTString();
    $('top_coupon_o').style.display = "none";
    $('top_coupon_c').style.display = "block";
}

var active_top_deal = ''
function toggle_weekly_deals(id)
{
    if(active_top_deal == id) return;
    if(active_top_deal && active_top_deal != ''){
        $('contr_'+id).className = 'current';
        $('contr_'+active_top_deal).className = '';
        Element.toggle(active_top_deal);
    }
    active_top_deal = id;
    Element.toggle(id);
}

function vaildate_search_form(searchForm){
    var check_box = searchForm['type'];
    var qurey_input = searchForm.keyword;
    if((check_box.options && check_box.options[check_box.options.selectedIndex].value == 'coupon')||
        (check_box.value && check_box.value=='coupon')){
        qurey_input.value = searchForm.suggest_keyword.value;
    }
    if (qurey_input.value == "" || qurey_input.value == 'example.com'){
        alert("please input the key word");
        qurey_input.focus();
        return false;
    }
    else{
        if(searchForm.suggest_keyword != null && searchForm.suggest_keyword != undefined){
            searchForm.suggest_keyword.disabled = true;}
        return true;}
}

function vaildate_search_coupon_form(searchForm){
    var qurey_input = searchForm.keyword;
    if (qurey_input.value == "" || qurey_input.value == 'example.com'){
        alert("please input the key word");
        qurey_input.focus();
        return false;
    }
    return true;
}


function changeSearchType(selected_value){
    if(selected_value == 'coupon'){
        Element.hide('keyword');
        Element.show('suggest_keyword');
        $('suggest_keyword').value = $('keyword').value
    }else{
        Element.hide('suggest_keyword');
        Element.show('keyword');
        $('keyword').value = $('suggest_keyword').value
    }
}

function fbs_click() {
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

function show_deal_categories(){
    Element.show('deal_category');
    Element.hide('coupon_category');
    $('deal_category_tag').setAttribute('class','current');
    $('deal_category_tag').setAttribute('className','current');
    $('coupon_category_tag').setAttribute('class','');
    $('coupon_category_tag').setAttribute('className','');
}

function show_coupon_categories(){
    Element.hide('deal_category');
    Element.show('coupon_category');
    $('deal_category_tag').setAttribute('class','');
    $('deal_category_tag').setAttribute('className','');
    $('coupon_category_tag').setAttribute('class','current');
    $('coupon_category_tag').setAttribute('className','current');
}

function focus_email_subscribe(obj){
    obj.style.background='#F7F7F2';
    if(obj.value=='Your email address'){obj.value='';}
    obj.style.color='#333';
}

function blur_email_subscribe(obj){
    obj.style.background='#fff';
    if(obj.value==''){obj.style.color='#888';obj.value='Your email address';}
}
/***********************************************
 * Cool DHTML tooltip script II- Dynamic Drive DHTML code library (www.dynamicdrive.com)
 * This notice MUST stay intact for legal use
 * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
 ***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=30 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=6 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="http://livehotdeals.com/images/tooltip_arrow.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
    var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor, thetextcolor){
    if (ns6||ie){
        if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
        if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
        if (typeof thetextcolor!="undefined" && thetextcolor!="") tipobj.style.color=thetextcolor
        tipobj.innerHTML=thetext
        enabletip=true
        return false;
    }
    return true;
}

function positiontip(e){
    if (enabletip){
        var nondefaultpos=false
        var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
        var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
        //Find out how close the mouse is to the corner of the window
        var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
        var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

        var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
        var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

        var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge<tipobj.offsetWidth){
            //move the horizontal position of the menu to the left by it's width
            tipobj.style.left=curX-tipobj.offsetWidth+"px"
            nondefaultpos=true
        }
        else if (curX<leftedge)
            tipobj.style.left="5px"
        else{
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
            pointerobj.style.left=curX+offsetfromcursorX+"px"
        }

        //same concept with the vertical position
        if (bottomedge<tipobj.offsetHeight){
            tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
            nondefaultpos=true
        }
        else{
            tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
            pointerobj.style.top=curY+offsetfromcursorY+"px"
        }
        tipobj.style.visibility="visible"
        if (!nondefaultpos)
            pointerobj.style.visibility="visible"
        else
            pointerobj.style.visibility="hidden"
    }
}

function hideddrivetip(){
    if (ns6||ie){
        enabletip=false
        tipobj.style.visibility="hidden"
        pointerobj.style.visibility="hidden"
        tipobj.style.left="-1000px"
        tipobj.style.backgroundColor=''
        tipobj.style.width=''
    }
}

document.onmousemove=positiontip

var clip = null;
// setup single ZeroClipboard object for all our elements
clip = new ZeroClipboard.Client();
ZeroClipboard.setMoviePath( 'http://livehotdeals.com/images/ZeroClipboard.swf' );
clip.setHandCursor( true );
clip.addEventListener('mouseOver', function(client) {
    ddrivetip('Click to copy coupon code and open site...', 240, 'fff','85562d');
});
clip.addEventListener('mouseOut', function(client) {
    hideddrivetip('');
});

function openlink(link) {
    window.open(link);
}

function flashChecker()
{
    var hasFlash=0;         //
    var flashVersion=0;     //
    if(document.all){       //if ie(not lower than ie4 )
        var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
        if(swf) {
            hasFlash=1;
            VSwf = swf.GetVariable("$version");
            flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
        }
    }
    else{
        if (navigator.plugins && navigator.plugins.length > 0){
            var theswf = navigator.plugins["Shockwave Flash"];
            if (theswf){
                hasFlash=1;
                var words = theswf.description.split(" ");
                for (var i = 0; i < words.length; ++i)
                {
                    if (isNaN(parseInt(words[i]))) continue;
                    flashVersion = parseInt(words[i]);
                }
            }
        }
    }
    return {
        f:hasFlash,
        v:flashVersion
    };
}

function copy_to_clipboard(text, link, object) {
    var fls = flashChecker();
    if(fls.f==1 && fls.v>8){
        // set the clip text to our innerHTML
        clip.setText(text);
        //if this is the first time , create it ,if not , reposition the movie over our element
        if (clip.div) {
            //clip.receiveEvent('mouseout', null);
            clip.reposition(object);
        }
        else clip.glue(object);
        //clip.receiveEvent('mouseover', null);
        var our_link = link;
        clip.setEventListener('mouseup', function(client) {
            openlink(our_link);
            hideddrivetip('');
        });
    }
}

function intval(v)
{
    v = parseInt(v);
    return isNaN(v) ? 0 : v;
}

function getPos(e)
{
    var l = 0;

    var t = 0;

    var w = intval(e.style.width);

    var h = intval(e.style.height);

    var wb = e.offsetWidth;

    var hb = e.offsetHeight;

    while (e.offsetParent){

        l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0);

        t += e.offsetTop + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0);

        e = e.offsetParent;

    }

    l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0);

    t += e.offsetTop + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0);

    return {
        x:l,
        y:t,
        w:w,
        h:h,
        wb:wb,
        hb:hb
    };

}


function getScroll()
{
    var t, l, w, h;

    if (document.documentElement && document.documentElement.scrollTop) {

        t = document.documentElement.scrollTop;

        l = document.documentElement.scrollLeft;

        w = document.documentElement.scrollWidth;

        h = document.documentElement.scrollHeight;

    } else if (document.body) {

        t = document.body.scrollTop;

        l = document.body.scrollLeft;

        w = document.body.scrollWidth;

        h = document.body.scrollHeight;

    }

    return {
        t: t,
        l: l,
        w: w,
        h: h
    };
}

function scroller(el, duration)
{
    if(typeof el != 'object') {
        el = document.getElementById(el);
    }
    if(!el) return;
    var z = this;
    z.el = el;
    z.p = getPos(el);
    z.s = getScroll();
    z.clear = function(){
        window.clearInterval(z.timer);z.timer=null
    };

    z.t=(new Date).getTime();
    z.step = function(){
        var t = (new Date).getTime();
        var p = (t - z.t) / duration;
        if (t >= duration + z.t) {
            z.clear();
            window.setTimeout(function(){
                z.scroll(z.p.y, z.p.x)
            },13);

        } else {
            st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
            sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
            z.scroll(st, sl);
        }
    };
    z.scroll = function (t, l){
        window.scrollTo(l, t)
    };

    z.timer = window.setInterval(function(){
        z.step();
    },13);

}

//  function subtmit_vote_comment(form){
//    submit_remote_form_without_clear(form);
////    Element.hide('deal_review_form');
////    scroller('deal_comments_link',800);
//}

function display_deal_comment_form(a_link){
    var deal_comment_from = $('add_deal_comment');
    if(Element.visible(deal_comment_from)){
        a_link.setAttribute('class','add_comment');
        a_link.setAttribute('className','add_comment');
        Element.hide('comments_notice_wrong')
        Effect.toggle(deal_comment_from,'slide')
    }else{
        a_link.setAttribute('class','add_comment add_comment_2');
        a_link.setAttribute('className','add_comment add_comment_2');
        Element.show(deal_comment_from)
        scroller('add_deal_comment',800);
    }
}

var current_htgt_div_for_landing_page = '';
function display_htgt_div(htgt_div_id){
    if(current_htgt_div_for_landing_page != ''){
        Element.hide(current_htgt_div_for_landing_page);
    }
    Element.show(htgt_div_id);
    current_htgt_div_for_landing_page = htgt_div_id;
}


function show_full_deal_description(_id){
    $(_id).style.overflow="visible";
    $(_id).style.height="auto";
    $("full_deal_button").hide();
    $("section_deal_button").show();
}

function show_partial_deal_description(_id){
    $(_id).style.overflow="hidden";
    $(_id).style.height="80px";
    $("full_deal_button").show();
    $("section_deal_button").hide();
}

function if_show_deal_description_button(_id){
    if($(_id).offsetHeight > 112){
        show_partial_deal_description(_id);
    }
    else{
        show_full_deal_description(_id);
        $("section_deal_button").hide();
    }
}

function add_src_type_for_link(obj,type){
    var src_sym = obj.href.indexOf('?') >= 0 ? '&' : '?';
    obj.href = obj.href + src_sym + 'utm_source=' + type;
    obj.onmousedown = function(){
        return true;
    }
    return true;
}

lastElementId = ''
function toggle_compare_price_coupons(event,element_id){
    var last_element = $(lastElementId);
    var toggle_element = $(element_id);
    if(toggle_element != 'undefined'){
        toggle_element.toggle();
        event = event ? event : window.event;
        event.stopPropagation();
        if(lastElementId == ''){
            var hide_f = function(){Element.hide(lastElementId)};
            Event.observe(document,'click', hide_f,false);         
        } 
        else          
            if(lastElementId != element_id){
                last_element.hide();
            }
        toggle_element.onclick= function(event){            
            event = event ? event : window.event;
            event.stopPropagation();
        };        
        Event.stopObserving(Event.element(event),'click', hide_f);  
        Event.stopObserving(toggle_element,'click', hide_f);  
        remove_onmouseover(toggle_element);      
        lastElementId = element_id;        
    }
}

function remove_onmouseover(toggle_element){
    if(toggle_element.style.display != 'none'){
        hideddrivetip();
    } 
}

function onmouseover_compare_price_coupons(element_id,text){
    if($(element_id).style.display == 'none'){
        ddrivetip(text, 180, '#fff', '#333');}
}

lastElementIdLeft = ''
function toggle_compare_price_coupons_left(merchant_id){
    var close_box_id = "merchant_coupon_box_"+merchant_id+"_close";
    var open_box_id = "merchant_coupon_box_"+merchant_id+"_open";
    if($(close_box_id) != 'undefined' && $(open_box_id) != 'undefined'){
        toggle_box(close_box_id,open_box_id);
        if(lastElementIdLeft != '' && lastElementIdLeft != merchant_id && $("merchant_coupon_box_"+lastElementIdLeft+"_open") != 'undefined' && $("merchant_coupon_box_"+lastElementIdLeft+"_close") != 'undefined') {
            Element.hide("merchant_coupon_box_"+lastElementIdLeft+"_open");
            Element.show("merchant_coupon_box_"+lastElementIdLeft+"_close");
        } 
        lastElementIdLeft = merchant_id;    
    }    
}

function toggle_box(close_box_id,open_box_id){
    if($(close_box_id).style.display != 'none' && $(open_box_id).style.display == 'none'){
        Element.hide(close_box_id);
        Element.show(open_box_id);
    }
    else
        if($(open_box_id).style.display != 'none' && $(close_box_id).style.display == 'none' )    {
            Element.hide(open_box_id);
            Element.show(close_box_id);
        }
}

function get_wide_panel_show_deals_ids(panel_id,element_id_prefix){
    var element_div = $(panel_id);
    var ids_array = [];
    if(element_div != null && element_div != undefined){
        var elements_tr = element_div.getElementsByTagName('tr');
        if(elements_tr.length > 0){
            for (var i=0;i<elements_tr.length;i=i+1){
                if(elements_tr[i].style.display != 'none'){
                    var id = elements_tr[i].id.replace(element_id_prefix,'');
                    ids_array.push(id);}
            }
        }
    }
    return ids_array.join(',');
}

function is_except_deal(elements_tr_id,element_id_prefix,except_deals_ids){
    var result = false;
    var except_deals_ids_array = except_deals_ids.split(',');
    if(except_deals_ids_array.length > 0){
        for (var i=0;i<except_deals_ids_array.length;i=i+1){
            if(element_id_prefix+except_deals_ids_array[i] == elements_tr_id){result = true;}
        }
    }
    return result;
}

function hide_except_deals_for_wide_deals_panel(panel_id,element_id_prefix,except_deals_ids,deals_count){
    var element_div = $(panel_id);
    if(element_div != null && element_div != undefined){
        var elements_tr = element_div.getElementsByTagName('tr');
        if(elements_tr.length > 0){
            var show_deal_count = 0;
            for (var i=0;i<elements_tr.length;i=i+1){
                var is_except_deal_tag = is_except_deal(elements_tr[i].id,element_id_prefix,except_deals_ids);
                if (is_except_deal_tag == true || show_deal_count >= deals_count){elements_tr[i].style.display = 'none';}     
                else{show_deal_count = show_deal_count + 1;}              
            }
            if(show_deal_count == 0){Element.hide(panel_id);}
        }        
    }
}

function requestDataFromServer(url,deals_ad_modle){
    new Ajax.Request(url,{
        method:'get',
        onComplete:function(response){
            var response_json = (response.responseText == '' ? [] : response.responseText.evalJSON(true));
            deals_ad_modle.loadOuterDatas(response_json);
        },
        onLoading:function(){}
    });
}

function hide_compare_box_if_no_data_from_pg(box_id){
    var compare_box_pg = $(box_id);
    if(compare_box_pg != undefined || compare_box_pg != null){
        var table_objs = compare_box_pg.getElementsByTagName('table');
        if(table_objs != undefined || table_objs != null){
            var trs = table_objs[0].getElementsByTagName('tr');
            if(trs.length < 3){compare_box_pg.hide();}
        }
    }
}
//function hide_deals_for_wide_deals(element_id_prefix,except_deals_ids){
//    var except_deals_ids_array = except_deals_ids.split(',');
//    if(except_deals_ids_array.length > 0){
//        for(var i=0;i<except_deals_ids_array.length;i=i+1){
//            hide_one_deal_for_wide_deals(element_id_prefix,except_deals_ids_array[i]);}
//    }  
//}
//
//function hide_one_deal_for_wide_deals(element_id_prefix,deal_id){
//    if($(element_id_prefix+deal_id) != null){
//        Element.hide(element_id_prefix+deal_id);}
//}
//function hide_wide_deals_panel_if_hide_all_deals(panel_id){
//    var element_div = $(panel_id);
//    if(element_div != null && element_div != undefined){
//        var elements_tr = element_div.getElementsByTagName('tr');
//        if(elements_tr.length > 0){
//            var hide_tag = true;
//            for (var i=0;i<elements_tr.length;i=i+1){
//                if(elements_tr[i].style.display != 'none'){hide_tag = false;}
//            }
//            if(hide_tag == true){Element.hide(panel_id);}
//        }        
//    }
//}
    
//function update_compare_price_coupons_left_class(element_id,button_element_id){
//    if($(element_id).style.display != 'none'){
//        $(button_element_id).setAttribute('class','merchant merchant_open');
//        $(button_element_id).setAttribute('className','merchant merchant_open');
//    }
//    else{
//        $(button_element_id).setAttribute('class','merchant');
//        $(button_element_id).setAttribute('className','merchant');
//    }
//}

//function openDealOut(url,sName,sFeatures,bReplac){
//    var adPopup = window.open('about:blank',sName,sFeatures,bReplac);
//    adPopup.blur();
//    adPopup.opener.focus();
//    adPopup.location = url;
//}



//usefull_comments_coupon_ids = []
//nouse_comments_coupon_ids  = []
//function vote_coupon_comment(coupon_id,if_good){
//    $("comments" + coupon_id).hide();
//    if (if_good)
//    {
//        $("bad_comment" + coupon_id).hide();
//        if(usefull_comments_coupon_ids.indexOf(coupon_id) < 0){
//            $('goold_comment' + coupon_id).update($('coupon_comments_form').innerHTML);
//            _form = $('goold_comment' + coupon_id).getElementsByTagName('form')[0];
//            _form["coupon_id"].value = coupon_id;
//            _form["comment[comment_type]"].value = '1';
//            usefull_comments_coupon_ids.push(coupon_id);
//            new Ajax.Request("/submit_valid_vote?coupon_id=" +coupon_id);
//        }
//        var goole_span = $("votesgood"+coupon_id);
//        goole_span.innerHTML = (parseInt(goole_span.innerHTML) + 1)
//        $("goold_comment" + coupon_id).toggle();
//    }
//    else
//    {
//        $("goold_comment" + coupon_id).hide();
//        if(nouse_comments_coupon_ids.indexOf(coupon_id) < 0){
//            $('bad_comment' + coupon_id).update($('coupon_comments_form').innerHTML);
//            _form = $('bad_comment' + coupon_id).getElementsByTagName('form')[0];
//            _form["coupon_id"].value = coupon_id;
//            _form["comment[comment_type]"].value = '2';
//            nouse_comments_coupon_ids.push(coupon_id);
//            new Ajax.Request("/submit_invalid_vote?coupon_id=" +coupon_id);
//        }
//        var bad_span = $("votesbad"+coupon_id);
//        bad_span.innerHTML = (parseInt(bad_span.innerHTML)+1)
//        $("bad_comment" + coupon_id).toggle();
//    }
//    var comment_div = $("coupon_comments_div_" +coupon_id);
//    comment_div.setAttribute('class','bk16_N_r bk16_N_gray')
//    comment_div.setAttribute('className','bk16_N_r bk16_N_gray')
//    $("valid_vote_" + coupon_id).onclick = 'return false;'
//    $("invalid_vote_" + coupon_id).onclick = 'return false;'
//}

//request_comments_coupon_ids = []
//function request_coupon_comments(coupon_id){
//    if(request_comments_coupon_ids.indexOf(coupon_id) < 0){
//        new Ajax.Request("/coupon_comments/index?coupon_id=" +coupon_id,{
//            asynchronous:false,
//            evalScripts:true
//        });
//        request_comments_coupon_ids.push(coupon_id);
//        Element.show('comments'+coupon_id);
//    }else{
//        Element.toggle('comments'+coupon_id);
//    }
//    $("bad_comment" + coupon_id).hide();
//    $("goold_comment" + coupon_id).hide();
//    _form = $('comments' + coupon_id).getElementsByTagName('form')[0];
//    _form["coupon_id"].value = coupon_id;
//}