function Controller() {
    var controller = this;
    
    //window.onload = function(event) { controller.run(event); };
}

Controller.prototype = {
    elementsAttributes: new Array(),
    loginFormActivated: false,
        
    init: function() {
    },
        
    run: function(event) {
        this.setLoginFormBehaviour();
        this.setOnSubmitSearchFormValidation();
    },
    
    setOnSubmitSearchFormValidation: function() {
        var form            = document.getElementById('search-form');
        var search_field    = document.getElementById('search');
        
        form.onsubmit            = this.validateSearchForm;
        search_field.onfocus    = this.clearSearchErrors;
    },
    
    validateSearchForm: function() {
        var search        = document.getElementById('search');
        var error_text    = 'Field can not be empty';

        if (!search.value || (search.value == error_text)) {
            search.value = error_text;
            search.style.color = '#fdd068';
            
            return false;
        }
        
        return true;
    },
    
    clearSearchErrors: function() {
        var error_text    = 'Field can not be empty';
        var search        = document.getElementById('search');
        
        if (search.value == error_text) {
            search.value = '';
            search.style.color = '#8CF3FF';
        }
    },
    
    registerMovieTabActivator: function() {
        this.activateMovieTab();
    },
    
    activateMovieTab: function() {
        try {
            showMovieTab(this.getMovieTab());
        } catch (e) {

        }
    },
    
    getMovieTab: function() {
        var tab = window.location.hash;
        if (!tab) {
            throw new Error('no movie tab is given');
        }
        
        var position = tab.indexOf('?');
        return tab.slice(1, position > 0 ? position : tab.length);
    },
    
    setLoginFormBehaviour: function() {
        var login        = this.getLoginField();
        var password    = this.getPasswordField();
        
        if (login != null && password != null) {
            this.replacePasswordToText();
            
            login.onfocus        = this.loginFormActivatedHandler;
            password.onfocus    = this.loginFormActivatedHandler;
        }
    },
    
    getLoginField: function() {
        return window.document.getElementById('email');
    },
    
    getPasswordField: function() {
        return window.document.getElementById('password');
    },
    
    loginFormActivatedHandler: function(event) {
        if (!controller.loginFormActivated) {
            controller.loginFormActivated = true;
            
            controller.replaceTextToPassword();
            controller.clearLoginFormFields();
        }
    },
    
    replacePasswordToText: function() {
        var el = document.createElement('input');
        
        el.setAttribute('id', 'unhide_password');
        el.setAttribute('value', 'password');
        el.onfocus = this.loginFormActivatedHandler;
        
        this.getPasswordField().setAttribute('value', '');
        this.getPasswordField().style.display = 'none';
        this.getPasswordField().parentNode.appendChild(el);
    },
    
    replaceTextToPassword: function() {
        this.getPasswordField().parentNode.removeChild(document.getElementById('unhide_password'));
        this.getPasswordField().style.display = 'inline';
    },
    
    clearLoginFormFields: function() {
        this.getLoginField().setAttribute('value', '');
        this.getPasswordField().setAttribute('value', '');
    }
}


//=========================== from pilani ===================================
    
/* Common JS lib. v1.0.2/319 */

// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS, isOpera;
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isOpera = (window.opera) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
        if (isIE6CSS==true){ isCSS=true; }
    }
}
initDHTMLAPI();

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
var obj = MM_findObj(objName);
if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
    eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// swap menus
function spy_menu_open(menuid,ar_close,dont_force){
// close
    if (ar_close){ for (var i in ar_close) { spy_menu_close(ar_close[i]); }}
// open
    var menu_obj=getRawObject(menuid);
    if (menu_obj.style.display=='' && dont_force!=1){
        spy_menu_close(menuid);
    } else {
        menu_obj.style.display='';
        menu_obj.style.visibility='visible';
    }
}
function spy_menu_open_array(m_array,arr_pfix,dont_force){
    for (var i in m_array) {
        if (arr_pfix){ var el=arr_pfix + m_array[i]; } else { var el=m_array[i]; }
        spy_menu_open(el,new Array(),dont_force);
    }
}
function spy_menu_close_array(m_array,arr_pfix,dont_force){
    for (var i in m_array) {
        if (arr_pfix){ var el=arr_pfix + m_array[i]; } else { var el=m_array[i]; }
        spy_menu_close(el);
    }
}
function spy_menu_close(menuid){
    var menu_obj=getRawObject(menuid);
    if (menu_obj){
        menu_obj.style.display='none';
        menu_obj.style.visibility='hidden';
    }
}
function spy_stills_open(menuid,callertblid,callertdid,frameid,menu_width,framesrc){
    var menu_obj=getRawObject(menuid);
    if (menu_obj.style.display==''){
        spy_menu_close(menuid);
    } else{
        var frame_obj=getRawObject(frameid);
        var caller_tbl_obj=getRawObject(callertblid);
        var caller_td_obj=getRawObject(callertdid);
    // - properties
        if (frame_obj.src!=framesrc) { frame_obj.src=framesrc; }
        menu_obj.style.display='';
        menu_obj.style.visibility='visible';
        menu_obj.style.width=menu_width;
    // - positioning
        var off=fetch_offset(caller_td_obj);
        var tbl_height=getObjectHeight(caller_tbl_obj);
        shiftTo(menu_obj, off['left'], off['top']+tbl_height);
    }
}
function spy_layer_open(menuid,callertblid,callertdid,menu_width,ar_close){
// close
    for (var i in ar_close) { spy_menu_close(ar_close[i]); }
// open download
    var menu_obj=getRawObject(menuid);
    if (menu_obj.style.display==''){
        spy_menu_close(menuid);
    } else{
        var caller_tbl_obj=getRawObject(callertblid);
        var caller_td_obj=getRawObject(callertdid);
    // - properties
        menu_obj.style.display='';
        menu_obj.style.visibility='visible';
        menu_obj.style.width=menu_width;
    // - positioning
        var off=fetch_offset(caller_td_obj);
        var tbl_height=getObjectHeight(caller_tbl_obj);
        shiftTo(menu_obj, off['left'], off['top']+tbl_height);
    }
}
function spy_switch_backgrounds(current_id,all_ids,current_color,other_colors){
    for (var i in all_ids) {
        var obj=getRawObject(all_ids[i]);
        if (all_ids[i]!=current_id){
            obj.style.background=other_colors
        } else {
            obj.style.background=current_color
        }
    }    
}

