// constants
var C_handlerPage = "a.php";

var C_msgDiv = "aMsg";
var C_actionDiv = "actionDiv";
var C_pickListDiv = "pinxPickList";
var C_listsDetailDiv = "listsDetail";
var C_listsDiv = "listsDiv";

// instance
var iPinxId = 0;
var iPage = 1;
var iListId = 0;
var iSourceListId = 0;
var iTargetListId = 0;
var iRowToHideDivId = null;
var iPinxPrice = 0;
var iGotoURL = null;
var iSelectedVal = null;
var iConfObj = null;

// generic functions

function getFromURL(att) {
	url = document.URL;
	pos = url.indexOf(att);
	posE = url.indexOf("#", pos+1);
	len = url.length;
	if (posE == -1) posE = len;
	value = url.substring(pos + att.length, posE);
//	alert(att + "  " + posE + "  " + value);
}

function ge(elem) {
	return document.getElementById(elem).value;
}

function gobj(elem) {
	return document.getElementById(elem);
}

function hide(name){
	tObject = document.getElementById(name);
	hideObj(tObject);
}
function hideObj(tObject){
	tObject.style.visibility = "hidden";
	tObject.style.height = "0px";
	tObject.style.width = "0px";
	tObject.style.position = "absolute";
}

function executeNoResponseHtml(serverPage, msg, afterEventAction) {
	execute(null, serverPage, msg, afterEventAction);
}

function execute(responseObjId, serverPage, msg, afterEventAction) {
	
	if (msg != null) showMsg(msg);
//	hideMsg();
//	return false;

	//Create a boolean variable to check for a valid Internet Explorer instance.
	var xmlhttp = false;
	
	//Check if we are using IE.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using Internet Explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-IE browser.
			xmlhttp = false;
		}
	}
	//If we are using a non-IE browser, create a javascript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	var responseObj = null;
	if (responseObjId != null) {
		responseObj = document.getElementById(responseObjId);
	}
//	alert(serverPage);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (responseObj != null) responseObj.innerHTML = xmlhttp.responseText;
			hideMsg();
			afterExecuteEvent(afterEventAction);
		}
	}
	xmlhttp.send(null);
}

function afterExecuteEvent(afterEventActionAction) {

	if (afterEventActionAction == null) return;

	if (afterEventActionAction == "gotoURL") {
		showMsg("taking you back ...");
		window.location = iGotoURL;
	}

	if (afterEventActionAction == "tweetConf") {
		msg = "We received your message and will publish it after approval.";
		msg += '<p><A href="javascript:void(0);" onClick="hide(\''+C_actionDiv+'\');">Close Window</a>';

		showDiv(110,250,C_actionDiv,msg,true,"Thanks!");

	}
 
	if (afterEventActionAction == "confirmUpdate") {
		confBox = document.getElementById(iConfObj);
		confBox.innerHTML = 'updated!';
	}

	if (afterEventActionAction == "refreshListCnt") {

		// refresh lists due to (count) - javascript update on DIV: increment new, decrement current (unless ALL)
		needRefresh = false;
//		needRefresh = true;
		if (iSourceListId > 0) needRefresh = changeListCnt("listCnt"+iSourceListId, -1);
		if (iTargetListId > 0) needRefresh = (needRefresh || changeListCnt("listCnt"+iTargetListId, 1));

		if (needRefresh) {
			serverPage = assemblePage("getList", null);
			execute(C_listsDiv, serverPage, "please wait ...", null);
		}

		// hide row
		if (iRowToHideDivId != null) hide(iRowToHideDivId);

	}
	if (afterEventActionAction == "showListDetail") {
		showListDetail(iListId, 1, 1);
	}
}

function getBrowserHeight() {                                         
	var intH = 0;                                                   
	var intW = 0;                                                   
								   
	if(typeof window.innerWidth  == 'number') {                     
		intH = window.innerHeight;                                   
		intW = window.innerWidth;                                    
	}                                                               
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		intH = document.documentElement.clientHeight;              
		intW = document.documentElement.clientWidth;               
    }                                                               
    else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {                                            
		intH = document.body.clientHeight;                            
		intW = document.body.clientWidth;                             
    }                                                               
                                                                           
    return {width: parseInt(intW), height: parseInt(intH)};         
}                                                                   

