var m_emailMsg;
var m_emailUrl;
var m_emailTitle;

var m_msgform;
var m_activepinx;
var m_msgformHeight;
var m_activepinxHeight;

var m_pdpWnd;
var m_pdpURL;
var m_timerThread;

function displayEmailMsg(msg, sub, id) {

	msgDiv = document.getElementById('usermail');
	msgDiv.innerHTML = "<P>" + msg;

	document.getElementById('mail_subject').value = sub;
	document.getElementById('mail_body').value = msg;
	document.getElementById('msgID').value = id;

}

function priceAlert(pongID) { 

	//email = document.getElementById("email").value;
	gotourl = '/pinxAmazon.php?pongID='+pongID;
	//alert(gotourl);
	lrg = window.open(gotourl,'priceguarantee', "width=700,height=480,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes"); 

} 

function priceAlertAmz(asins, prices) { 

	// remove , since it is used as sep
	prices = prices.replace(",","");

	//email = document.getElementById("email").value;
	gotourl = '/pinxAmazon.php?asins='+asins+'&prices='+prices;
	//alert(gotourl);
	lrg = window.open(gotourl,'priceguarantee', "width=700,height=480,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes"); 

} 

function showTarget(href) { 
	wnd = window.open(href,'PDP', "height=" + screen.height + ",width=" + screen.width + ",links=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=no,resizable=yes"); 
	return wnd;
} 

function showPRLink(href) { 
	wnd = window.open(href,'PR', "height=" + screen.height + ",width=" + screen.width + ",links=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=no,resizable=yes"); 
	return false;
} 

function initTimer() {
	m_timerThread = window.setTimeout('forwardToPDP()', 3200);
}
function forwardToPDP() {
	window.clearTimeout(m_timerThread)
	m_pdpWnd.location = m_pdpURL;
}

function gotoPDP(link, affURL) {
	m_pdpURL = link.href;
	if (affURL != null && affURL != '') {
		wnd = showTarget(affURL);
		m_pdpWnd = wnd;
		initTimer();
		return false;
	}
	else {
		return true;
	}
}

function showFreeShip() { 
	lrg = window.open('http://www.amazon.com/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fhelp%2Fcustomer%2Fdisplay.html%3Fie%3DUTF8%26nodeId%3D527692%26pop-up%3D1&tag=pricepinx-20&linkCode=ur2&camp=1789&creative=9325','FREESuperSaverShipping', "width=800,height=880,toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=no"); 
} 

function showQuickFeedback() { 
	lrg = window.open('quickfeedback.php','YourFeedback', "width=580,height=210,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no"); 
} 

function emailPinx(url, title, price, newPrice) { 
	//alert(url + "*"+title+"*"+price+"*"+newPrice);
	m_emailMsg = "Check out Price!pinx. They monitor the price of products for you and notify you about price drops as they happen. It is a breeze to use.";
	m_emailMsg += "\n\nI !pinxed the product\n*** " + title + " ***\n";
	if (newPrice == "")	{
		m_emailMsg += "Now I just sit back and wait for my price drop email notification.";
	}
	else {
		m_emailMsg += "Now the price dropped from " + price + " to " + newPrice + " and I automatically got an email notification.";
	}
	m_emailMsg += "\n\nHere is the link to my product:";
	m_emailUrl = "http://www.pricepinx.com/" + url;
	m_emailTitle = title;
	lrg = window.open('emailPinx.php','emailPinx', "width=780,height=510,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=no"); 
	return;
} 

function confirmMsg() {
	return confirm('Are you sure?');
} 

function getEmailMsg() {
	return m_emailMsg;
}
function getEmailUrl() {
	return m_emailUrl;
}
function getEmailTitle() {
	return m_emailTitle;
}

function bookmark() {
	var url = document.URL;
    var title = document.title;
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,""); 
	} 
	else if (window.external) {
		window.external.AddFavorite(url,title) 
	} 
	else {
		alert("Sorry, but your browser doesn't support this feature. Please bookmark this page manually."); 
	}
	if (!window.sidebar && !window.external) {
	document.getElementById('bookmarkPage').style.display = 'none';
	}
}


