if (typeof MD=="undefined") {var MD=new Object();}

MD = Class.create();

MD.confirm = function(msg){
    try{
        return !confirm(msg)?false:true;
    }catch(e){
        return false;
    }
}

MD.notEmpty = function(id){
    if($F(id).strip().empty()){
        return false;
    }
    return true;
}

MD.validate_string = function(v){
    return /^[a-zA-Z0-9_]{5,15}$/.test(v);
}

MD.location = function(l){
    if(!l){return false;}
    window.location.href = l.replace(/&amp;/g, '&');
    return false;
}


MD.preview = function(cid,w,h,p){
    w = parseInt(w);
    h = parseInt(h);
    if(!p){
        var url = MD.domain+'previews/'+cid+'.flv';
    }else{
        var file = cid.split('.');
        var url = MD.domain+'showcase_previews/'+file[0];
        cid = null;
        cid = file[0];
    }

    if(!w){w = 238}
    if(!h){h=178}
    if(/\d/.test(w) && /\d/.test(h) && /^[a-zA-Z0-9_]{1,}$/i.test(cid))
    {
        if (p)
        {
            var content = AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width',w,'height',h,'title',cid,'src',url,'quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie',url,'flag',1 );
            var html = '<div id="mgt" style="min-width:238px; overflow:hidden; border:0px; padding:0px;">'
            +content
            +'</div>'
            +'<noscript>'
            +'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase='
            +'"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0"'
            +'width="'+w+'" height="'+h+'" title="'+cid+'">'
            +'<param name="movie" value="'+url+'" />'
            +'<param name="quality" value="high" />'
            +'<embed src="'+url+'" quality="high" pluginspage='
            +'"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"'
            +'type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed>'
            +'</object>'
            +'</noscript>';
        }
        else
        {
            var html =
                '<div id="mgt" style="min-width:238px; overflow:hidden; border:0px; padding:0px;">' +
                '<embed width="326" height="178" flashvars="&file='+url+'&controlbar=none&autostart=true&displayclick=none&repeat=always" allowfullscreen="true" allowscriptaccess="always" quality="high" name="mpl" id="mpl" style="" src="/player-licensed.swf" type="application/x-shockwave-flash"/>' +
                '</div>';
        }

        return html;
    }

    return false;
}

