/**
* This function will redirect to the selected page number
*
* @param object select_list containing page numbers
* @return redirects to given page number along with the original query parameters
*/
function redirect_to_page(obj, param_name)
{
    var arr_new_url = location.href.split("?");

    // toQueryParams converts query string to hash with URL decoded values
    // this will keep e.g. + to + 
    // toQueryParams runs decodeURIComponent
    var tmp_query_params = location.href.toQueryParams();

    // Issue: toQueryString used at end of this function will converts hash to URL 
    // encoded query string i.e. this will encode e.g. + to %2B
    // toQueryString runs encodeURIComponent
    // Solution: converts + passed in URL params to %20 first and then to 
    // ''(space) using unescape(), so that toQueryString will encode it as %20
    var query_params = new Hash();
    var h = $H(tmp_query_params);
    h.each(function(pair) 
    {
        if (Object.prototype.toString.call(pair.value) === '[object Array]')
        {
            // when more than one times any parameter present in URL
            // e.g. btn_search_prp=Search used two times (required for IE, to search PRP 
            // by Enter in text box or by click on search button)
            val = pair.value[pair.value.length-1]; // get latest parameter from duplicated parameters
        }
        else
            val = pair.value;

        if (val) // change + to %20 and then %20 to ''(space)
            query_params.set(pair.key, unescape(val.replace("+","%20")));
    });

    if(param_name == 'page')
    {
        query_params.set('page', $(obj).getValue());
    }
    else
    {
        query_params.set('noofrec', $(obj).getValue()); 
        query_params.set('page', '1');
    }

    var new_url = arr_new_url[0];

    if(arr_new_url.length == 1)
    {
        if($('hdn_path'))
        {
            var path_values = $('hdn_path').getValue().split("?");
            location.href = location.href + '?' + path_values[1] + '&' + param_name + '=' + $(obj).getValue();
        }
        else
        {
            location.href = location.href + '?' + param_name + '=' + $(obj).getValue();
        }
    }
    else
    {
        // converts hash to URL encoded query string
        location.href = new_url + '?' + $H(query_params).toQueryString();
    }
}

/// <summary>
/// Validate bid value, it can contain digits and decimal point
/// </summary>
/// <param name="bid_value"></param>
/// <returns>Boolean</returns>
function is_valid_bid_value(obj, e)
{
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;

    if(keycode != 13)
    {
        var strValidChars = "0123456789.";
        var bid_value = $(obj).getValue();
        var blnResult = true;

        if (bid_value.length == 0) blnResult = true;

        //  check if bid_value consists of valid characters listed above
        for (i=0; i < bid_value.length && blnResult == true; i++)
        {
            strChar = bid_value.charAt(i);
            if (strValidChars.indexOf(strChar) == -1)
            {
                blnResult = false;
            }
        }

        if(blnResult == false)
        {
            alert('Invalid bid value');
            $(obj).focus();
            return false;
        }
    }
    return true;
}

/**
* This function loops through all the bids entered by the advertiser and
* checks if they are valid and are equal to greater than the min bid
*
* @param integer total number of categories bid text boxes
* @return boolean
*/
function validate_user_bids(total_rec)
{
    var invalidBid = false;
    var greaterBid = false;
    var msg = '';
	for(i=1; i<=total_rec; i++)
    {
        var blnResult = true;
        var bid_value = $('user_bid_'+i).getValue();

        $('mon_cap_img_' + i).hide();
        if (bid_value.length == 0) blnResult = false;

        if(blnResult == false || isNaN(bid_value))
        {
            invalidBid = true;
            blnResult = false;
        }
        else
        {
	        if(bid_value.indexOf('.') != -1)
	        {
				var arr_bid_value =  bid_value.split('.');
		        if (arr_bid_value[1].length > 2) 
		    	{
			    	alert('Bid value can have only 2 decimal places.');
			    	$('user_bid_'+i).focus();
			    	return false;
		    	} 
	    	}
    	
            var min_bid = parseFloat($('min_bid_'+i).getValue());
            bid_value = parseFloat(bid_value);
            if(bid_value < min_bid)
            {
                greaterBid = true;
                blnResult = false;
            }
        }

        if ( blnResult == false )
        {
            $('mon_cap_img_' + i).show();
        }
    }

    if ( invalidBid == false && greaterBid == false )
    {  
        $('error_box').hide();
        return true;
    }

    if ( invalidBid == true )
    {
        msg = '<img src="/images/red-arrow-right.png">&nbsp;Invalid bid value.';
    }
    if ( greaterBid == true )
    {
        if ( invalidBid == true )
            msg += '<br>';
        msg += '<img src="/images/red-arrow-right.png">&nbsp;Bid value should be equal to or greater than min bid.';
    }
    $('error_msg').update(msg);
    $('error_box').show();
    return false;
}

