
var storeName;
function tagInfo(tag)
{
	if (tag.currentprice > 0.0)
	{
		//for geting Img Src
		var imgsrc = imageURL(tag.imageurl);
		//for geting Short Description
		//alert(tag.shortdesc);
		tag.shortdesc = tag.shortdesc.replace("\n", " ");
		//alert(tag.shortdesc);
		//alert(tag.shortdesc + "   " + subStr(tag.shortdesc,10));
		var shortdesc = subStr(tag.shortdesc,20);
		//for geting Long Description
		var longdesc = tag.longdesc.trim();
		if(longdesc.length > 100)
			var longdesc = subStr(tag.longdesc.trim(),100) + "&nbsp;<a target='_blank' href='buyurlhandler.jsp?uri=" + tag.producturl + "'>more..</a>";
		//for geting Store Name
		var store = tag.vendorname;
		//alert(tag.vendorname);
		storeName = tag.vendorname;
		//alert("storeName---"+storeName);
		if(store.length > 15)
		store = store.substr(0,15)+"..."
		//for geting Product URL
		//var purl = productURL(tag.producturl);
		var purl = tag.producturl;
		//for geting Old Price
		var op = tag.pricewhentagged.toFixed(2);
		//for geting Current Price
		var cp = tag.currentprice.toFixed(2);
		//for geting Tagged Price
		var tp = tag.targetPrice.toFixed(2);
		//for geting Differance in %
		var ch = tag.currentprice - tag.pricewhentagged;
		var pc = (ch * 100.0)/tag.pricewhentagged;
		ch = ch.toFixed(2);
		pc = pc.toFixed(2).toString() + "%";
		// for geting tagged date
		var dstr =  dateFormat(tag.tagdate,"/");;
		var tagid = tag.id;
		var expired = parseInt(tag.expired);
		var productid = tag.productid;
		//alert(shortdesc);
		return {tagid:tagid,productid:productid, ImgURL:imgsrc,shortDesc:shortdesc,longDesc: longdesc,Store:store,oldPrice:op,currentPrice:cp,taggedPrice:tp,taggedDate:dstr,percntageDiff:pc,purl:purl,expired:expired};
	}
}