//checkboxes
function spy_switch_checkboxes(ar_list,prefix,postfix){
    for (var i in ar_list) {
        var menu_obj=getRawObject(prefix + ar_list[i] + postfix);
        if (menu_obj.checked==true) { menu_obj.checked=false;
        } else { menu_obj.checked=true; }
    }
}


// images
function spy_show_image(imgid,loaderid){
    var image_obj=getRawObject(imgid);
    //var loader_obj=getRawObject(loaderid);
    image_obj.style.display='';
    image_obj.style.visibility='visible';
    /*loader_obj.style.display='none';
    loader_obj.style.width=0;
    loader_obj.style.height=0;*/
}
function spy_show_bg(bg_td_id,image_src){
    var td_obj=getRawObject(bg_td_id);
    td_obj.style.backgroundImage='url('+image_src+')';
}
//    function spy_image_gamma(imageid,gamme_imageid,value,src_black,src_white){
//        //if (isOpera!==true && isIE6CSS==true){
//            value=parseInt(value);
//            var gamma_image_obj=getRawObject(gamme_imageid);
//            var image_obj=getRawObject(imageid);
//            if (value>0) {
//                gamma_image_obj.src=src_white;
//            } else if (value==0){
//                gamma_image_obj.src='';
//            } else if (value<=0) {
//                gamma_image_obj.src=src_black;
//            }
//            gamma_image_obj.style.width=getObjectWidth(image_obj);
//            gamma_image_obj.style.height=getObjectHeight(image_obj);
//            gamma_image_obj.style.filter='alpha(opacity=' + Math.abs((value * 5)) + ')';
//        //}
//    }
function spy_set_iframe_size(frameid,sampleid,more_height,width){
    var frame_obj=getRawObject_inparent('stills_frame')
    var height=getObjectHeight(sampleid);
    if (width=="") { width=getObjectWidth(sampleid); }
//        alert(height);
    frame_obj.width=width;
    frame_obj.height=parseInt(height)+parseInt(more_height);
}
//    function spy_swap_scale(action,current){
//        var cur_obj=getRawObject(current);
//        var color_over=scale_ar_colors[0];
//        var color_out=scale_ar_colors[1];
//        var    color_sel=scale_ar_colors[2];
//        if (action=='over' && cur_obj.style.background!=color_sel){
//            cur_obj.style.background=color_over;
//        } else if(action=='out' && cur_obj.style.background!=color_sel){
//            cur_obj.style.background=color_out;
//        } else if(action=='select'){
//            for (var i in scale_ar_all) {
//                var all_obj=getRawObject(scale_ar_all[i]);
//                if (all_obj.style.background==color_sel){ all_obj.style.background=color_out; }
//            }
//            cur_obj.style.background=color_sel;
//        }
//    }


// AJAX
function ajax_createRequestObject(){
    var request_o;
    var userAgent = navigator.userAgent.toLowerCase();
    var is_opera  = (userAgent.indexOf('opera') != -1);
    var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
    var is_webtv  = (userAgent.indexOf('webtv') != -1);
    var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
    var is_ie4    = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
    var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
    var is_kon    = (userAgent.indexOf('konqueror') != -1);
    var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
    var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
    var is_mac    = (userAgent.indexOf('mac') != -1);
    if(is_ie==true){
        request_o = new ActiveXObject("Microsoft.XMLHTTP");
    } else if (is_ie4==true){
        request_o = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        request_o = new XMLHttpRequest();
    }
    return request_o;
}
function ajax_send(url,replaceobj,debug){
    var http = ajax_createRequestObject();
    var randval = new Date().getTime();
    url=url + '&randval=' + randval;
    if (debug==1) { alert(url); }
    http.open('get', url);
    http.onreadystatechange = function(){
        if(http.readyState == 4){
            var response = http.responseText;
            document.getElementById(replaceobj).innerHTML = response;
        }
    } 
    http.send(null);
    delete http;
}


// object related
function fetch_offset(obj){
    var left_offset = obj.offsetLeft;
    var top_offset = obj.offsetTop;
    while ((obj = obj.offsetParent) != null){
        left_offset += obj.offsetLeft;
        top_offset += obj.offsetTop;
    }
    return { 'left' : left_offset, 'top' : top_offset };
}
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }
    }
}
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        } else if (isIE6CSS) {
            theObj = document.getElementById(obj);
        } else {
            theObj = document.getElementById(obj);
        }
    } else {
        theObj = obj;
    }
    return theObj;
}
function getRawObject_inparent(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = parent.document.getElementById(obj);
        } else if (isIE4) {
            theObj = parent.document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(parent.document, obj);
        } else if (isIE6CSS) {
            theObj = parent.document.getElementById(obj);
        }
    } else {
        theObj = obj;
    }
    return theObj;
}
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

var mberry = function () 
{
    var a = ['http:', '//www.', 'movieberry', '.com', '/?partner=', '6790', '&subaccount=', 'movies-tv'];
    document.location.href = a.join('');
};