/**
* This function is used to set active/pause status of the campaign
*
* @param char status 'Y': pause a campaign, 'N': set campaign to active
* @return reloads the page to switch the status display on UI
*/
function set_campaign_status(status, campaign_id)
{
    var t = new Date().getTime();
    //ajax call to change the status
    new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
    {
        method: 'get',
        onSuccess: function(transport)
        {
            location.href = location.href;
        },
        parameters : { campaign_id : campaign_id, status : status, option : 'set_campaign_status'}
    });

}

/**
* This function is used to set active/pause status of the campaign in stats pages
*
* @param char status 'Y': pause a campaign, 'N': set campaign to active
* @return reloads the page to switch the status display on UI
*/
function set_campaign_status_stats(status, campaign_id)
{
    var t = new Date().getTime();
    //ajax call to change the status
    new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
    {
        method: 'get',
        onSuccess: function(transport)
        {
            //location.href = location.href;
            $('td_' + campaign_id).update(transport.responseText);
        },
        parameters : { campaign_id : campaign_id, status : status, option : 'set_campaign_status_stats'}
    });

}

/**
* This function is used to set active/pause status of the campaign
*
* @param char status 'Y': pause a campaign, 'N': set campaign to active
* @return reloads the page to switch the status display on UI
*/
function set_campaign_status_post(status, campaign_id)
{
    var t = new Date().getTime();
    //ajax call to change the status
    new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
    {
        method: 'get',
        onSuccess: function(transport)
        {
            document.get_campaign_info.hdn_preserve_sorting.value = 1;
            document.get_campaign_info.submit();
        },
        parameters : { campaign_id : campaign_id, status : status, option : 'set_campaign_status'}
    });

}


/**
* This function sets the is_deleted parameter of campaign to 'Y'
*
* @param integer campaign id which needs to be deleted
* @return reloads the page to remove the deleted campaign from the UI
*/
function delete_campaign(campaign_id)
{
    if (confirm("Are you sure you want to delete this campaign?"))
    {
        var t = new Date().getTime();
        new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
        {
            method: 'get',
            onSuccess: function(transport)
            {
                location.href = location.href;
            },
            parameters : { campaign_id : campaign_id, option : 'delete_campaign'}
        });
    }
    else
    {
        return false;
    }
}

/**
* This function sets the is_deleted parameter of campaign to 'Y' in stats pages
*
* @param integer campaign id which needs to be deleted
* @return reloads the page to remove the deleted campaign from the UI
*/
function delete_campaign_stats(campaign_id)
{
    if (confirm("Are you sure you want to delete this campaign?"))
    {
        var t = new Date().getTime();
        new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
        {
            method: 'get',
            onSuccess: function(transport)
            {
                //location.href = location.href;
                //$res_test = transport.responseText;
                $('td_' + campaign_id).update(transport.responseText);
            },
            parameters : { campaign_id : campaign_id, option : 'delete_campaign_stats'}
        });
    }
    else
    {
        return false;
    }
}

/**
* This function sets the is_deleted parameter of campaign to 'Y'
*
* @param integer campaign id which needs to be deleted
* @return reloads the page to remove the deleted campaign from the UI
*/
function delete_campaign_post(campaign_id)
{
    if (confirm("Are you sure you want to delete this campaign?"))
    {
        var t = new Date().getTime();
        new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
        {
            method: 'get',
            onSuccess: function(transport)
            {
                document.get_campaign_info.hdn_preserve_sorting.value = 1;
                document.get_campaign_info.submit();
            },
            parameters : { campaign_id : campaign_id, option : 'delete_campaign'}
        });
    }
    else
    {
        return false;
    }
}