function addTag(tag)
{
	tag = tagInfo(tag)
	//alert(tag.shortDesc);
	var tagPos = tag.tagid; 
	var Html = '<div id="Item_' + tagPos + '"><div class="thumbnail">\n';
	Html += '<img width="100" height="125" src="' + tag.ImgURL + '" alt="" border="0" /></div>\n';
	Html += '<h4>' + trim(tag.shortDesc) + '</h4>\n';
	//alert("In Side addTag---"+storeName);
	Html += '<p><strong>Store Name: </strong><font title="'+ storeName +'">' + tag.Store + '</font><br \>\n';
	//Html += '<strong>Current Price:</strong> $' + tag.currentPrice + '<br />\n';
	Html += '<strong>List Price:</strong> $' + tag.oldPrice + '<br \>\n';
	Html += '<strong>Tagged:</strong> $' + tag.taggedPrice + '<br \>';
	
	if(tag.expired == 0)
		{
			if(tag.currentPrice==tag.oldPrice)
				Html += '<span>No Change in Price</span><br />\n';
			else
				Html += '<span>NOW $' + tag.currentPrice + '</span><br />\n';
			Html += '<input name="Buy Now" type="submit" onclick="window.open(\'buyurlhandler.jsp?uri=' + tag.purl + '\')" class="button_buym" value="Buy Now"><br>';
		}
	else
		Html += '<span>NOW Expired</span><br />\n';
	Html += '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<img  alt="More Details.." class="btnlo"  onclick="currentDlg.showPopUP('+ tagPos + ')" src="images/more_detail.jpg" alt="More Details" border="0" />\n';
	Html += '</p></div>\n';
	//PopUp Div HTML-------------------------------------------------------------
	Html += '<div id="popup_' + tagPos + '" class="nag_main_boxm"  >\n';
		Html += '<!--header start-->'; 
	   	Html += '<div class="hd_for_header" onmousedown="currentDlg.begindmove(event)"><center><b style="line-height:25px;">'+trim(tag.shortDesc)+'</b></center></div>';
	 	Html += '<div class="contantm"   align="left"><img onmousedown="currentDlg.reSet();" src="images/nag_popclose.gif" alt="close" width="13" height="13" border="0" class="closem">'; 
	    Html += '<!--IMG CONTANT-->'; 
	    Html += '<div class="img_inf_boxm">'; 
		    Html += '<div class="img_bxm fl" align="left"><img  src="'+ tag.ImgURL + '" alt="image" width="100" height="125"></div>'; 
		 	Html += '<div class="status_boxm">'; 
	         Html += '<div class="status_roww"><label>Store</label>: '+ storeName + '</div>'; 
	         //Html += '<div class="status_roww"><label>Current Price</label>: $' + tag.currentPrice + '</div>'; 
	         Html += '<div class="status_roww"><label>List Price</label>: $' + tag.oldPrice + '</div>'; 
	         Html += '<div class="status_roww"><label>Tag Price</label> : $' + tag.taggedPrice + '</div>'; 
	         Html += '<div class="status_roww"><label>Tag Date</label>: '+ tag.taggedDate + '</div>'; 
	         if(tag.expired == 0)
	         {
	            if(tag.currentPrice==tag.oldPrice)
					Html += '<div class="red_txtm"  class="status_roww">No Change in Price</div>';
				else
					Html += '<div class="red_txtm"  class="status_roww"><label>NOW</label>$' + tag.currentPrice + '</div>'; 
	         	Html += '<div class="buy_bxm" id="buyBoxHTML_' + tagPos + '"> <input name="Buy Now" type="submit" onclick="window.open(\'buyurlhandler.jsp?uri=' + tag.purl + '\')" class="button_buym" value="Buy Now"></div>';	         	
	         } 
	         else
	         {
	        	Html += '<div class="red_txtm  class="status_roww""><label>Status</label>: NOW Expired!</div>';
       		 }
       Html += '</div>'; 
       Html += '<div class="img_namem"><div class="img_hd_green">' + tag.shortDesc + '</div>' + tag.longDesc + '</div>';
       Html += '</div>'; 
	   	Html += '<div class="dividerm"><img src="images/nag_pop_dvdr.gif" alt="divider" width="510" height="1"></div>';
	   	Html += '<div class="form_save_errorm" id="cbox_message_' + tagPos + '" align="center"></div>'; 
	   	Html += '<div class="dividerm"><img src="images/nag_pop_dvdr.gif" alt="divider" width="510" height="1"></div>';
	  	Html += '<div class="form_bxm" id="statusBox_' + tagPos + '">'; 
			//status.statusBox;
      	
      	Html +='<div class="txt_pehra">Price drop from list price<span>&nbsp;' + tag.percntageDiff + '</span></div>';
      	Html += '<div class="form_hdm"  align="center">Perform following actions on this item:</div>';
      	Html += '<div class="form_contantm">';
		Html += '<form action="" method="get" name="nag" class="margin_zerom" onsubmit="return false;">';
		  	Html += '<div class="tbx_div"><label><span>*</span>Re-tag item at low price :</label>';
		  	Html += '<input id="tagValue' + tagPos +  '" type="text" class="text_aream" value="' + tag.taggedPrice + '" />';
      	//Html += '<div class="tbx_div"><label>&nbsp;</label>';
		  	Html += '&nbsp;<input name="Submit" onclick="dochange(\'Cell_\',\'' + tagPos +  '\')" type="submit" class="submit_buttonm" value="Update"></div>';
		Html += '</form>';
		Html += '</div>';
      	/////
      	Html += '</div>'; 
	  	Html += '<div class="share_divider"><img src="images/nag_pop_dvdr.gif" alt="divider" width="510" height="1"></div>';
			 	
	//	Html += '<div class="share_divider"><img src="images/nag_pop_dvdr.gif" alt="divider" width="510" height="1"></div>';	 	
	 	
	 
	 	Html += '<div id="nag_pannel' + tagPos + '" style="display:none;">';
		 	Html += '<div class="form_bxm" id="nagbox_' + tagPos + '">';
		      	Html += '<div class="form_contantm">';
				Html += '<form action="" method="get" name="nag" class="margin_zerom" onsubmit="return false;">';
				  	Html += '<div class="tbx_div"><label><span>*</span>Enter <a title="Nag allows NetHaggler users to negotiate for a lower price which is below the list price">Nag</a> price :</label>';
				  	Html += '<input id="nagValue' + tagPos +  '" type="text" class="text_aream" value="0.00" />';
				  	Html += '&nbsp;<input onclick="onaddnag(' + tagPos + ',\'' + tag.Store + '\',\'' + tag.productid + '\',\'' + tag.currentPrice + '\');" name="Submit" type="submit" class="submit_buttonm" value="Add"></div>';
				Html += '</form>';
				Html += '</div>';   
	      	Html += '</div>'; 
			//Html += '<div class="share_divider"><img src="images/nag_pop_dvdr.gif" alt="divider" width="510" height="1"></div>';
		Html += '</div>';
		
		
		//for Haggle Button
		Html += '<div id="haggle_pannel' + tagPos + '" style="display:none;">';
		 	Html += '<div class="form_bxm" id="hagglebox_' + tagPos + '">';
		      	Html += '<div class="form_contantm">';
				Html += '<form action="" method="get" name="haggle" class="margin_zerom" onsubmit="return false;">';
				  	Html += '<div class="tbx_div"><label><span>*</span>Enter Haggle Price :</label>';
				  	Html += '<input id="haggleValue' + tagPos +  '" type="text" class="text_aream" value="0.00" /><br\><br\>';
		      	  	Html += '<label><span>*</span>Quantity :</label>';
		      	  	Html += '<input id="qtyValue' + tagPos +  '" type="text" class="text_aream" value="1" /><br\>';
		      	  	if(tag.shortDesc.match('"') || tag.shortDesc.match("'"))
		      	  	{
		      	  		var newshortDesc= tag.shortDesc;
						if(newshortDesc.match('"'))
							newshortDesc= newshortDesc.replace('"', " ");
						if(newshortDesc.match("'"))
							newshortDesc= newshortDesc.replace("'", " ");
						Html += '&nbsp;<center><input onclick="onaddhaggle(' + tagPos + ',\'' + tag.Store + '\',\'' + tag.productid + '\',\'' + tag.currentPrice + '\',\''+newshortDesc+'\');" name="Submit" type="submit" class="submit_buttonm" value="Add"></center></div>';
					}
					else
		      	  		Html += '&nbsp;<center><input onclick="onaddhaggle(' + tagPos + ',\'' + tag.Store + '\',\'' + tag.productid + '\',\'' + tag.currentPrice + '\',\''+trim(tag.shortDesc)+'\');" name="Submit" type="submit" class="submit_buttonm" value="Add"></center></div>';
				Html += '</form>';
				Html += '</div>';   
	      	Html += '</div>'; 
		 	Html += '<div class="share_divider"><img src="images/nag_pop_dvdr.gif" alt="divider" width="510" height="1"></div>';
		Html += '</div>';
		
		
	  	
	  	Html += '<div id="share_pannel' + tagPos + '" style="display:none;">';
	  	Html += '<div class="share_form_contantm"  style="padding: 0 0 0 40px; "> '; 
        Html += '<div class="share_tbx_div"> ';
            Html += '<div class="share_txtar_cont fl"> ';
              Html += '<div class="share_txtar_P">E-mail Address(One per line):</div>';
              Html += '<textarea id="email_'+ tagPos + '" class="text_boxm" type="text"></textarea>'; 
            Html += '</div> ';
            Html += '<div class="share_txtar_contRgt fl"> ';
             Html += '<div class="share_txtar_P">Personal Message : </div> ';
              Html += '<textarea id="sharemessage_'+ tagPos + '" class="text_boxm" type="text"></textarea>';
            Html += '</div>';
			Html += '<div class="fl" style="padding: 25px 0 0 0; height: auto; width: auto;"><input name="send" type="button" class="submit_buttonm" onclick="sendMail(' + tagPos + ',\''+ tag.purl +'\')" value="Send"><br/><input name="cancel" type="button" class="submit_buttonm" onclick="onShareCancel('+tagPos+')" value="Cancel"/ style="margin-top: 5px;">';
			Html += '</div>';
          Html += '</div>'; 
         Html += '</div>';
	  	Html += '<div class="share_divider"><img src="images/nag_pop_dvdr.gif" alt="divider" width="510" height="1"></div>';
	  	Html += '</div>';
	 	
	 	Html += '<div id="cellControl_'+ tagPos + '" class="footer_linkm"><ul>'; 
		Html += '<li><input onclick="onnag(' + tagPos + ');" name="Submit" type="submit" class="submit_ft_buttonm" value="Nag Now"></li>';
		Html += '<li><input name="Submit" onclick="onhaggle(' + tagPos + ');" type="submit" class="submit_ft_buttonm" value="Haggle"></li>'; 
		Html += '<li><input  onclick="onshare(' + tagPos + ');" name="Submit" type="button" class="submit_ft_buttonm" value="Share"></li>'; 
		Html += '<li><input onclick="ondelete(\''+ tagPos + '\')" name="Submit" type="submit" class="submit_ft_buttonm" value="Delete"></li>'; 
		Html += '<li><input onclick="currentDlg.reSet();" name="Submit" type="submit" class="submit_ft_buttonm" value="Close"></li>';
		Html += '</ul></div>';
		Html += '</div>'; 
		Html += '</div>'; 
	
	//--------------------------------------------------------
	
	return Html
}



