/*Clippings version 1.0.6.18.2001summary - - - - -script handles all Clipping functionalitythis is a stripped down version of the IHT Clippings codethe primary difference is the removal of animation code which I am not that happy withand a few minor improvements+  Add to Clippings+  Link to Clipping+  Update Clipping as read+  Remove Clipping(s)+  Save Clippingscomments- - - - - - Clippings only work with DOM browsers.  Opera at this point does not have enough of the DOM to support clippings.There is little or no feature/browser compatibiliy checking in this code, so use wisely.The code has been tested on IE 5.0, 5.5, 6.0 on Windows, IE 5.0 on Mac, and various versions of Netscape 6.0 and Mozilla.loadClippingURL() will control how Clipping urls are handled.  You will want to customize this method.clippingsTag is a variable which defines what tag your Clippings icon will be nested in.  All clipping icons must be in the same type of tag.there is a fix for a display error in Mozilla on lines 266-268 and again on changelog- - - - - - 08.06.2001 Mindor tweak to clippingsSetContainerHeight()copyright- - - - - -Copyright (C) 2001 John Weir  (www.smokinggun.com)This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.A copy of the license may be found at www.smokinggun.com/perm/gnu.phpor www.fsf.org (Free Software Foundation)*///bassel = new Array();allClippings = new Array();  //all Clippings on pageactiveClippings = new Array() //all Clippings stored by the usercurrentClipping = 0; //where in the list of Clippings is the userclippingsDivArray = new Array(); //array of all clipping divs on the page, used to find duplicatescookiesOn = true; //used to make sure cookies are enabledclippingsTag = "A"; //the tag which the Clipping icon is located invar mouseX = mouseY =0;//returns height, width and other window information//works in NS6 and IE5(Mac/Win)function screenObject()	{	this.bottom = function(){		if (document.body.scrollHeight) return document.body.scrollHeight};		this.height = function() {		if (document.body.offsetHeight) return document.body.offsetHeight;}		this.visHeight = function() {		if (window.innerHeight) return window.innerHeight;		if (document.body.clientHeight) return document.body.clientHeight;}		this.width = function() {		if (document.body.offsetWidth) return document.body.offsetWidth;}		this.scrollTop = function() {		if(document.body.scrollTop) return document.body.scrollTop		if (window.pageYOffset) return window.pageYOffset;		else return 0;};	}function mousePosition(e)	{	if (e) event = e;   //for Netscape	mouseX = event.clientX;	mouseY = event.clientY;	}	//resize the clippings container	function windowResize()	{	//clippingsSetContainerHeight()	}//this method needs to be called to initialize the clippingsfunction initClippings()	{	createPageClippingsArray()	loadClippings();	setClippingsVisibility();			updateClippingCounter();	drawClippings();	}	//clipping classfunction Clipping(id,name,URL, read)	{	this.id = id;	this.name = name;	this.URL = URL;	this.read = read;	this.clicked = markRead;	}//get Clippings from a cookiefunction loadClippings()	{	clippingsString = null;	tempArray = document.cookie.split(";");	x = -1;		for (tA = 0; tA < tempArray.length; tA++)	{		if (tempArray[tA].indexOf('clippings=') > -1) //found the clippings section			{			tPos = tempArray[tA].indexOf("=")+2;			clippingsString = tempArray[tA].substring(tPos,tempArray[tA].length); //striping out "clippings=^"			}	} 	clippingsString = jQuery.cookie('clippings');	clippingsString = clippingsString.substring(1);  	 	if (clippingsString != null)		{				tempArray = clippingsString.split("^");		if (tempArray.length > 1)		{		x=0;		    jQuery("div#downloadall").show();		    jQuery("div#emptyMessage").hide();				    for (i=0; i < tempArray.length/4; i++)			    {			    //add the id, name, url, readstate			    activeClippings[i] = new Clipping(tempArray[x],tempArray[x+1],tempArray[x+2],tempArray[x+3])			    x=x+4;			    }		    }	  }else{		jQuery("div#downloadall").hide();		jQuery("div#emptyMessage").show();			}    }//saves clippings to cookie	function saveClippings()	{	if(activeClippings.length > 0){	jQuery("div#downloadall").show();	jQuery("div#emptyMessage").hide();		}else{	jQuery("div#downloadall").hide();	jQuery("div#emptyMessage").show();		}	//tempCookie = "clippings=";	tempCookie = ""; // BASSSEL	for(i=0; i < activeClippings.length; i++)		{		tempCookie=tempCookie+"^"+(activeClippings[i].id)+"^"+(activeClippings[i].name)+"^"+(activeClippings[i].URL)+"^"+(activeClippings[i].read);		//tempCookie=tempCookie+(activeClippings[i].id)+"^"+(activeClippings[i].name)+"^"+(activeClippings[i].URL)+"^"+(activeClippings[i].read); //BASSEL		}	var expire = new Date ();   	expire.setTime (expire.getTime() + (6 * 24 * 3600000)); //expires in 6 days from users clock   	expire = expire.toGMTString();	finalCookie = tempCookie+"; path=/; expires="+expire;  	  	//document.cookie = finalCookie;  	jQuery.cookie('clippings', tempCookie, { path: '/', expires: expire });	}// detects wether cookies are turned on or notfunction eventCheckForCookies()	{	document.cookie = "cookies=on";  	  	checkForCookie = document.cookie.split(";");  	  		for (x=0; x < checkForCookie.length; x++)  			{  			if (checkForCookie[x].indexOf("cookies") >= 0) {cookiesOn = true;}  			}  		if (cookiesOn == false) alert("You will need to enable\ncookies to use Clippings.");	}//marks a clipping readfunction markRead(id)	{	if (!id) id = this.id.substring(5,this.id.length);	for (i=0; i < activeClippings.length; i++)		{		if (activeClippings[i].id == id) activeClippings[i].read = "yes";		}			//refresh the container	drawClippings();	}	//loads the url of the clippingfunction loadClippingURL(pos)	{	markRead(activeClippings[pos].id);		n = open(activeClippings[pos].URL,"win"+activeClippings[pos].id);	}//load next unread clipping in arrayfunction eventShowNextClipping()	{	if (activeClippings != null) 		{		total = 0;		for (aC = 0; aC < activeClippings.length; aC++)			{			if (activeClippings[aC].read != "yes") 				{				markRead(activeClippings[aC].id);				saveClippings();				loadClippingURL(aC);				//document.location = activeClippings[aC].url;				break;				}			}		}	}//remove clipfunction eventRemoveClip(arg){if(eval("bassel"+arg)){//alert("YES"+eval("bassel"+arg).length); var ArrToRemove = eval("bassel"+arg);   ArrToRemove.push(arg);    for (kk=0; kk<ArrToRemove.length; kk++)    {    for (i=0; i < activeClippings.length; i++)		{		if (activeClippings[i].id ==  arg) 		{		activeClippings[i].read = "yes"; 		}				}    eventClearReadClippings();    }	}else{ alert("Nothing in Array");}  }//function eventRemoveClip1(arg1){if(eval("bassel"+arg1)){    //alert("YES"+eval("bassel"+arg1).length);    var ArrToRemove1 = eval("bassel"+arg1);    //ArrToRemove1.push(arg1);    for (kk1=0; kk1<ArrToRemove1.length; kk1++)    {    for (i1=0; i1 < activeClippings.length; i1++)		{		if (activeClippings[i1].id ==  eval("bassel"+arg1)[kk1]) {activeClippings[i1].read = "yes"; }		}    eventClearReadClippings();    }}else{ alert("Nothing in Array2");}    	}//removes all read clippings	function eventClearReadClippings()	{	tempClippings = new Array()	x = 0;	for (i=0; i < activeClippings.length; i++)		{		if (activeClippings[i].read != "yes") {tempClippings[x] = activeClippings[i]; x++; }		}	activeClippings = tempClippings;	drawClippings();	setClippingsVisibility();		updateClippingCounter();	saveClippings();	}//removes all clippings	function eventClearAllClippings()	{		activeClippings = new Array();	updateClippingCounter();	setClippingsVisibility();	drawClippings();		saveClippings();	}//creates the HTML for the clippings menu when a clipping is added//removed create element and used innerHTML insteadfunction drawClippings()	{	newHTML = "";		//draw this text if there are no clippigns	if (activeClippings.length < 1) 		{		newHTML = "";		newHTML += "";		}		for (i=0; i < activeClippings.length; i++)		{		clipping = activeClippings[i];				if (clipping.read == "yes") tClass = "clippingItemRead";		else tClass = "clippingItem";		newHTML += "<div style='min-height:20px;height:auto;'><a href=\"javascript:loadClippingURL("+i+")\" class='"+tClass+"' id='cLink"+clipping.id+"'>";		newHTML += unescape(clipping.name)+"</a><div title='remove "+clipping.name+"' class='removeClip' onclick='eventRemoveClip("+clipping.id+");return false;'>X</div><br /></div>";				}	try {	       obj = document.getElementById("clippingsContainer");	           obj.innerHTML = newHTML;           //this is a fix for Mozilla, which is not draw the contents to screen currently;           obj.style.display = "none";           obj.style.display = "block";	} catch(e)	{	}				//make sure that the clippings container does not go off screen	//clippingsSetContainerHeight();	}//sets the height of the clippings container, make sure it does not go off screenfunction clippingsSetContainerHeight()	{	try {	    obj = document.getElementById("clippingsContainer");	if (userScreen.visHeight() > 350)		{		obj.style.height= (userScreen.visHeight()-350)+"px";		}	}catch(e){	}		}//make sure there is no other record of that clipping in usefunction checkForDuplicates()	{	for (i=0; i < activeClippings.length; i++)		{		if (newClipping == activeClippings[i].id) {i = allClippings.length; duplicate = true;}		}	}function checkForDuplicates1()	{	for (i=0; i < activeClippings.length; i++)		{		if (newClipping1 == activeClippings[i].id) {i = allClippings.length; duplicate = true;}		}	}function checkForDuplicates2()	{	for (i=0; i < activeClippings.length; i++)		{		if (newClipping2 == activeClippings[i].id) {i = allClippings.length; duplicate = true;}		}	}//creates array of all clippings on page//having this array helps speed things up on the macfunction createPageClippingsArray()	{		d = document.getElementsByTagName(clippingsTag)		for (j=0; j < d.length; j++) if (d[j].id.indexOf("clp") > -1) 			{			clippingsDivArray[clippingsDivArray.length] = d[j];			}	 }//finds duplicate clippings on a pagefunction clippingInstanceVisibility(id,state)	{	t = document.getElementsByName(id);	if(t.length > 0)		{		for (j=0; j < t.length; j++) 			{			t[j].style.visibility = state;			t[j].onclick = addClipping;			}		}	else {	 	d = clippingsDivArray;  		{		for (j=0; j < d.length; j++) if (d[j].id == id) 			{			d[j].style.visibility = state;			d[j].onclick = addClipping;			}		}		}			}	//sets the visibility and events for an object;	function setClippingsVisibility()	{		for (i=0; i < allClippings.length; i++)		{		vis = "visible";				//find if this clipping is already selected		for (x=0; x <activeClippings.length; x++) if (allClippings[i].id == activeClippings[x].id) vis = "hidden";			obj = "clp"+allClippings[i].id;			clippingInstanceVisibility(obj,vis)			}					}//this event is triggered when a clipping is clicked function addClipping()	{		newClipping = this.id.substring(3,this.id.length);	toremove = newClipping;	//alert('Doing it ' + newClipping);	duplicate = false;	for (i=0; i < allClippings.length; i++) //find the position the allClippings array of the selected clipping		{		if (newClipping == allClippings[i].id) {pos = i; i = allClippings.length}		}			if (activeClippings.length > 0)	checkForDuplicates() //make sure clipping is not already seletected		if (!duplicate)	{			eventCheckForCookies();		if (cookiesOn == true)			{			activeClippings[activeClippings.length] = new Clipping(allClippings[pos].id,allClippings[pos].name,allClippings[pos].URL);						//find all instances of the clipping in article and hides it	 		clippingInstanceVisibility(this.id,'hidden') 	 			 		drawClippings();		 		if (document.all) event.cancleBubble = true;	 		updateClippingCounter();			saveClippings();		 	}	 	}	 	try {	if(eval('bassel'+toremove)){		   // alert('Its parent');//	    var myArray = eval('bassel'+toremove);//	    if (myArray.length>0)//	    {//	    // alert('We are clicked at : '+bassel[newClipping].length);//	        //for(k=0; k <myArray.length; k++){//	           // alert(myArray[k]);//	           // addBClipping(myArray[k]);//	          //  addBClipping(2);//	       // }//	    };	}	} catch(e) {	}	}// bassel functionfunction addBClipping(n){newClipping1 = n;//this.id.substring(3,this.id.length)teRemove1 = newClipping1;	duplicate = false;	for (i=0; i < allClippings.length; i++) //find the position the allClippings array of the selected clipping		{		if (newClipping1 == allClippings[i].id) {pos = i; i = allClippings.length}		}			if (activeClippings.length > 0)	checkForDuplicates1() //make sure clipping is not already seletected		if (!duplicate)	{			eventCheckForCookies();		if (cookiesOn == true)			{			activeClippings[activeClippings.length] = new Clipping(allClippings[pos].id,allClippings[pos].name,allClippings[pos].URL);						//find all instances of the clipping in article and hides it				 		clippingInstanceVisibility('clp'+n,'hidden') 	 			 		drawClippings();		 			 		if (document.all) event.cancleBubble = true;	 		{	 		updateClippingCounter();	 			 		}	 		saveClippings();	 				 	}	 	}	 	try {	if(eval('bassel'+teRemove1)){		   // alert('Its parent');	    var myArray = eval('bassel'+teRemove1);	    if (myArray.length>0)	    {	    // alert('We are clicked at : '+bassel[newClipping].length);	        for(k1=0; k1 <myArray.length; k1++){	            //alert(bassel[newClipping][k]);	            addB1Clipping(myArray[k1]);	          //  addBClipping(2);	        }	    };	}	} catch(e) {	}}function addB1Clipping(n){newClipping2 = n;//this.id.substring(3,this.id.length)	duplicate = false;	for (i=0; i < allClippings.length; i++) //find the position the allClippings array of the selected clipping		{		if (newClipping2 == allClippings[i].id) {pos = i; i = allClippings.length}		}			if (activeClippings.length > 0)	checkForDuplicates2() //make sure clipping is not already seletected		if (!duplicate)	{			eventCheckForCookies();		if (cookiesOn == true)			{			activeClippings[activeClippings.length] = new Clipping(allClippings[pos].id,allClippings[pos].name,allClippings[pos].URL);						//find all instances of the clipping in article and hides it				 		clippingInstanceVisibility('clp'+n,'hidden') 	 			 		drawClippings();		 			 		if (document.all) event.cancleBubble = true;	 		{	 		updateClippingCounter();	 			 		}	 		saveClippings();	 				 	}	 	}}//sets the number of unread clippingsfunction updateClippingCounter()	{	if (activeClippings != null) 		{		total = 0;		for (aC = 0; aC < activeClippings.length; aC++)			{			if (activeClippings[aC].read != "yes") total++			}		}	obj = document.getElementById("clippingsCounter");	obj.innerHTML = "clippings: "+total;//+"<a href=\"javascript:eventShowNextClipping()\">Next Unread Clipping</a>";	obj.style.display = "none";	obj.style.display = "block";	}		//initialize clippings	function init()		{				//fix for differences in how IE and Netscape setAttribute to the class property		try		{		if (document.all) classFix = "className";		else classFix = "class";				//create a screen object, handles height, width of the screen		userScreen = new screenObject(); 				//in window.js		window.onresize = windowResize;				initClippings();		}catch(Err){}						//REMOVE THIS, ONLY FOR SMOKINGGUN.COM!		try			{			windowInit();			}		catch(err) {}		}			window.onload = init;	