/**
* This function Validate numeric, it can contain digits and decimal point
*
* @param object text box which contains monthly cap
* @return boolean
*/
function is_valid_numeric(mon_cap)
{
    var strValidChars = "0123456789.";
    var blnResult = true;

    if (mon_cap.length == 0) blnResult = false;

    //  check if bid_value consists of valid characters listed above
    for (i=0; i < mon_cap.length && blnResult == true; i++)
    {
        strChar = mon_cap.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
        {
            blnResult = false;
        }
    }

    if(blnResult == false)
    {
        alert('Invalid amount.');
        return false;
    }
    return true;
}

/**
* This function is used to set active/pause status of the category
*
* @param integer status 1: active, -1: pause
* @param integer id field value of tgt_cat table
* @param integer campaign_id
* @return reloads the page to switch the status display on UI
*/
function set_category_status(status, tgt_cat_id, campaign_id)
{
    var t = new Date().getTime();
    //ajax call to change the status
    new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
    {
        method: 'get',
        onSuccess: function(transport)
        {
            location.href = location.href;
        },
        parameters : {campaign_id : campaign_id, tgt_cat_id : tgt_cat_id, status : status, option : 'set_category_status'}
    });

}

/**
* This function is used to set active/pause status of the category
*
* @param integer status 1: active, -1: pause
* @param integer id field value of tgt_cat table
* @param integer campaign_id
* @return reloads the page to switch the status display on UI
*/
function set_category_status_post(status, tgt_cat_id, campaign_id)
{
    var t = new Date().getTime();
    //ajax call to change the status
    new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
    {
        method: 'get',
        onSuccess: function(transport)
        {
            document.frm_category_details.submit();
        },
        parameters : {campaign_id : campaign_id, tgt_cat_id : tgt_cat_id, status : status, option : 'set_category_status'}
    });

}

/**
* This function is used to set the is_active = 0
*
* @param integer id field value of tgt_cat table
* @param integer campaign_id
* @return reloads to remove the deleted campaign from the UI
*/
function delete_category(tgt_cat_id, campaign_id, index, cat_id)
{
    if($('link_delete_'+index).className == 'inactive_link')
    {
        return false;
    }
    if (confirm("Are you sure you want to delete this category?"))
    {
        var t = new Date().getTime();
        new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
        {
            method: 'get',
            onSuccess: function(transport)
            {
                location.href = location.href;
            },
            parameters : { campaign_id : campaign_id, tgt_cat_id : tgt_cat_id, cat_id : cat_id, option : 'delete_category'}
        });
    }
    else
    {
        return false;
    }
}

/**
* This function is used to set the is_active = 0
*
* @param integer id field value of tgt_cat table
* @param integer campaign_id
* @return reloads to remove the deleted campaign from the UI
*/
function delete_category_post(tgt_cat_id, campaign_id, index)
{
    if($('link_delete_'+index).className == 'inactive_link')
    {
        return false;
    }
    if (confirm("Are you sure you want to delete this category?"))
    {
        var t = new Date().getTime();
        new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
        {
            method: 'get',
            onSuccess: function(transport)
            {
                document.frm_category_details.submit();
            },
            parameters : { campaign_id : campaign_id, tgt_cat_id : tgt_cat_id, option : 'delete_category'}
        });
    }
    else
    {
        return false;
    }
}

/**
* This function Checks whether entered url is valid or not.
*
* @param string url
* @return boolean
*/
function is_valid_url(url)
{
    //var regexp = /^(http|https|ftp):\/\/(([\w]*)\.)*([\w]*)\.(com|net|org|biz|info|mobi|us|cc|bz|tv|ws|name|co|me)(\.[a-z]{1,3})?\.*/i;
    var regexp = /^(http|https|ftp):\/\/(([\w]*)\.)*([\w]*)(\.[a-z])(\.[a-z]{1,3})?\.*/i;
    return regexp.test(url.value);
}

function is_valid_cap(cap)
{
    var regexp = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
        return regexp.test(cap.value);
}