function onnag(tagid)
{
	var share_pannel = E("share_pannel" + tagid);
	var haggle_pannel = E("haggle_pannel" + tagid);
	var box = E("cbox_message_" + tagid);
	var nag_pannel = E("nag_pannel" + tagid);
	var statusBox = E("statusBox_"+tagid);
	
	if(statusBox.style.display == "none")
		statusBox.style.display = "";
	else
		statusBox.style.display = "none";
	if(nag_pannel.style.display == "none")
		nag_pannel.style.display = "";
	else
		nag_pannel.style.display = "none";
		
	share_pannel.style.display = "none";
	if(haggle_pannel!=null)
	haggle_pannel.style.display = "none";
	box.style.display = "none";
	box.innerHTML = "";
}
function onhaggle(tagid)
{
	//alert("Hi");
	var statusBox = E("statusBox_" + tagid);
	var share_pannel = E("share_pannel" + tagid);
	var box = E("cbox_message_" + tagid);
	var nag_pannel = E("nag_pannel" + tagid);
	var haggle_pannel = E("haggle_pannel" + tagid);
	if(haggle_pannel.style.display == "none")
		haggle_pannel.style.display = "";
	else
		haggle_pannel.style.display = "none";
	
	statusBox.style.display = "none";
	share_pannel.style.display = "none";
	nag_pannel.style.display = "none";
	box.style.display = "none";
	box.innerHTML = "";
}