function BrowserType() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns||this.ie)
}

bType = new BrowserType()


function openWindow (URL, WinName, Features) { 
	window.open(URL, WinName, Features); 
} 

function winOpen (URL, WinName, Features) { 
	window.open(URL, WinName, Features); 
} 

function showLargeImage(url, title, h, w) { 

	lrg = window.open('url','title',"width=" + w + ",height=" + h + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no"); 
	lrg.document.write("<HTML><HEAD><TITLE>"+title+"</TITLE><BODY><IMG SRC='"+url+"'></BODY></HTML>");

} 

function showSendPage(from) { 

	lrg = window.open('http://www.pricepinx.com/tellAFriend.php','friend', "width=480,height=540,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes"); 

} 

function showLargeImage(url, title, h, w) { 

	lrg = window.open('url','title',"width=" + w + ",height=" + h + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no"); 
	lrg.document.write("<HTML><HEAD><TITLE>"+title+"</TITLE><BODY><IMG SRC='"+url+"'></BODY></HTML>");

} 

function getUrlToSend() { 
	return m_send_url;
}
function isTellAFriend() { 
	return m_tellafriend;
}


function div(a, b) { return Math.floor(a/b) }


function getUrlArg(url, src, def) {

	var pos = 0;
	var div = 0;
	var ret = def;

	var len=src.length;

	pos = url.indexOf(src);
	div = url.indexOf('&',pos+len);
	if (pos > 0) {
		if (div < 0) div = pos + 20; // end of str
		ret = url.substring(pos+len,div); 
	}
	
	return ret;
}


function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );



	//alert("name="+ name);
	//alert("setting val="+ value);

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
	//	  alert("found cookie");
		c_start=c_start + c_name.length+1 ;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
	//	alert("val="+document.cookie.substring(c_start,c_end));
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function Get_Cookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function signOut() {
	Delete_Cookie( "auth", "/", "" );
	Delete_Cookie( "uid", "/", "" );
	Delete_Cookie( "fn", "/", "");
}


function bookmarklet( isDetailLevel ) {
	nN=navigator.appName;
	nV=navigator.appVersion;
	aN="Unknown";
	nVs="?";
	var bookmarkImg = "";

	var msgBase = '* Move the mouse pointer over the large <IMG style="vertical-align:bottom" SRC="/images/pinx_s.gif" WIDTH="16" HEIGHT="16" BORDER="0"> image on the left. Right click on the image and choose ';

	var msg = '';
	var msg1 = '';
	var msg2 = '';

	if (nN=='Netscape') {
		bookmarkImg = 'images/ff_how_to_show_toolbar.gif';
		msg1 = msgBase + '"<I>Bookmark This Link</I>". Create the bookmarklet in the <I>Bookmarks Toolbar</I> folder.<p><IMG SRC="images/bookmark_ff.gif" BORDER="0" ALT="Bookmarks Toolbar folder">';
		if (nV.lastIndexOf('Win')!=-1) {
				msg2 = msg1;
				msg1 = '* Just drag the large <IMG style="vertical-align:bottom" SRC="/images/pinx_s.gif" WIDTH="16" HEIGHT="16" BORDER="0"> image on the left up to your Personal Bookmarks Toolbar.';
		} 
		else {
			if (nV.lastIndexOf('Mac')!=-1) {
				msg1 = "Open your Bookmarks for editing and drag the green large <span class=ex>!</span><span class=p>p</span> image on the left from this page over to the preferred place in your Bookmarks window.";
				msg2 = "";
			}
		}
		aN='Firefox/Netscape/Safari';
		nNs='n';
		nVs=parseInt(nV);
	} 
	else {
		if (nN=='Microsoft Internet Explorer') {
			bookmarkImg = 'images/how_to_show_toolbar.gif';
			aN = 'Internet Explorer ';
			nNs='e';
			nVs=parseInt(nV);
			msg1 = msgBase + '"Add to Favorites".';
			if (nV.lastIndexOf('Windows')!=-1) {
					msg1 = msgBase + '"Add to Favorites".<br>* If you receive a Security Alert, click "Yes" (Don\'t worry, this is safe!).<br>* Create the bookmarklet in the <I>Links</I> Folder (Click <I>Create In &gt;&gt;</I> if you do not see the <I>Links</I> folder) <div style="float: right" ><IMG align=right SRC="images/bookmark_ie_links.gif" BORDER="0" ALT="bookmark in Links folder">';
				//msg2 = 'Drag the green bookmarklet link into your Favorites (using View &gt;&gt;  Explorer Bar).  You can also drag the link up to your Favorites menu; when the menu opens, drag to whichever place you prefer.';
			} 
			else {
				if (nV.lastIndexOf('Mac')!=-1) {
					if (nV.lastIndexOf('4.')!=-1) {
						msg1 = 'Point at large <span class=ex>!</span><span class=p>p</span> image on the left. Hold down mouse button and choose "Add Link to Favorites".';
						msg2 = 'Drag the large <span class=ex>!</span><span class=p>p</span> image on the left into your Favorites (using the Explorer Bar, or by Opening your Favorites).'; 
						nVs='4';
					} 
					else {
						if (nV.lastIndexOf('3.')!=-1) {
							msg1 = 'Point at large <span class=ex>!</span><span class=p>p</span> image on the left. Hold down mouse button and choose "Add Link to Favorites".';
							msg2 = 'Open your Favorites and drag the large <span class=ex>!</span><span class=p>p</span> image on the left from this page over to the preferred place in your Favorites window.'; 
							nVs='3';
						}
					}
				}
			}
		}
	}

	var msgDiv;
	msgDiv = document.getElementById('instructions');
	cntent = '<table width="100%" cellspacing=10><tr>';
	msgDiv.innerHTML = '';
	if (msg2 != "")	{
		cntent += '<td width="49%" style="vertical-align: top;font-size:15px"><b>Setup Bookmarklet Option 1:</b><p>'+msg1+'</td>';
		cntent += '<td width="2%" style="vertical-align: top;font-size:15px"><b>OR</b></td><td width="49%" style="vertical-align: top;font-size:15px"><b>Setup Bookmarklet Option 2:</b><p>'+msg2+'</td>';
	}
	else {
		cntent += '<td width="90%" style="vertical-align: top;font-size:15px"><b>Setup Bookmarklet Instructions:</b><p>'+msg1+'</td>';
	}
	cntent += '</tr></table>'
	msgDiv.innerHTML = cntent;

	var broDiv;
	broDiv = document.getElementById('browser');
	if (broDiv != null) {
		broDiv.innerHTML = '';
		broDiv.innerHTML = aN;
	}

	if (isDetailLevel) document.images['toolbar'].src=	bookmarkImg;
}

bType = new BrowserType()

function layerHide(layer) {
	layer.style.visibility = (bType.ns4)? "hide" : "hidden"
}
function layerShow(layer) {
	layer.style.visibility = (bType.ns4)? "show" : "visible"
}
function getObj(name) {

	this.doc = document;

	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}
function showBoxMsg() {
	LayerResizeHeightTo(m_msgform, m_msgformHeight);
	layerShow(m_msgform);
}
function hideBox(l) {
	layerHide(l);
	LayerResizeHeightTo(l, 0);
}
function initLayers() {
	m_msgform = new getObj('msgform');
	m_activepinx = new getObj('activepinx');
	LayerResizeHeightTo(m_msgform, 0);
	m_msgformHeight = 100;
	m_activepinxHeight = 200;
}
function LayerResizeHeightTo(layer, w) {
	if (w != null) {
		layer.style.height = w;
		if (bType.ns) layer.style.height = w;
		else layer.style.pixelHeight = w;
	}
}