function showtrail(imagename,type,title,width,height,catid,copyright,format){
    if(type == 'video') {
        if(width <= 0) {
            width = 266;
        }
        if(height > 0) {
            var factor = width / 266;
            if(factor != 0) {
                var new_height = height / factor;
                if(new_height > 100) {
                    height = new_height;
                }
                else {
                    height = 150;
                }
            }
            else {
                width = 266;
                height = 150;
            }
        }
        else {
            height = 150;
        }
        width = 266;
    }

    if (height > 0){
        currentimageheight = height;
    }


    document.onmousemove=followmouse;

    var newHTML = '<table border="0" width="240" cellpadding="3" cellspacing="3" bgcolor="#666666">';
  newHTML = newHTML + '<tr><td width="100%" valign="top">';
      newHTML = newHTML + '<table class="thin" width="222">';
        newHTML = newHTML + '<tr><td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">';
              newHTML = newHTML + '<tr><td width="100%"><p align="center">';

                if(type=='photo')
                newHTML = newHTML + '<div align="center" style="padding: 0px 0px 0px 0px;"><img src="' + imagename + '" border="0"></div>';
                if(type=='video') {
                        temp = '<div align="center" style="padding: 0px 0px 0px 0px; background-color: black;">'
                                 +'     <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" id="434_player" align="middle">'
                                 +'     <param name="allowScriptAccess" value="sameDomain" />'
                                 +'     <param name="movie" value="playerS.swf" />'
                                 +'     <param name="quality" value="high" />'
                                 +'     <param name="bgcolor" value="#000000" />'
                                 +' <param name="FlashVars" value="path='+imagename+'" /> '
                                 +'     <embed FlashVars="path='+imagename+'" src="playerS.swf" quality="high" bgcolor="#000000" width="'+width+'" height="'+height+'" name="player" align="middle"allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
                                 +'     </object>'
                                 +'</div>';

                   newHTML += temp;

newHTML = newHTML + '</td></tr><tr><td width="100%" bgcolor="#FFFFFF">';
                  newHTML = newHTML + '<table border="0" width="100%" cellpadding="2"><tr>';
                      newHTML = newHTML + '<td width="100%"><font face="Tahoma" size="1">'+title+'</font>';
                      newHTML = newHTML + '<br><font face="Tahoma" size="1">&#169;' +copyright+ '</font></td></tr>';
                  newHTML = newHTML + '</table></td></tr>';
            newHTML = newHTML + '</table></td></tr></table></td></tr>';
  newHTML = newHTML + '<tr><td width="100%" valign="top"><font face="Tahoma" size="1" color="#FFFFFF">Stock Footage<br> Native Resolution: '+format+'</font></td>';
  newHTML = newHTML + '</tr></table>';



                }

                if(type=='audio') {
                        temp = '<div align="center" style="padding: 0px 0px 0px 0px; background-color: white;">'
                                 +'     <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="0" height="0" id="434_player" align="middle">'
                                 +'     <param name="allowScriptAccess" value="sameDomain" />'
                                 +'     <param name="movie" value="playerA.swf" />'
                                 +'     <param name="quality" value="high" />'
                                 +'     <param name="bgcolor" value="#000000" />'
                                 +' <param name="FlashVars" value="file='+imagename+'" /> '
                                 +'     <embed FlashVars="file='+imagename+'" src="playerA.swf" quality="high" bgcolor="#000000" width="0" height="0" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
                                 +'     </object>'
                                 +'</div>';

                   newHTML += temp;

newHTML = newHTML + '<img src="http://lvs.revostock.com/themes/indiefootage/images/' + catid + 'medium.jpg" width="266">';
    newHTML = newHTML + '</td></tr><tr><td width="100%" bgcolor="#FFFFFF">';
                  newHTML = newHTML + '<table border="0" width="100%" cellpadding="2"><tr>';
                      newHTML = newHTML + '<td width="100%"><font face="Tahoma" size="1">'+title+'</font>';
                      newHTML = newHTML + '<br><font face="Tahoma" size="1">&#169;' +copyright+ '</font></td></tr>';
                  newHTML = newHTML + '</table></td></tr>';
            newHTML = newHTML + '</table></td></tr></table></td></tr>';
  newHTML = newHTML + '<tr><td width="100%" valign="top"><font face="Tahoma" size="1" color="#FFFFFF"><br></font></td>';
  newHTML = newHTML + '</tr></table>';

                }


        gettrailobjnostyle().innerHTML = newHTML;

        gettrailobj().visibility="visible";

}


MD.m_out = function(id){
    if(!$(id)){return false;}
    var ele = $(id);
    if(ele.hasChildNodes){
        while(ele.firstChild){
              ele.removeChild(ele.firstChild);
        }
    }
    return false;
}


MD.display_price = function(product_id){
    var sp_id = mprice = price = prefix = '';
    prefix = 'selected_'+product_id;
    price = $(prefix).options[$(prefix).selectedIndex].value.split('|');
    sp_id = 'sp_price_'+product_id;
    $(sp_id).innerHTML = '';
    $(sp_id).innerHTML ='$'+price[1];
}

MD.serverNotFound = function(){
    alert('404: No response from server.');
}
MD.serverError = function(){
    alert('Request failed! Please try again later.');
}

MD.encodeQueryComponents = function (kvpairs) {
    return $H(kvpairs).toQueryString();
}

MD.is_pid = function(product_id){
    if(!/^[a-zA-Z0-9]{10,20}/i.test(product_id)){
        return false;
    }
    return true;
}

MD.is_type = function(type){
    if(!/^[1-3]{1}/.test(type)){
        return false;
    }
    return true;
}

MD.is_sa= function(s_a_id){
    if(!/^[1-9]{1}/.test(s_a_id)){
        return false;
    }
    return true;
}