function onshare(tagid)
{

	var nag_pannel = E("nag_pannel" + tagid);
	var haggle_pannel = E("haggle_pannel" + tagid);
	var share_pannel = E("share_pannel" + tagid);
	var box = E("cbox_message_" + tagid);
	var statusBox = E("statusBox_"+tagid);
	
	if(statusBox.style.display == "none")
		statusBox.style.display = "";
	else
		statusBox.style.display = "none";
	if(share_pannel.style.display == "none")
		share_pannel.style.display = "";
	else
		share_pannel.style.display = "none";
	
	if(nag_pannel)
	{
		nag_pannel.style.display = "none";
	}
	if(haggle_pannel)
	{
		haggle_pannel.style.display = "none";
	}
	
	box.style.display = "none";
	box.innerHTML = "";
	
}

function sendMail(tagid, uri ,pid)
{
	var msg="";
	var addresses = E("email_" + tagid).value;
	var message = E("sharemessage_" + tagid).value;
	E("email_" + tagid).value = "";
	E("sharemessage_" + tagid).value = "";
	var status = "";
	
	addresses = addresses.replaceAll("\r", "");
	if (validate(addresses, tagid)) 
	{
		nagHandler.ShareMail(tagid,addresses,message, uri, pid);
	}
}

String.prototype.replaceAll = function(findStr,repStr){
			var txt = this;
			var srchNdx = 0;
			var newStr = "";
			while (txt.indexOf(findStr,srchNdx) != -1) {
				newStr += txt.substring(srchNdx,txt.indexOf(findStr,srchNdx));
				newStr += repStr;
				srchNdx = (txt.indexOf(findStr,srchNdx) + findStr.length);
			}
			newStr += txt.substring(srchNdx,txt.length);
			return newStr;
		}