function showMsg(msg) {
	hm = 50;
	wm = 180;
	showDiv(hm,wm,C_msgDiv,msg,false,null);
}
                                                                           
function showDiv(hm,wm,divId,content,alignLeft, title) {

	if (alignLeft) {
		aln = 'left';
	}
	else {
		aln = 'center';
	}

	titleDisp = "";
	if (title != null) titleDisp = "<span class='actionDivTitle'>"+title+"</span><p>";
	if (content != null) {
		content = '<table width="100%"><tr><td align="'+aln+'">'+titleDisp+content+'</td></tr></table>';
	}
	var bws = getBrowserHeight();                                   
								   
//	hs = screen.height; 
//	ws = screen.width;
	hs = bws.height;
	ws = bws.width;
//	alert("hs="+hs+ "  ws=" + ws);
	scrollTop = 0;
	topOffset = 0;

	if(bType.ie) {
		scrollTop = document.body.scrollTop;
		topOffset = 0; // this is the position of the H1 tag from the top of the screen
	}
	posTop = scrollTop + parseInt((hs - topOffset - hm) / 2);
	posLeft = parseInt((ws - wm) / 2);

	theObject = document.getElementById(divId);
	if (alignLeft) {
		theObject.style.textAlign = 'left';
	}
	else {
		theObject.style.textAlign = 'center';
	}
	theObject.style.height = hm + "px";
	theObject.style.width = wm + "px";
	theObject.style.top = posTop + "px";
	theObject.style.left = posLeft + "px";

	if (bType.ie) {
		theObject.style.position = "absolute";
	}
	else {
		theObject.style.position = "fixed";
	}

	if (content != null) theObject.innerHTML = content;
	theObject.style.visibility = "visible";

}

function showHiddenDiv(divId, hm, wm) {

	theObject = document.getElementById(divId);
	theObject.style.height = hm + "px";
	theObject.style.width = wm + "px";
	theObject.style.visibility = "visible";
	theObject.style.position = "relative";

}

function hideMsg() {
	hide(C_msgDiv);
}


function assemblePage(action, tok, p1, v1, p2, v2, p3, v3, p4, v4, p5, v5, p6, v6, p7, v7) {
	uauth = "";
	if (document.getElementById('uauth') != null) uauth = document.getElementById('uauth').value;
	p = C_handlerPage + "?action=" + action + "&uauth=" + uauth;
	if (tok != null) p += "&tok=" + tok; 
	if (p1 != null) p += "&" + p1 + "=" + escape(v1); 
	if (p2 != null) p += "&" + p2 + "=" + escape(v2); 
	if (p3 != null) p += "&" + p3 + "=" + escape(v3); 
	if (p4 != null) p += "&" + p4 + "=" + escape(v4); 
	if (p5 != null) p += "&" + p5 + "=" + escape(v5); 
	if (p6 != null) p += "&" + p6 + "=" + escape(v6); 
	if (p7 != null) p += "&" + p7 + "=" + escape(v7); 
	p += "&" + Math.random();
	return p;
}

//	business functions

