// JScript File

function P2W_ToggleElement(el)
{
    var obj = document.getElementById(el);
    var display = (obj.style.display == "") ? "none" : "";
    obj.style.display = display;
}
function P2W_ReturnToResults()
{
    var s = P2W_ResultPageState.GetValues("ResultPageState");
    var arr = s.toString().split("___");
    var u = unescape(arr[0]);    
    location.href = u;
    P2W_ResultPageState.SetValue(s + "___true");
}


function P2W_SelectOptionByValue(targ, val)
{
    for(var i=0; i<targ.options.length; i++)
    {
        var el = targ.options[i];       
        if(el.value == val)
        {
            targ.selectedIndex = i;        
            break;
        }
    }
}

function P2W_SelectRadioByValue(targ, val)
{
    for(var i=0; i<targ.length; i++)
    {
        var el = targ[i];               
        if(el.value == val)
        {
            el.checked = true;        
            break;
        }
    }
}
function P2W_CreateXMLHttpRequest() {
  try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
  try { return new XMLHttpRequest();                   } catch(e) {}
  alert("XMLHttpRequest is not supported");
  return null;
}

function P2W_PrintPage()
{
    var da = (document.all) ? 1 : 0;
	var pr = (window.print) ? 1 : 0;
	var mac = (navigator.userAgent.indexOf("Mac") != -1);
    if (pr)
        window.print();
    else if (da && !mac) 
        vbPrintPage(); 
    else 
        alert("Sorry, your browser doesn't support this feature.");
        
    if (da && !pr && !mac) 
    {
        with (document) 
        { 
            writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');  
            writeln('<' + 'SCRIPT LANGUAGE="VBScript">');  writeln('Sub window_onunload');  
            writeln('  On Error Resume Next');  
            writeln('  Set WB = nothing');  
            writeln('End Sub');  
            writeln('Sub vbPrintPage');  
            writeln('  OLECMDID_PRINT = 6');  
            writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');  
            writeln('  OLECMDEXECOPT_PROMPTUSER = 1');  
            writeln('  On Error Resume Next');  
            writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');  
            writeln('End Sub');  
            writeln('<' + '/SCRIPT>');
        }
    }
}
function P2W_CookieManager(n,e,d,p)
{
	this.Name = n;
	this.Duration = e;
	this.Domain = d;
	this.Path = p;
	this.Delim = "|";	
	this.AddValue = p2w_cookiemanager_addvalue;
	this.RemoveValue = p2w_cookiemanager_removevalue;
	this.RemoveAll = p2w_cookiemanager_removeall;
	this.SetValue = p2w_cookiemanager_setvalue
	this.GetValues = p2w_cookiemanager_getvalues;						
}
function p2w_cookiemanager_removeall()
{
	this.SetValue("");
}
function p2w_cookiemanager_setvalue(v)
{
	var strCookie = "";
	var d = (this.Domain ==  null) ? "" : "domain = " + this.Domain + " ";
	if (this.Duration != null)
	{
		var expires = new Date();
		expires.setTime(expires.getTime() + this.Duration);					
		strCookie = this.Name + "= " + v + "; "+d+"path=" + this.Path + "; expires=" + expires.toGMTString();			
	}
	else
	{			
		strCookie = this.Name + "= " + v + "; "+d+"path=" + this.Path;
	}			
	document.cookie = strCookie;
}
function p2w_cookiemanager_removevalue(v)
{
	var val = new Array();
	var str = "";
	var items = this.GetValues(this.Name);	
	if(items != "" && items != null)
	{
		for(var i=0; i<items.length; i++){				
			if (items[i] != v)
			{
				val[val.length] = items[i];							
			}				
		}
	}
	if(val.length > 0)
		str = val.join(this.Delim);
	this.SetValue(str);
}
function p2w_cookiemanager_addvalue(v)
{
	var existing = this.GetValues(this.Name);			
	if(existing != "" && existing != null)
		v = existing.join(this.Delim) + this.Delim + v;			
	this.SetValue(v);						
}
function p2w_cookiemanager_getvalues()
{
	var val = null;
	var arr = document.cookie.split(";");	
	
	for(var i=0; i<arr.length; i++){
		nv =  arr[i].split("=");
		var name = nv[0].toString()
	
		if (nv.length == 2 && name.indexOf(this.Name.toString()) != -1)
		{
			var v = nv[1].split(this.Delim);	
			if (v != "" && v != null)
			{
				val = v;
			}
			break;				
		}
	}
	return val;
}
function P2W_Clipper(){
	this.Delim = "~";
	this.ListItems = new Array();
	this.AddToList = p2w_clipper_addtolist;			
	this.Cookies = new P2W_CookieManager("List",(60* 60 * 1000),null,"/");				
	this.Remove = p2w_clipper_remove;
	this.RemoveAll = p2w_clipper_removeall;
	this.Init = p2w_clipper_init;
	this.Count = 0;
	this.Init();			
}
function p2w_clipper_removeall()
{
	this.Cookies.RemoveAll();
	this.ListItems = new Array();
	this.Count = 0;
}

