/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Varien
 * @package     js
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
function popWin(url,win,para) {
    var win = window.open(url,win,para);
    win.focus();
}

function setLocation(url){
    window.location.href = url;
}

function setPLocation(url, setFocus){
    if( setFocus ) {
        window.opener.focus();
    }
    window.opener.location.href = url;
}

function expandDetails(el, childClass) {
    if (Element.hasClassName(el,'show-details')) {
        $$(childClass).each(function(item){item.hide()});
        Element.removeClassName(el,'show-details');
    }
    else {
        $$(childClass).each(function(item){item.show()});
        Element.addClassName(el,'show-details');
    }
}

/**
 * Executes event handler on the element. Works with event handlers attached by Prototype,
 * in a browser-agnostic fashion.
 * @param element The element object
 * @param event Event name, like 'change'
 *
 * @example fireEvent($('my-input', 'click'));
 */
function fireEvent(element, event){
    if (document.createEventObject){
        // dispatch for IE
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt)
    }
    else{
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
    }
}

/*bookmark*/
var title=window.document.title;
var description="";
function loadPage(site,pageTitle,pageDescription){
 var rawURL=window.location.href;
 rawURL=rawURL.replace("#","");
 if(rawURL.indexOf("SRCCODE=")>0)
 {rawURL=rawURL.replace("SRCCODE=","SRCCODE=WEBDIGG&OLDSRC=")}
 else if(rawURL.indexOf("?")>0)
 {rawURL=rawURL+"&SRCCODE=WEBDIGG"}
 else{rawURL=rawURL+"?SRCCODE=WEBDIGG"}
 var currentURL=encodeURIComponent(rawURL);
 var title=encodeURIComponent(pageTitle);
 var bodytext=encodeURIComponent(pageDescription);
 var newURL;
 var go=true;
 switch(site){
  case"del.icio.us":newURL="http://del.icio.us/post?v=4;url="+currentURL+";title="+title;break;
  case"digg":newURL="http://digg.com/submit?phase=2&url="+currentURL+"&title="+title+"&bodytext="+bodytext+"&topic=tech_deals";break;
  case"reddit":newURL="http://reddit.com/submit?url="+currentURL+"&title="+title;break;
  case"furl":newURL="http://www.furl.net/savedialog.jsp?t="+title+"&u="+currentURL;break;
  case"rawsugar":newURL="http://www.rawsugar.com/home/extensiontagit/?turl="+currentURL+"&tttl="+title;break;
  case"twitter":newURL="http://twitthis.com/twit?url="+currentURL+"&title="+title;break;
  case"stumbleupon":newURL="http://www.stumbleupon.com/submit?url="+currentURL+"&title="+title;break;
  case"blogmarks":break;
  case"facebook":newURL="http://www.facebook.com/share.php?src=bm&v=4&u="+currentURL+"&t="+title;break;
  case"technorati":newURL="http://technorati.com/faves?sub=favthis&add="+currentURL;break;
  case"spurl":newURL="http://www.spurl.net/spurl.php?v=3&title="+title+"&url="+currentURL;break;
  case"simpy":newURL="http://www.simpy.com/simpy/LinkAdd.do?title="+title+"&href="+currentURL;break;
  case"ask":break;
  case"google":newURL="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+currentURL+"&title="+title;break;
  case"netscape":newURL="http://www.netscape.com/submit/?U="+currentURL+"&T="+title+"&C="+bodytext;break;
  case"slashdot":newURL="http://slashdot.org/bookmark.pl?url="+rawURL+"&title="+title;break;
  case"backflip":newURL="http://www.backflip.com/add_page_pop.ihtml?title="+title+"&url="+currentURL;break;
  case"bluedot":newURL="http://bluedot.us/Authoring.aspx?u="+currentURL+"&t="+title;break;
  case"kaboodle":newURL="http://www.kaboodle.com/za/selectpage?p_pop=false&pa=url&u="+currentURL;break;
  case"squidoo":newURL="http://www.squidoo.com/lensmaster/bookmark?"+currentURL;break;
  case"bluedot":newURL="http://blinkbits.com/bookmarklets/save.php?v=1&source_url="+currentURL+"&title="+title;break;
  case"blinkList":newURL="http://blinkbits.com/bookmarklets/save.php?v=1&source_url="+currentURL+"&title="+title;break;
  case"browser":bookmarksite(pageTitle,rawURL);go=false;break
  }
 if(go==true){window.open(newURL,"bookmarkWindow")}}