function delReview(revId){
	rowId = "row" + revId;

	serverPage = assemblePage("delReviewItem", null, "pid", revId);

	//execute("dbg", serverPage, "deleting ...");
	executeNoResponseHtml(serverPage, "deleting ...", null);
	hide(rowId);
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
	  retValue = retValue.substring(1, retValue.length);
	  ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
	  retValue = retValue.substring(0, retValue.length-1);
	  ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function showInputWnd(prompt, label, returnFunction){

	var cnt = "";
	cnt += '<form><b>'+label+':</b>&nbsp;&nbsp;<input ass=field type="text" id="inDiv" name="inDiv"></form>';
	cnt += '<p>';
	cnt += '<IMG onClick="val = ge(\'inDiv\');if (validateInputText(val)) {hide(\''+C_actionDiv+'\');'+returnFunction+'(val)}" SRC="images/continue.png" BORDER="0" >';
	cnt += '&nbsp;&nbsp;<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/cancel.gif" BORDER="0" >';

	showDiv(120,280,C_actionDiv,cnt,true,prompt);
}

function showListforPinxWnd(pinxId, sourceList, rowToHideDivId) {
	iPinxId = pinxId;
	iSourceListId = sourceList;
	iRowToHideDivId = rowToHideDivId;
	showDiv(480,250,C_pickListDiv,null,false);
}

function selectListforPinx(listId) {

//	alert(listId);
	iTargetListId = listId;

	hide(C_pickListDiv);
//	alert("from list " + iSourceListId + " selected list " + listId + " for " + iPinxId);

	// update !pinx
	serverPage = assemblePage("assignPinxToList", null, "pinxId", iPinxId, "listId", listId);
	executeNoResponseHtml(serverPage, "processing ...", "refreshListCnt");
	//debug: execute(C_listsDiv, serverPage, "updating list...", null);
}

function changeListCnt(spanId, add) {
	wasZero = false;
	
	if (document.getElementById(spanId) == null) return;

	if (parseInt(document.getElementById(spanId).innerHTML) == 0) wasZero = true;
	
	document.getElementById(spanId).innerHTML = parseInt(document.getElementById(spanId).innerHTML) + parseInt(add);
	
	return wasZero;
}

function validateInputText(val) {
	if (trim (val) == "") return false;
	return true;
}

function showCreateListWnd(){

	returnFunction = "createList";

	var cnt = "";
	cnt += '<form>';
	cnt += '<b>Name:</b>&nbsp;&nbsp;<input ass=field type="text" id="inDiv" name="inDiv">';
	cnt += '<p><b>Privacy Level:</b>&nbsp;&nbsp;<input class=rb type="radio" id="eisPublic" name="eisPublic" checked >&nbsp;public';
	cnt += '<input class=rb type="radio" id="eisPublic" name="eisPublic">&nbsp;private';
	cnt += '</form>';
	cnt += '<p>';
	cnt += '<IMG onClick="isP = document.getElementById(\'eisPublic\').checked;val = ge(\'inDiv\');if (validateInputText(val)) {hide(\''+C_actionDiv+'\');'+returnFunction+'(val, isP)}" SRC="images/continue.png" BORDER="0" >';
	cnt += '&nbsp;&nbsp;<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/cancel.gif" BORDER="0" >';

	showDiv(140,300,C_actionDiv,cnt,true,"Please enter the name of the new list.");
	//showInputWnd("", "Name", "createList");
}

function createList(name, isPublic){

	isPublic = toBool01(isPublic);
	serverPage = assemblePage("createList", null, "listname", name, "isPublic", isPublic);

	execute(C_listsDiv, serverPage, "creating list...", null);
}

function showListDetail(listId, page, sort) {

	serverPage = assemblePage("showListDetail", null, "listId", listId, "page", page, "sort", sort);
	execute(C_listsDetailDiv, serverPage, "Please wait ...", null);
}

function toBool01(bstr) {
	var b = 1;
	if(bstr == false) b = 0;
	return b;
}

function updateList(listId, name, isPublic, isDefault) {
	isPublic = toBool01(isPublic);
	isDefault = toBool01(isDefault);
	iListId = listId;
	serverPage = assemblePage("updateList", null, "listId", listId, "name", name, "isPublic", isPublic, "isDefault", isDefault);
	execute(C_listsDiv, serverPage, "updating list...", "showListDetail");
}

function deleteList(listId) {
	serverPage = assemblePage("deleteList", null, "listId", listId);
	execute(C_listsDiv, serverPage, "deleting list...", null);
}

function showEditListWnd(listId, isPublic, name, isDefault) {
	var cnt = "";
	
	checkedPublic = "";
	checkedPrivate = "";
	if (isPublic) checkedPublic = "checked";
	if (!isPublic) checkedPrivate = "checked";

	checkedDefault = "";
	if (isDefault) checkedDefault = "checked";

	cnt += '<form>';
	cnt += '<b>List Name:</b>&nbsp;&nbsp;<input size="30" class=field type="text" id="ename" name="ename" value="'+name+'">';
	cnt += '<p>';
	cnt += '<b>Privacy Level:</b>&nbsp;&nbsp;<input class=rb type="radio" id="eisPublic" name="eisPublic" '+checkedPublic+' >&nbsp;public';
	cnt += '<input class=rb type="radio" id="eisPublic" name="eisPublic" '+checkedPrivate+' >&nbsp;private';
	cnt += '<p>';
	cnt += '<b>Default List:</b>&nbsp;&nbsp;<input class=cb type="checkbox" id="isDefault" '+checkedDefault+' >';
	cnt += '</form>';
	// buttons
	cnt += '<p>';
	cnt += '<IMG onClick="isP = document.getElementById(\'eisPublic\').checked;name = ge(\'ename\'); isD = document.getElementById(\'isDefault\').checked; hide(\''+C_actionDiv+'\');updateList('+listId+', name, isP, isD)" SRC="images/update.gif" BORDER="0" >';
	
	// delete
	cnt += '&nbsp;&nbsp;<IMG onClick="if (confirm(\'Delete this list?\')){hide(\''+C_actionDiv+'\');deleteList('+listId+');}" SRC="images/deleteList.gif" BORDER="0" >';

	// cancel
	cnt += '&nbsp;&nbsp;<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/cancel.gif" BORDER="0" >';

	showDiv(180,300,C_actionDiv,cnt,true,"Edit list '" + name +"'");
}

function showEditPinxWnd(pinxId, page, listId, tags, comment, title, targetPrice, pinxPrice, pinxPriceDisp) {
	iPinxId = pinxId;
	iListId = listId;
	iPage = page;
	iPinxPrice = pinxPrice;

	//targetPrice = parseFloat(targetPrice);
	//alert(pinxPrice);

	doValidate = true;

	var cnt = "";
	
	cnt += "(All fields below are optional)<P>";
	cnt += '<form><table>';
	
	cnt += '<tr><td><b>Product Name:</b></td></tr><tr><td><input maxlength=80 size="80" class=field type="text" id="etitle" name="etitle" value="'+title+'"></td></tr>';
	cnt += '<tr><td><b>Comment/Notes:</b></td></tr><tr><td><Input maxlength=80 size="80" class=field type="text" id="ecmt" name="ecmt" value="'+comment+'"></td></tr>';
	cnt += '<tr><td><b>Item Tags:</b></td></tr><tr><td><input maxlength=80 size="80" class=field type="text" id="etags" name="etags" value="'+tags+'"></td></tr>';
	if (pinxPrice != null) {
		cnt += '<tr><td><b>Target Price:</b></td></tr><tr><td><input size="12" class=field type="text" id="etp" name="etp" value="'+targetPrice+'">  you pinxed it at '+pinxPriceDisp+'<br>(Set target price to only get a price drop alert if the price drops to or below the amount entered)</td></tr>';
	}
	else {
		cnt += '<tr><td><input type="hidden" id="etp" name="etp" value="'+targetPrice+'"></td></tr>';
		doValidate = false;
	}

	cnt += '</table></form>';

	// button
	cnt += '<p>';
	cnt += '<IMG onClick="p = ge(\'etp\');if (!doValidate || validateTargetPrice('+pinxPrice+', p)) {cmt = ge(\'ecmt\'); tit = ge(\'etitle\');tags = ge(\'etags\'); hide(\''+C_actionDiv+'\');updatePinx(tags,cmt,tit,p)}" SRC="images/update.gif" BORDER="0" >';
	
	// cancel
	cnt += '&nbsp;&nbsp;<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/cancel.gif" BORDER="0" >';

	showDiv(300,430,C_actionDiv,cnt,true,'Edit !pinx information');
}

function showRevEditPinxWnd(pinxId) {
	iPinxId = pinxId;

	doValidate = false;

	var cnt = "";
	
	cnt += '<form><table>';
	
	cnt += '<tr><td><b>status: [<a href="javascript:void(0);" onClick="gobj(\'status\').value = \'inactive\'">inactive</A>, <a href="javascript:void(0);" onClick="gobj(\'status\').value = \'discontinued\'">disco</A>, <a href="javascript:void(0);" onClick="gobj(\'status\').value = \'active\'">active</A>]</b></td></tr><tr><td><input maxlength=80 size="80" class=field type="text" id="status" name="status"></td></tr>';
	cnt += '<tr><td><b>price line:</b></td></tr><tr><td><Input size="80" class=field type="text" id="pline" name="pline" </td></tr>';
	cnt += '<tr><td><b>new price:</b></td></tr><tr><td><input size="80" class=field type="text" id="newprice" name="newprice"></td></tr>';
	cnt += '<tr><td><b>url:</b></td></tr><tr><td><input 80 size="80" class=field type="text" id="url" name="url"></td></tr>';
	cnt += '<tr><td><b>title:</b></td></tr><tr><td><input size="80" class=field type="text" id="title" name="title"></td></tr>';
	cnt += '</table></form>';

	// button
	cnt += '<p>';
	cnt += '<IMG onClick="newprice = ge(\'newprice\');pline = ge(\'pline\'); url = ge(\'url\'); title = ge(\'title\'); status = ge(\'status\'); hide(\''+C_actionDiv+'\');updateRevPinx(pline,newprice,status, title, url);" SRC="images/update.gif" BORDER="0" >';
	
	// cancel
	cnt += '&nbsp;&nbsp;<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/cancel.gif" BORDER="0" >';

	showDiv(300,430,C_actionDiv,cnt,true,'Edit !pinx information');
}

function updateRevPinx(pline, newprice, status, title, url) {
	//alert(iPinxId + "|" + pline + "|" + status + "|" + newprice + "|" + url + "|" + title);
	serverPage = assemblePage("updateRevPinx", null, "pinxId", iPinxId, "pline", pline, "status", status, "newprice", newprice, "title", title, "url", url);
//	executeNoResponseHtml(serverPage, "updating !pinx ...", null);
	execute("dbg", serverPage, "updating !pinx ...", null);
}

function validateTargetPrice(pinxPrice, targetPrice) {
	rc = true;
	if (trim(targetPrice + "") == "") {
		return true;
	}

	targetPrice = parseFloat(targetPrice);
	if (isNaN(targetPrice)) {
		alert("Target Price must be a number");
		rc = false;
	}
	else if (targetPrice >= pinxPrice) {
		alert("Target Price must be less than the price !pinxed");
		rc = false;
	}
	else if (targetPrice <= 0) {
		alert("Target Price must not be less or equal to zero");
		rc = false;
	}
	return rc;
}

function updatePinx(tags,cmt,title,targetPrice) {
	targetPrice = trim(targetPrice + "");
	//alert(targetPrice);
	serverPage = assemblePage("updatePinx", null, "pinxId", iPinxId, "listId", iListId, "tags", tags, "cmt", cmt, "title", title, "targetPrice", targetPrice, "page", iPage);
	execute(C_listsDetailDiv, serverPage, "updating !pinx ...", null);
}

function updatePinxWithToken(pinxId,tags,cmt,title,targetPrice,listId,token,confObj) {
//	alert("here");
	targetPrice = trim(targetPrice + "");
	iConfObj = confObj;

	// clear conf msg
	confBox = document.getElementById(iConfObj);
	confBox.innerHTML = '';

	serverPage = assemblePage("updatePinxWithToken", null, "pinxId", pinxId, "listId", listId, "targetPrice", targetPrice, "token", token, "title", title, "tags", tags, "cmt", cmt);
	//execute("dbg",serverPage, "updating !pinx ...", null);
	executeNoResponseHtml(serverPage, "updating !pinx ...", "confirmUpdate");
}

function deletePinxWnd(pinxId, listId, rowHide) {
	if (confirm("Delete this !pinx?")){
		serverPage = assemblePage("deletePinx", null, "pinxId", pinxId, "listId", listId);
		executeNoResponseHtml(serverPage, "deleting !pinx ...", null);

		// decrement count
		if (listId > 0) needRefresh = changeListCnt("listCnt"+listId, -1);
		// hide row
		if (rowHide != null) hide(rowHide);
	}
}

function repinx(url, token, pinxId) {
	iGotoURL = url;
	serverPage = assemblePage("deletePinxWithToken", null, "pinxId", pinxId, "authToken", token);
	executeNoResponseHtml(serverPage, "deleting !pinx ...", "gotoURL");
}

function validateEmailList(emails) {
	var currentTagTokens = emails.split( "," );
	var existingTags = "";

	valid = true;
	for ( var i = 0; i < currentTagTokens.length; i++ )
	{
		valid = validateEmail(currentTagTokens[ i ]);
		if (!valid) return false;
	}
	return true;

}

function validateEmail(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email) == false) {
		alert('Invalid Email Address');
		return false;
	}
	return true;
}