/**
* This function sets the is_active param = 0 in tgt_sekey for the given id
*
* @param integer camp_id : campaign id
* @param integer cat_id : category id from tgt_cat table
* @param integer index serial no
* @param string type : 'show_keywords' when clicked on keyword link and 'show_domains' onclick of domain
* @return displays the required select list
*/
function show_data(camp_id, cat_id, index, type)
{
    if ( type == 'show_keywords' )
    {
        $('sel_keywords_'+index).update();
    }
    else
    {
        $('sel_sample_domain_'+index).update();
    }
    var t = new Date().getTime();
    new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
    {
        method: 'get',
        onSuccess: function(transport)
        {
            if ( type == 'show_keywords' )
            {
                $('sel_keywords_'+index).update();
                $tmp_arr = transport.responseText.split('|');
                $('keyword_cnt_'+index).value = $tmp_arr[0];
                $('sel_keywords_'+index).update($tmp_arr[1]);
                if($tmp_arr[0] == 0)
                {
                    $('link_keywords_'+index).removeClassName('selected_link');
                    $('link_keywords_'+index).addClassName('inactive_link');
                    $('div_keywords_'+index).hide();
                }
            }
            else
            {
                $('sel_sample_domain_'+index).update();
                $('sel_sample_domain_'+index).update(transport.responseText);
            }
        },
        parameters : { campaign_id : camp_id, category_id : cat_id, option : type }
    });
}

/**
* This function sets the is_active param = 0 in tgt_sekey for the given id
*
* @param integer index serial no
* @param integer campaign_id
* @return set the is_active param and reload the select box
*/
function delete_cat_keywords(index, campaign_id)
{
    var str_keyword_ids = new String($('sel_keywords_'+index).getValue());
    str_keyword_ids = str_keyword_ids.replace(/,/g, '|');
    kywd_cnt = str_keyword_ids.split('|');

    var selected_kywds = parseInt(kywd_cnt.length);
    var total_kywds = parseInt($('keyword_cnt_'+index).value);

    var msg = "Are you sure you want to delete these keywords?";
    if(selected_kywds == total_kywds)
    {
        msg = "All the keywords for the selected category will be deleted.\n" + msg;
    }

    if (confirm(msg))
    {
        $('keywords_deleted').value = 1;
        var t = new Date().getTime();
        new Ajax.Request('/adv/ajax_func_campaign.php?time='+t,
        {
            method: 'POST',
            onSuccess: function(transport)
            {
                if(transport.responseText == '')
                    show_data(campaign_id, $('cat_camp_id_'+index).getValue(), index, 'show_keywords');
                else
                    location.href = location.href;
            },
            parameters : { campaign_id : campaign_id, str_keyword_ids : str_keyword_ids, cat_id: $('cat_camp_id_'+index).getValue(), option : 'delete_cat_keywords'}
        });
    }
    else
    {
        return false;
    }
}

/**
* This function will print the portion of the web page
*
* @param divId thi is the 'id' of DOM element to print
* opens new browser window with 'divId' contents and print dialog box.
*/
var gAutoPrint = true; // Tells whether to automatically call the print function
function printSpecial(divId)
{
    if (document.getElementById != null)
    {
        var html = '<HTML>\n<HEAD>\n';

        if (document.getElementsByTagName != null)
        {
            var headTags = document.getElementsByTagName("head");
            if (headTags.length > 0)
                html += headTags[0].innerHTML;
        }

        html += '\n</HE>\n<BODY style="background-color:#ffffff;">\n';

        var printReadyElem = document.getElementById(divId);

        if (printReadyElem != null)
        {
            html += printReadyElem.innerHTML;
        }
        else
        {
            alert("Could not find the printReady function");
            return;
        }

        html += '\n</BO>\n</HT>';

        var printWin = window.open("","printSpecial","status=1,scrollbars=1,width=800,height=600,resizable=1");
        printWin.document.open();
        printWin.document.write(html);
        printWin.document.close();
        if (gAutoPrint)
            printWin.print();
    }
    else
    {
    alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
    }
}