MD.addCart = function(pID,type,s_a_id){
  try {
    var prefix = s_p = '';
    if (!pID || !MD.is_pid(pID) || !MD.is_type(type)) { return false; }
    prefix = 'selected_' + pID;
    if (!s_a_id) {
      if (!$(prefix)) { return false; }
      s_p = $(prefix).getValue().strip();
    } else { s_p = s_a_id; }
    if (parseInt(s_p) < 1 || !MD.is_sa(s_p)) {
      return false;
    }
    var xmlHttpReq = Ajax.getTransport();
    if (!xmlHttpReq) { throw new Error(""); }
    var myDict = {
      'action'  : 'add_cart',
      'pid'     : pID,
      'type'    : type,
      's_a_id'  : s_p,
      'nocache' : (new Date()).getTime()
    }
    var opt = {
      method    : 'post',
      postBody  : MD.encodeQueryComponents(myDict),
      onSuccess : function(req) {
        var request = JSON.parse(req.responseText);
          if (req.status == 200 && request) {
            MD.location(MD.domain + 'cart');
          } else {
            alert('Server Error! Please try again later...');
            MD.location(document.location);
            return false;
          }//end if
        },
      on404     : MD.serverNotFound,
      onFailure : MD.serverError
    };
    (new Ajax.Request(MD.domain + 'motions_response', opt));
  } catch(e) {
    alert(e.message);
    MD.location(document.location);
  }
}//end

MD.addBin = function(pID,type){
    try{
        var xmlHttpReq = Ajax.getTransport();
        if(!pID || !MD.is_pid(pID) || !MD.is_type(type)){return false;}
        if(!xmlHttpReq)
            throw new Error('');
        var myDict = {'action': 'add_bin', 'pid':pID, 'type':type,'nocache': (new Date()).getTime()};
        var options = {
                method: 'post',
                postBody  : MD.encodeQueryComponents(myDict),
                onSuccess : function(transport){
                    var request = transport.responseText.evalJSON(true);
                    if(transport.status==200&&request){
                        if($('sp_bin_count'))
                            $('sp_bin_count').update(parseInt(request.c_bins));
                         alert(request.message);
                        return;
                    }else{
                        alert('Server Error! Please try again later..');
                        MD.location(document.location);
                    }
                },
                on404: MD.serverNotFound,
                onFailure: MD.serverError
            };
        new Ajax.Request(MD.domain+'motions_response', options);
    }catch(e){
        alert(e.message);
        MD.location(document.location);
    }
}




MD.set_ds_d = function(obj,pID){
    var prefix = other_s = s_index = '';
    s_index = obj.options[obj.selectedIndex].value.strip();
    if(s_index == 'Download'){
        prefix = 'selected_'+pID;
        if(prefix){
            other_s = $(prefix).options[$(prefix).selectedIndex].value.strip().split('|');
            prefix = '';
            prefix = 'sp_ds_'+pID;
            if($(prefix) && other_s.length == 3 && other_s[1] != ''){
                $(prefix).innerHTML = 'Download Size: '+other_s[1];
            }
        }
    }else if(s_index == 'DVD-R'){
        prefix = '';
        prefix = 'sp_ds_'+pID;
        if($(prefix)){
            $(prefix).innerHTML = '';
        }
    }
}

MD.set_ds_p = function(obj,pID){
    var prefix = other_s = s_index = '';
    try{
        s_index = obj.options[obj.selectedIndex].value.strip().split('|');

        prefix = 'delivery_'+pID;
        if($(prefix)){
            other_s = $(prefix).getValue().strip();
        }
        if(other_s == 'Download' && s_index.length == 3 && s_index[1] != ''){
            prefix = '';
            prefix = 'sp_ds_'+pID;
            if($(prefix)){
                $(prefix).update('Download Size: '+s_index[1]);
            }
        }
    }catch(e){
        return false;
    }
}





MD.ufo_obj = {};
MD.create_ufo = function(obj_id,cid,p){
    var w = 282;var h = 229;
    if(p == 'medium'){
        w = 350;//w = 372;
        h = 229;
    }

    MD.ufo_obj.ufo = {
        movie:MD.domain+"FLVPlayer_Progressive.swf",
        width:w,
        height:h,
        wmode:"opaque",
        majorversion:"8",
        build:"0",
        bgcolor:"#FFFFFF",
        quality:'high',
        scale:'noscale',
        name:'FLVPlayer',
        salign:'lt',
        flashvars:'&MM_ComponentVersion=1&skinName='+MD.domain+'Halo_Skin_3&streamName=http://www.motiondrops.com/previews/'+cid+'&autoPlay=false&autoRewind=false'
    };
    UFO.create(MD.ufo_obj.ufo, obj_id);
    MD.ufo_obj = null;
}


MD.setStyle = function(ele,myDict){
    if(!$(ele)){return false;}
    $(ele).setStyle(myDict);
}