function shareList(e,cmt,copy) {
	serverPage = assemblePage("shareList", null, "listName", iListName, "listId", iListId, "e", e, "cmt", cmt, "cc", copy);
	executeNoResponseHtml(serverPage, "sending email(s) ...", null);
//	execute("dbg", serverPage, "sending email(s) ...");
}

function shareListWnd(listId, name) {
	iListId = listId;
	iListName = name;

	var cnt = "";
	
	cnt += '<form><table>';
	
	cnt += '<tr><td><b>Your Message (optional): </b></td></tr><tr><td><Input maxlength=125 size="125" class=field type="text" id="ecmt" name="ecmt" value=""></td></tr>';
	cnt += '<tr><td><b>Send To Address(es):</b></td></tr><tr><td><input maxlength=120 size="125" class=field type="text" id="email" name="email" value=""><br>(separate multiple addresses by commas)</td></tr>';
	cnt += '<tr><td><br><b>Send me a Copy:</b> <input class=cb type="checkbox" id="copyme" name="copyme" ></td></tr>';

	cnt += '</table></form>';

	// button
	cnt += '<p>';
	cnt += '<IMG onClick="e = ge(\'email\');if (validateEmailList(e)) {cmt = ge(\'ecmt\');copy = document.getElementById(\'copyme\').checked; hide(\''+C_actionDiv+'\');shareList(e,cmt,copy)}" SRC="images/send.gif" BORDER="0" >';
	
	// cancel
	cnt += '&nbsp;&nbsp;<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/cancel.gif" BORDER="0" >';

	showDiv(220,680,C_actionDiv,cnt,true,"Share list '"+name+"' with friends and family");
}