function validate( addresses, tagid)
{
	var msg = "";
	var count = 0;
	var fld = "email_" + tagid;
	var list = addresses.split("\n");
	for (var i = 0; i < list.length; i++) 
	{
		var addr = list[i];
		if(addr.indexOf(" ") != -1)
		{
			msg = "Email address '"+addr+"' must be in following format : example@example.com";
				break;
		}
		if (addr.length > 0) 
		{
			if (validEmail(addr)) 
			{
				count++;
			} 
			else 
			{
				msg = "Email address '"+addr+"' must be in following format : example@example.com";
				break;
			}
		}
		
		if(addr.length >50 )
		{
			msg = "Email addres is longer than 50 character.";
			break;
		}
	}
	if (msg.length == 0 && count == 0) 
	{
		msg = "<b>Please enter one or more email addresses of your friends.</b>";
	}
	
	if (msg.length > 0) 
	{
		E(fld).focus();
		setmsg(msg, "brown", tagid);   
		return false;
	} 
	else 
	{
		return true; 
	}
}


function setmsg(msg, clr,tagid)
{
	var box = E("cbox_message_" + tagid);
	box.innerHTML = "<div class='dividerm'><img src='http://www.nethaggler.com/home/images/nag_pop_dvdr.gif' alt='divider' width='510' height='1'></div>"+msg;
	box.style.display = "";
	box.style.color = clr;
}
function onaddnagNotNaggable(tagid)
{
 //alert('onaddnagNotNaggable');
 msg = "Presently, NetHaggler doesn't facilitate Nagging on this product. We are working on adding new merchantsand products and please check back later. Meanwhile, you can tag and haggle for the same merchant";
 setmsg(msg, "brown", tagid);
 return false;
}