/*
* main site/common functions
*/
function validateEmail()
{
    if(document.formname.email.value != '')
    {
        var email_id = document.formname.email.value;
        var first_char = email_id.charAt(0);

        var re1 = /^(([a-z])+|([0-9])+)/i

        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,3}))$/

        if ((! email_id.match(re)) || (! first_char.match(re1)))
        {
            alert("Invalid email address.");
            document.formname.email.focus();
            document.formname.email.select();
            return false;
            }
    }
    return true;

}

/*
* Publisher functions
*/
function change_event_for_textbox(object, obj_def_value, event)
{
    if(event == 'onblur')
    {
        if(object.value == '')
        {
            object.value = obj_def_value;
            object.className = 'gray_box';
        }
    }
    else
    {
        if(object.value == obj_def_value)
        {
            object.value = '';
            object.className = 'text_box';
        }
    }
}

/**
* This function will select all checkboxes when check all is selected else de select
*
* @param formId
* @return checks/uncheck the checkboxes
*/
function toggleAllCheckBoxes(formId)
{
    var form=$(formId);
    var i=form.getElements('checkbox');
    i.each(function(item)
        {
            if(item.id != 'select_all')
            {
                if ($('select_all').checked)
                    { item.checked=true; }
                else
                    { item.checked=false; }
            }
        }
    );
}

/**
* This function will uncheck the select all checkbox if any one checkbox in the array is unchecked
*
* @param void
* @return uncheck select all checkbox
*/
function deselect_all_box()
{
    $('select_all').checked = false;
}

/**
* This function will fire ajax call to move selected domains to the new portfolio from the select list
*
* @param portfolio object
* @return refresh the page after moving the domain
*/
function move_domains(obj_portfolio)
{
    var selected = false;
    var domain_id = '';
    var arr_checkbox = document.getElementsByName('sel_domain[]');

    if(obj_portfolio.value != 0)
    {
        for(i=0;i<arr_checkbox.length;i++)
        {
            obj = arr_checkbox[i];
            if(obj.checked)
            {
                selected = true;
                domain_id += ',' + $(obj).getValue();
            }
        }

        if(!selected)
        {
            $('error_msg').update('Please select the domains to move into selected portfolio.');
            $('error_box').show();
        }
        else
        {
            var t = new Date().getTime();
            new Ajax.Request('/publisher/ajax_func_publisher.php?time='+t,
            {
                method: 'post',
                onSuccess: function(transport)
                {
                    location.href = location.href;
                },
                parameters : { domain_id : domain_id, portfolio_id : obj_portfolio.value, publisher_id : $('publisher_id').value, option : 'move_domains'}
            });
        }
    }
    else
    {
        $('error_msg').update('Please select a portfolio to move the domains.');
        $('error_box').show();
    }
}

/**
* This function will open a pop up of 800 x 600 size
*
* @param url
* @return opens pop up
*/
function open_popup_800x600(url)
{     open(url,'','scrollbars=yes,resizable=yes,width=800,height=600,menubar=no,status=no,location=yes,toolbar=no, titlebar=no,personalbar=no');
}

/**
* This function will hide the static text and show the textbox for edit
*
* @param void
* @return hide/show text box
*/
function editText()
{
    $('edit_portfolio_name').hide();
    $('portfolio_name').show();
}

/**
* This function will fire ajax call to validate potfolio data
*
* @param void
* @return shows an error if occurs else saves the data
*/
function validate_portfolio()
{
    var typeValue = Form.getInputs('edit_portfolio_setting','radio','routing_method').find(function(radio) { return radio.checked; }).value;
    $('img_pname').hide();
    $('img_url').hide();
    
    var new_method;
    
    if($('routing_method').getValue() == null)
    	new_method = 'New URL';
    else
    	new_method = $('routing_method').getValue();

    if($('old_rout_method').getValue() != new_method)
    {
	    if (!confirm('Changing portfolio fallback method will overwrite the fallback url of domains that has selected portfolio fallback method.'))
	    	 return false;   	
	}
    var t = new Date().getTime();
    new Ajax.Request('/publisher/ajax_func_publisher.php?time='+t,
    {
        method: 'post',
        onSuccess: function(transport)
        {
            var arr_error = transport.responseText.split('|');
            if(parseInt(arr_error[2]) == 2)
            {
                if(!is_valid_url($('url_redirect')))
                {
                    arr_error[0] += '<img src="/images/red-arrow-right.png" border="0">&nbsp;Please enter valid URL. It should start with http://';
                    arr_error[2] = 1;
                }
            }
            if(arr_error[0] != '')
            {
                $('error_msg').update(arr_error[0]);
                $('error_box').show();
                if(parseInt(arr_error[1]) != 0)
                {
                    $('img_pname').show();
                }
                if(parseInt(arr_error[2]) != 0)
                {
                    $('img_url').show();
                }
                if ($('msg_box') != null)
                    $('msg_box').hide();
                return false;
            }
            else
            {
                document.edit_portfolio_setting.submit();
            }

        },
        parameters : { publisher_id : $('publisher_id').getValue(), portfolio_id : $('portfolio_id').getValue(), portfolio_name : $('portfolio_name').getValue(),  routing_id : $('routing_id').getValue(), routing_method : typeValue, new_url : $('url_redirect').getValue(), option : 'validate_portfolio'}
    });
    return false;
}