function sendFeedbackWnd() {
	var cnt = "";
	
	cnt += '<form><table>';
	
	cnt += '<tr><td><b>Your Message:</b></td></tr><tr><td><TextArea class=field id="ecmt" name="ecmt" cols=72 rows=5></TextArea></td></tr>';

	cnt += '</table></form>';

	// button
	cnt += '<p>';
	cnt += '<IMG onClick="cmt = ge(\'ecmt\');hide(\''+C_actionDiv+'\');sendFeedback(cmt)" SRC="images/send.gif" BORDER="0" >';
	
	// cancel
	cnt += '&nbsp;&nbsp;<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/cancel.gif" BORDER="0" >';

	showDiv(190,400,C_actionDiv,cnt,true,"Send us your feedback!");
}

function getListLinkWnd(link) {
	var cnt = "";
	
	cnt += '<textarea onfocus="this.select()" cols=63 rows=3>'+link+'</textarea>';
	cnt += '<br>(select the text above and use Ctrl+C to copy it into your clipboard)';
	cnt += '<p>';
	
	// cancel
	cnt += '&nbsp;&nbsp;<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/close.gif?x=1" BORDER="0" >';

	showDiv(170,550,C_actionDiv,cnt,true,"Please copy the link from the box below:");
}

function extendPinx(pinxId, page, listId) {
//	p = getFromURL("#p=");
//	s = getFromURL("#s=");
	if (confirm('Extend this !pinx by 30 days?')){
		serverPage = assemblePage("extendPinx", null, "pinxId", pinxId, "listId", listId, "page", page);
		execute(C_listsDetailDiv, serverPage, "extending !pinx ...", null);
	}
}