function p2w_clipper_remove(url)
{
		var arr = this.Cookies.GetValues();
		for(var i=0; i<arr.length; i++){
			var un = arr[i].split(this.Delim);
			if(un[0] == url)
			{
				this.Cookies.RemoveValue(un[0] + this.Delim + un[1]);
				this.ListItems[url] = null;	
				this.Count--;
			}
		}
					
}			
function p2w_clipper_addtolist(url, name)
{		
	this.Init();
	if(!this.ListItems[url])
	{
		this.ListItems[url] = new P2W_Clipper_Item(name,url);
		this.Cookies.AddValue(url + this.Delim + name);
		this.Count++;		
	}		
}

function p2w_clipper_init()
{
	this.ListItems = new Array();
	this.Count = 0;
	var arr = this.Cookies.GetValues();	
	
	if(arr)
	{
		for(var i=0; i<arr.length; i++)
		{
			var un = arr[i].split(this.Delim);
			this.ListItems[un[0]] = new P2W_Clipper_Item(un[1],un[0]);	
			this.Count++;													
		}			
	}				
}
function P2W_Clipper_Item(n,u)
{
	this.Name = n;
	this.Url = u;	
}

var P2W_List = new P2W_Clipper();
var P2W_ResultPageState = new P2W_CookieManager("ResultPageState",(60* 60 * 1000),null,"/");
function P2W_SelectListItems()
{
    var SelectedItems = P2W_List.ListItems;				
    for (var i in SelectedItems)
    {    
	if(SelectedItems[i].Url ==null)
		continue;
        var arr = SelectedItems[i].Url.split("_");
        var contentID = arr[1];
        var objID = "chk_" + contentID;        
       
        var obj = document.getElementById(objID);	
        
        if(obj != null)
        {
            obj.checked = true;
            continue;
        }        	
        
        if (typeof(P2W_P_View) != "undefined" && P2W_P_View.SelectedItem == contentID)
        {        
            obj = document.getElementById("chk_hldr");
            if(obj != null)
            {
                obj.checked = true;
            }  
         }
     }     
    
}
function P2W_AddItemToList(url, nm)
{
    if(P2W_List.ListItems[url] != null)
    {
	    P2W_List.Remove(url);
	}else
	{
		P2W_List.AddToList(url, nm);
	}
}
function P2W_Util()
{
	this.Url = new P2W_Url();
	this.WriteDate = P2W_Util_WriteDate;
}
//--------------------------------------------------------------------------

function P2W_Util_WriteDate(){
	var today = new Date();
	var months = new Array(
		"January", "February", "March", "April", 
		"May", "June", "July", "August", "September", 
		"October", "November", "December"
	);
	var m = today.getMonth();
	var d = today.getDate();	
	var y = today.getFullYear();	
	document.write(months[m] + " " + d + ", " + y);
}

//--------------------------------------------------------------------------