function onaddnag(tagid, Store, productid, currentprice,templateId,imageUrl,storename,shortdesc,longdesc,hreflink)
{
  //added code for feed template				
			    templateId1 = templateId;
			    imageUrl1 = imageUrl;
			    productId1 = productid;
			    currentPrice1 = currentprice;
			    vendername1 = Store;
			    shortdesc1 = shortdesc;
			    longdesc1 = longdesc;
			    hreflink1 = hreflink;		     
			
	var msg = "";
	if(currentprice <= 1.0)
	{
		var msg = "<b>You can only Nag an item which has price greater than $1.0.</b>";
		setmsg(msg, "brown", tagid);
		E("nagValue" + tagid).focus();
		return false;
	}
	ten=(currentprice/100)*10;
	ninenine=(currentprice/100)*99;
	var hprice=E("nagValue" + tagid).value;
	hprice = String(hprice).replace(/[^\d.-]*/gi, "");
	hprice=hprice.trim();
	if(hprice.indexOf(" ")!=-1)
	{
		msg = "<b>Nag price is invalid. There should be no space.</b>";
		setmsg(msg, "brown", tagid);
		E("nagValue" + tagid).focus();
		return false;
	}
	var decIndex=hprice.indexOf(".");	
	
	if(decIndex!=-1)
	{		
		decIndex=decIndex+1;
		str=hprice.substr(decIndex);	
		
		if(str.length > 3)
			{
				msg = "<b>Nag price is invalid. Please enter 3 digits after decimal</b>";
				setmsg(msg, "brown", tagid);
				E("nagValue" + tagid).focus();
				return false;
			}
	}
	
	var nagValue = E("nagValue" + tagid).value;
	nagValue = String(nagValue).replace(/[^\d.-]*/gi, "");
	if (isNaN(nagValue) || nagValue=='undefined' || nagValue=="" || nagValue==null)
	{
		msg = "<b>Nag price is invalid.</b>";
		setmsg(msg, "brown", tagid);
		E("nagValue" + tagid).focus();
		return false;
	}	
	var nagValue = parseFloat(nagValue);
	if (isNaN(nagValue) || nagValue < 1.0)
	{
		msg = "<b>Nag price is invalid.(Nag price must be at least $1.0.)</b>";
		setmsg(msg, "brown", tagid);
		E("nagValue" + tagid).focus();
		return false;
	}
	if(nagValue > currentprice)
	{
		msg = "<b>Nag price is greater than Current price</b>";
		setmsg(msg, "brown", tagid);
		E("nagValue" + tagid).focus();
		return false;
	}
	else if(nagValue < ten || nagValue > ninenine )
	{
		var msg = "<b>Nag price is invalid. It must be between 10% to 99% of the current price.</b>";
		setmsg(msg, "brown", tagid);
		E("nagValue" + tagid).focus();
		return false;
	}
	else
	{
		nagHandler.addNagfromTag(tagid, Store, productid, currentprice, nagValue);
		//alert(currentprice);
	}
} 


function onaddhaggle(tagid, Store, productid, currentprice, proName,templateId,imageUrl,storename,shortdesc,longdesc,hreflink)
{
   //added code for feed template				
			    templateId1 = templateId;
			    imageUrl1 = imageUrl;
			    productId1 = productid;
			    currentPrice1 = currentprice;
			    vendername1 = Store;
			    shortdesc1 = shortdesc;
			    longdesc1 = longdesc;
			    hreflink1 = hreflink;
			
	var msg = "";
	currentprice=parseFloat(currentprice);
	if(currentprice <= 1.0)
	{
		var msg = "<b>You can only Haggle an item which has price greater than $1.0.</b>";
		setmsg(msg, "brown", tagid);
		E("haggleValue" + tagid).focus();
		return false;
	}
	var tagPriceMin= currentprice * 0.1;
	var tagPriceMax = currentprice * 0.99;
	//alert(proName+"-----In Side onaddhaggle");
	var hprice=E("haggleValue" + tagid).value;
	hprice = String(hprice).replace(/[^\d.-]*/gi, "");
	hprice=hprice.trim();
	var decIndex=hprice.indexOf(".");	
	if(hprice.indexOf(" ")!=-1)
	{
		msg = "<b>Haggle price is invalid. There should be no space.</b>";
		setmsg(msg, "brown", tagid);
		E("haggleValue" + tagid).focus();
		return false;
	}
	if(decIndex!=-1)
	{		
		decIndex=decIndex+1;
		str=hprice.substr(decIndex);		
		if(str.length > 3)
			{
				msg = "<b>Haggle price is invalid. Please enter 3 digits after decimal</b>";
				setmsg(msg, "brown", tagid);
				E("haggleValue" + tagid).focus();
				return false;
			}
	}
	var haggleValue = hprice;//E("haggleValue" + tagid).value;
	
	if (isNaN(haggleValue) || haggleValue.indexOf('+')!=-1)
	{
		msg = "<b>Haggle price is invalid. </b>";
		setmsg(msg, "brown", tagid);
		E("haggleValue" + tagid).focus();
		return false;
	}
	var qtyValue = E("qtyValue" + tagid).value;
	qtyValue = String(qtyValue).replace(/[^\d.-]*/gi, "");
	var haggleValue = parseFloat(haggleValue);
	if (isNaN(haggleValue) || haggleValue < 1.0 )
	{
		msg = "<b>Haggle price is invalid. (Haggle Price must be at least  $1.0) </b>";
		setmsg(msg, "brown", tagid);
		E("haggleValue" + tagid).focus();
		return false;
	}
	if(haggleValue > parseFloat(currentprice) || haggleValue < tagPriceMin || haggleValue > tagPriceMax)
	{
		msg = "<b>Please Enter valid Price value (10% to 99% of the current price) </b>";
		setmsg(msg, "brown", tagid);
		E("haggleValue" + tagid).focus();
		return false;
	}
	qtyValue=qtyValue.trim();	
	if(qtyValue == "" || qtyValue.indexOf(' ')!=-1 || qtyValue.indexOf('+')!=-1 || isNaN(qtyValue) || 0 >= parseInt(qtyValue) || qtyValue.indexOf(".")!=-1 || qtyValue=="0")
	{
		msg = "<b>Please Enter valid Quantity.</b>";
		setmsg(msg, "brown", tagid);
		E("qtyValue" + tagid).focus();
		return false;
	}
	//alert(parseInt(qtyValue))
	if(parseInt(qtyValue) > 999)
	{
		msg = "<b>Please Enter Quantity lesser than 999.</b>";
		setmsg(msg, "brown", tagid);
		E("qtyValue" + tagid).focus();
		return false;
	}	
	else
	{
		//alert("trim(tag.shortDesc)"+ proName);
		nagHandler.addHagglefromTag(tagid, Store, productid, currentprice, haggleValue, qtyValue, proName );
	}
} 