function makeListPublic(listId) {
		serverPage = assemblePage("makeListPublic", null, "listId", listId);
		execute(C_listsDetailDiv, serverPage, "making list public ...", null);
}

function sendFeedback(cmt) {
	serverPage = assemblePage("sendFeedback", null, "cmt", cmt);
	executeNoResponseHtml(serverPage, "sending feedback ...", null);
}

function showListHelpWnd() {
	var cnt = "";
	
	cnt += 'This page displays your !pinx. You can organize your !pinx into Lists. ';
	cnt += '<p><b>Lists</b><br>';
	cnt += 'A list can either be public <IMG SRC="images/publicFolder.gif" BORDER="0"> or private <IMG SRC="images/privateFolder.gif" BORDER="0">.';
	cnt += '<br>By default a new list is private. If you wish to share your list with others or link to it, then make it public.';
	cnt += '<br>';
	cnt += 'One of your lists can be the Default List. It is marked with a star <IMG SRC="images/defaultList.gif" BORDER="0">.';
	cnt += '<br>';
	cnt += 'You can change the privacy level (public or private), the Default List, or the name of a list by clicking the edit icon <IMG SRC="images/edit.gif" BORDER="0"> next to the list. ';
	cnt += 'Editing a list also allows you to delete it.';
	cnt += '<br>';
	cnt += 'By default there is a list called "Not in Any List". It contains all the !pinx that you have not placed in a list. There is no need to place a !pinx in a list.';
	cnt += '<p><b>Default List</b><br>';
	cnt += 'If you make one of your lists the Default List <IMG SRC="images/defaultList.gif" BORDER="0">, then all new !pinx that you create will go by default into this list. But of course you can always change the assignment of a !pinx to a list at a later point in time.';
	cnt += '<p>';
	
	// close
	cnt += '<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/close.gif?x=1" BORDER="0" >';

	showDiv(340,550,C_actionDiv,cnt,true,"my!pinx Quick Help");
}

