/*
 *  Tip - Tiny Prototype.
 *  (c) 2010 Konstantin Kirilov. 
 *  Tip is freely distributable under the terms of an MIT-style license.
 *  Tip is a modification and follow up of 
 *
 *  Prototype JavaScript framework, version 1.6.0.3
 *  (c) 2005-2008 Sam Stephenson
 *  For Prototype details, see the Prototype web site: http://www.prototypejs.org/
 *
*/

function swap_class(ob, style_class){
   ob.setAttribute( 'class', style_class );
}

//Utilities:
       //Get substring starting from substring:
       function getSubsFromSubs( str, sub, noCaseSearch ) {
            if( noCaseSearch ) {
                var pos=str.indexOf(sub);
            } else {
                var pos=str.toLowerCase().indexOf(sub.toLowerCase()); 
            }
            return pos > -1  ? str.substr( pos + sub.length ) : '';
       }


//Case insensetive:
       function getParFromHrefCaseInsensetive( href, par ){
             var query=getSubsFromSubs( href, '?' );
             var pos=query.toLowerCase().indexOf(par.toLowerCase()+'=');   
             if( pos < 0 ) return '';
             var preparsed = query.substr( pos + par.length + 1 );
             var pos=preparsed.indexOf('&');   
             return pos > 0  ? preparsed.substr(0, pos) : preparsed; 
       }
       //iname = iframe name,
       //url   = target source,
       //ids   = array of ids to pull:
                function injectIFrameAndPullDataFromIt( iname, url, ids, idsResult ){
                       var fr = document.getElementById( iname ); 
                       fr.onload = function (){ 
                               var doc=(fr.contentWindow || fr.contentDocument);
                               if(doc.document) doc=doc.document;
                               //Works:
                               //alert(fr.src + ' body=' + doc.body.innerHTML);
                               for(var i=0; i<ids.length; i++){
                                  var el = doc.getElementById(ids[i]);
                                  //if(el) alert(el.innerHTML);
                                  idsResult[ids[i]]=el;
                               }
                       };
                       fr.src = url;
                       fr.style.visibility = "visible";
                }
       //Test case:
       //<input type="button" onclick="var xxx=''; for( var x in idsResult ){ xxx = xxx + idsResult[x].innerHTML; }; alert(xxx); " />
       //var idsResult = {}; //let us to pollute global space.
       //var fr = injectIFrameAndPullDataFromIt( 'my_iframe', 'test.html', ['test1', 'test2'], idsResult );