function ondelete(tagid)
{
	if(confirm("Are you sure you want to delete this Product from TAG list ?"))
	{
		dodelete(tagid);
	}
}

function dodelete(tagid)
{
	//E("cellControl_"+ tagid).style.display = "none";
	//E("cellProgress_" + tagid).style.display = "block";
	var res = simpleCall("tagupdate.jsp",{op:"delete",tagid:tagid});
	if (res.status=="OK")
	{
		var sortBy = E("sortBy").value;
		authentiCall("1",sortBy);
	}
	else
	{
		alert("Could not delete the tag.\n" + res.message);
	}
}
// function created for tag limit fincationality for paging in tag.
function doChangeTagForLimit(el,tagid,currentPrice)
{
	currentPrice=parseFloat(currentPrice);
	if(currentPrice <= 1.0)
	{
		var msg = "<b>You can only Tag an item which has price greater than $1.0.</b>";
		setmsg(msg, "brown", tagid);
		E("tagValue" + tagid).focus();
		return false
	}
	var Cell = E(el + tagid);
	var offer = E("tagValue" + tagid).value;
	offer = String(offer).replace(/[^\d.-]*/gi, "");
	
	var decIndex=offer.indexOf(".");
	if(offer.indexOf(" ")!=-1 ||  offer.indexOf('+')!=-1 || offer.indexOf('-')!=-1)
	{
		msg = "<b>Tag price is invalid. There should be no space,+,- etc.</b>";
		setmsg(msg, "brown", tagid);
		E("tagValue" + tagid).focus();
		return false
	}
	if(decIndex!=-1)
	{		
		decIndex=decIndex+1;
		str=offer.substr(decIndex);		
		if(str.length > 3)
			{
				msg = "<b>Tag price is invalid. Please enter 3 digits after decimal</b>";
				setmsg(msg, "brown", tagid);
				E("tagValue" + tagid).focus();
				return false
			}
	}	
	
	var oprice = parseFloat(offer);
	tagPriceMin=currentPrice* 0.1;
	tagPriceMax = currentPrice * 0.99;
	//alert(isNaN(currentPrice));
	if (isNaN(oprice) ||   oprice < 1.0)
	{
		var msg = "<b>Please enter valid price.(Tag Price must be at least  $1.0) </b>";
		setmsg(msg, "brown", tagid);
		E("tagValue" + tagid).focus();
		return false
	}
	else if(oprice > currentPrice || oprice < tagPriceMin || oprice > tagPriceMax)
	{
		var msg = "<b>Please enter a price between 10% to 99% of the current price.</b>";
		setmsg(msg, "brown", tagid);
		E("tagValue" + tagid).focus();
		return false
	}
	else if(oprice >= currentPrice)
	{
		var msg = "<b>Offer price is invalid. It must be below the current price.</b>";
		setmsg(msg, "brown", tagid);
		E("tagValue" + tagid).focus();
		return false
	}
	else
	{
		//E("cellControl_"+ tagid).style.display = "none";
		//E("cellProgress_" + tagid).style.display = "block";
		var res = simpleCall("tagupdate.jsp",{op:"change",tagid:tagid,offer:offer});
		if (res.status=="OK")
		{
			var email = authenticate();
			if(email)
			{
				var e=document.getElementById("puttag")	
				var sortBy = E("sortBy").value;				
				e.innerHTML=ajaxCallForText("myTagLimit",{email:email,sortBy:sortBy,lower:0});		
				
			}
		}
		else
		{
			alert("Could not change the offer price.\n" + res.message);
		}
	
	}
	
}
function dochange(el,tagid)
{
	var Cell = E(el + tagid);
	var offer = E("tagValue" + tagid).value;
	
	var tag = findTag(tagid);
	offer = String(offer).replace(/[^\d.-]*/gi, "");
	var oprice = parseFloat(offer);
	var tagPriceMin;
	tagPriceMin = tag.currentprice * 0.1;
	var tagPriceMax;
	tagPriceMax = tag.currentprice * 0.99;
	/*alert(oprice+"--oprice");
	alert(tag.currentprice+"--tag.currentprice");
	alert(tagPriceMin+"---tagPriceMin");
	alert(tagPriceMax+"---tagPriceMax");*/
	if (isNaN(oprice))
	{
		var msg = "<b>Please enter valid price. </b>";
		setmsg(msg, "brown", tagid);
		E("tagValue" + tagid).focus();
		return false
	}
	else if(oprice > tag.currentprice || oprice < tagPriceMin || oprice > tagPriceMax)
	{
		var msg = "<b>Please enter a price between 10% to 99% of the current price.</b>";
		setmsg(msg, "brown", tagid);
		E("tagValue" + tagid).focus();
		return false
	}
	else if(oprice >= tag.currentprice)
	{
		var msg = "<b>Offer price is invalid. It must be below the current price.</b>";
		setmsg(msg, "brown", tagid);
		E("tagValue" + tagid).focus();
		return false
	}
	else
	{
		//E("cellControl_"+ tagid).style.display = "none";
		//E("cellProgress_" + tagid).style.display = "block";
		var res = simpleCall("tagupdate.jsp",{op:"change",tagid:tagid,offer:offer});
		if (res.status=="OK")
		{
			var email = authenticate();
			if(email)
			{
			
				var sortBy = E("sortBy").value;
				//mtags is declared in the tag.js page
				mtags = getTags("mytag",{toolbarid:x54_toolbarid,email:email,sortBy:sortBy,tag_type:1});
				tag = findTag(tagid);
				Cell.innerHTML = addTag(tag);
				//showDiv(E("Item_" + tagid), "popup_" + tagid);
			}
		}
		else
		{
			alert("Could not change the offer price.\n" + res.message);
		}
	
	}
}

function showDiv(e)
{
	/*var Obj = findPos(this);
	var popupDiv = E(this.getAttribute("popupDiv"));
	popupDiv.style.left   = parseInt((Obj.x1 +  Obj.x2)/2) + "px";
	popupDiv.style.top = parseInt((Obj.y1 +  Obj.y2)/2) + "px";
	popupDiv.style.display   = "block";*/
}