function showPinxHelpWnd() {
	var cnt = "";
	
	cnt += 'This page displays your !pinx. You can organize your !pinx into Lists. ';
	cnt += '<p><b>Assign/Move a !pinx to a List</b><br>';
	cnt += 'You can organize your !pinx by placing them into lists. It is also useful to place !pinx in a list if you want to share them with others. For example you can place them into your Wish List, make this list public, and send it to others.';
	cnt += '<br>You can assign a !pinx to a list by clicking <IMG SRC="images/assign_pinx.gif" BORDER="0"> next to the !pinx.';
	cnt += '';
	cnt += '<p><b>Edit a !pinx</b><br>';
	cnt += 'You can edit a !pinx by clicking <IMG SRC="images/edit.gif" BORDER="0"> next to the !pinx. You can change the product name, add a comment, assign tags, and set the target price. The product name shows on the my!pinx page and the comment is visible once you move the move over the product name of the !pinx.';
	cnt += '<br>If you set a target price then you will only get a price drop alert if the price drops to or below the amount entered. You can only set a target price for active !pinx.';
	cnt += '';
	cnt += '<p><b>Email a !pinx</b><br>';
	cnt += 'You can email a !pinx to a anyone by clicking on the email icon <IMG SRC="images/email_pinx.gif" BORDER="0"> next to the !pinx.';
	cnt += '';
	cnt += '<p><b>Delete a !pinx</b><br>';
	cnt += 'You can delete a !pinx by clicking on the garbage bin icon <IMG SRC="images/del_pinx.gif" BORDER="0"> next to the !pinx.';
	cnt += '';
	cnt += '<p><b>Extend a !pinx</b><br>';
	cnt += 'You can extend an expired !pinx by clicking on the clock icon <IMG SRC="images/extend_pinx.gif" BORDER="0"> next to the !pinx.';
	cnt += '<p>';
	
	// close
	cnt += '<IMG onClick="hide(\''+C_actionDiv+'\');" SRC="images/close.gif?x=1" BORDER="0" >';

	showDiv(450,550,C_actionDiv,cnt,true,"my!pinx Quick Help");
}

function sendtweetForApproval(st) {
	serverPage = assemblePage("tweet", null, "msg", st);
	executeNoResponseHtml(serverPage, "sending your message ...", "tweetConf");
//	execute("dbg", serverPage, "sending your message ...", "tweetConf");
}

function shareApprove(app, id) {
	serverPage = assemblePage("tweetApprove", null, "app", app, "id", id);
	executeNoResponseHtml(serverPage, "processing ...", null);
//	execute("dbg", serverPage, "processing ...", null);
}