MD.getSelectValue = function(obj){
    return $(obj).options[$(obj).selectedIndex].value.strip();
}


MD.setStatus = function(ele,flag){
    var sameOpt = document.getElementById('useShippingRadio');
    var disabled = flag;
    var billingAddrInputs = document.getElementById(ele);
    var inputList = billingAddrInputs.getElementsByTagName('input');
    var selectList = billingAddrInputs.getElementsByTagName('select');
    for (var i=0; i<inputList.length; i++) {
       if (inputList[i].getAttribute('type') != 'hidden') {
          inputList[i].disabled = disabled;
       }
    }
    for (var i=0; i<selectList.length; i++) {
        selectList[i].disabled = disabled;
    }

    var myDict = { cssFloat: 'left',opacity: 0.5};
    if(!flag){myDict['opacity'] = 1}


    MD.setStyle(ele,myDict);
}

MD.ys_toggleBillingAddr = function(){
    var sameOpt = document.getElementById('useShippingRadio');
    var disabled = sameOpt.checked ? true : false;
    MD.setStatus('b_info',disabled);
}

MD.setRadioHiddenFields = function(){
    var sameOpt = document.getElementById('ccSelectedRadio');
    var disabled = sameOpt.checked ? false : true;
    MD.setStatus('bb_info',disabled);
    MD.setStatus('billCreditCard',disabled);
}


MD.balloon = function(txt){
    var inner = '<div id="b_tip">'
                +txt
                +'</div>'
    ;
    return inner;
}

MD.cleanTxt = function(txt)
{
    if(txt != null)
    {
        //replace unsafe characters
        var clean = txt;
        clean = clean.replace(/\"/gi,"&quot;");
        clean = clean.replace(/\'/gi,"&quot;");
        clean = clean.replace(/\</gi,"&lt;");
        clean = clean.replace(/\>/gi,"&gt;");
        clean = clean.replace(/\&/gi,"&amp;");
        return clean;
    }
}

MD.load_clip_info = function(cid,flag,is_clip){
    if(!flag){
        flag = 1;
    }
    if(!is_clip){is_clip=1;}

    if(flag == 1){
        var prefix = 'a_f_'+cid;
    }else{
        var prefix = 'a_i_'+cid
    }

    if($(prefix)){
        if($(prefix).className == 'mas menos'){
            try{
                var xmlHttpReq = Ajax.getTransport();
                if(xmlHttpReq){
                    var myDict = {'action': 'load_clip_info', 'cid':cid,'flag':!flag?1:flag,'is_clip':is_clip,'nocache': (new Date()).getTime()}

                    var opt = {
                     method: 'post',
                     postBody: MD.encodeQueryComponents(myDict),
                     onSuccess: function(req){
                             if(flag == 1){
                                $('my_td_'+cid).update(req.responseText);
                                return;
                            }else{
                                $('my_td_more_info_'+cid).update(req.responseText);
                                return;
                            }//end if
                         },
                     on404: MD.serverNotFound,
                     onFailure: MD.serverError
                };
                (new Ajax.Request('motions_response', opt));

                }else{
                    window.location.href = document.location;
                }
            }catch(e){
                alert(e.message);
                return false;
            }
        }//end if
    }//end if
    return false;
}

MD.only = function(){
    var mcates = $('biz_detailsnewCats').getElementsByClassName('category_name');
    return parseInt(mcates.length) >= 3?false:true;
}
var win = null;
MD.openWindow = function(mlink,w,h,scroll){
    scroll?scroll:'no';
    var LeftPosition = (screen.width - w)?((screen.width - w)/2):0;
    var TopPosition =  (screen.height - h)?((screen.height - h)/2):0;
    var settings = 'height='+h+',width='+w+',directories=no,status=no,toolbar=no,location=no,menubar=no,top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no';
    win =window.open(mlink,'guide_pop',settings)
    win = settings = null;
    return false;
}

MD.ck = function(name){
    try{
        var inputs = '';
        inputs = $$('input');
        var error = 1;
        for( x in inputs ) {
            if( inputs[x].checked == true && inputs[x].name == name) {
                error = 0;
                break;
            }
        }//end for
        return (error ==0)?true:false;
    }catch(e){
        return false;
    }

}


MD.isEmail = function(v){
    return /^[a-z0-9,!\#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})/i.test(v);

}