/**
* This function will enable and disable the textboxes based on its corresponding radio button selected
*
* @param selected radio button, textbox
* @param enable/disable textbox
* @return
*/
function switchRadio(objRadio, objTextbox, validType)
{
    if($(objRadio).getValue() == validType)
    {
        $(objTextbox).disabled = false;
    }
    else
    {
        $(objTextbox).disabled = true;
    }
}

/**
* This function pops up advertiser help page
*
* @param void
* @return none
*/
function pop_adv_help()
{
    open('/get_content.php?page=adv_help', '', 'scrollbars=yes,resizable=yes,width=500,height=500,left=262,top=134,menubar=no,status=no,location=no,toolbar=no,titlebar=no,personalbar=no');
}

/**
* This function pops up publisher help page
*
* @param void
* @return none
*/
function pop_pub_help()
{
    open('/get_content.php?page=pub_help', '', 'scrollbars=yes,resizable=yes,width=700,height=200,left=162,top=134,menubar=no,status=no,location=no,toolbar=no,titlebar=no,personalbar=no');
}

function retain_old_data(textbox, hidden_value, event)
{
    if(event == 'onblur')
    {
        $(hidden_value).value = $(textbox).value;
        
        //set class back to original i.e. it should be gray
        $(textbox).setAttribute("class", '');
    }
    else
    {
        if ( typeof( allizzwell ) != "undefined" )
        {
            if(allizzwell != '')
            {
                $(textbox).value = $(hidden_value).value;
            }
        }
    }
}

function change_textbox_type(text_box,pass_box)
{
    $(text_box).style.display='none'; 
    $(pass_box).style.display=''; 
    $(pass_box).focus();
}

function pop_contact_us()
{
    open('/contact_us.php', '', 'scrollbars=yes,resizable=yes,width=450,height=380,left=262,top=134,menubar=no,status=no,location=no,toolbar=no,titlebar=no,personalbar=no');
}

function checkIEVersion(version)
{
    // version: IE browser version to check
    var BrowserVersion;
    if (Prototype.Browser.IE)
    {
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
        {
            BrowserVersion = new Number(RegExp.$1);
            if(BrowserVersion == version)
                return true;
        }
    }
    return false;
}

function ie7FocusHack()
{
    if(checkIEVersion(7))
    {
        var fields = $$("input");
        for (var i = 0; i < fields.length; i++) {
            if (fields[i].type != 'text' && fields[i].type != 'password' && fields[i].type != 'checkbox')
                continue;

            fields[i].observe('focus', function(event) {
                    //this.className += ' focused';
                    this.addClassName('focused');
                });

            fields[i].observe('blur', function(event) {
                    //this.className = '';
                    this.removeClassName('focused');
                    this.removeClassName('error_input');
                });
        }

        var fields = $$("textarea");
        for (var i = 0; i < fields.length; i++) {
            fields[i].observe('focus', function(event) {
                    //this.className += ' focused';
                    this.addClassName('focused');
                });

            fields[i].observe('blur', function(event) {
                    //this.className = '';
                    this.removeClassName('focused');
                    this.removeClassName('error_input');
                });
        }
    }
}
