function E(id){
   return (typeof(id)==="string") ? document.getElementById(id) : id;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


function isURL(str)
{
    return /^http|https|www/.test(str);
}

function setmsg(msg, clr){
	clr = clr || "black";
	var el = E("message");
	if (el) {
	   el.style.color=clr;
	   el.innerHTML = msg;
	}
}

function getbox(elem){
   var vport = (document.compatMode=='CSS1Compat') ? document.documentElement : document.body;
	if (typeof(elem.getBoundingClientRect) != 'undefined'){
		var b = elem.getBoundingClientRect();
		b.left -= 3;
		return {x:b.left+vport.scrollLeft,y:b.top+vport.scrollTop,w:b.right-b.left,h:b.bottom-b.top};
	} else {
		var x=0,y=0;
		var w = elem.offsetWidth;
		var h = elem.offsetHeight;
		while(elem){
			x += elem.offsetLeft;
			y += elem.offsetTop;
			elem = elem.offsetParent;
		}
		return {x:x,y:y,w:w,h:h};
	}
}

var urlparams=[];
function geturlparam (name){
   if (urlparams.length == 0) {
      var url = window.document.URL.toString();
      if (url.indexOf("?") > 0){
         var query = url.split("?")
         var params = query[1].split("&")

         for (var i=0;i<params.length;i++){
            var param =  params[i].split("=")
            var pname = param[0].toLowerCase();
            if (param[1] != "")
              urlparams[pname] = unescape(param[1])
         }
      }
   }
   return urlparams[name.toLowerCase()];
}
    
    
if (window.location.hostname == "nethaggler.com") {
	window.location.replace(window.location.href.replace("nethaggler.com","www.nethaggler.com"));
} //TODO- need to change this to 301 redirect

var nhkatz = [
   {}, //dummy to make the list 1-based
	{catname:"Apparel",			tagcms:"0.20"},
	{catname:"Babies & Kids",	tagcms:"0.30"},
	{catname:"Books",			tagcms:"0.30"},
	{catname:"Cell Phones",		tagcms:"0.70"},
	{catname:"Computers",		tagcms:"0.70"},
	{catname:"Electronics",		tagcms:"0.70"},
	{catname:"Flowers & Gourmet",tagcms:"0.30"},
	{catname:"Health & Beauty",	tagcms:"0.40"},
	{catname:"Home & Garden",	tagcms:"0.30"},
	{catname:"Jewelry & Watches",tagcms:"0.20"},
	{catname:"Magazines",		tagcms:"0.70"},
	{catname:"Movies",			tagcms:"0.35"},
	{catname:"Music",			tagcms:"0.30"},
	{catname:"Musical Instruments",tagcms:"0.50"},
	{catname:"Office",			tagcms:"0.60"},
	{catname:"Photography",		tagcms:"0.75"},
	{catname:"Software",		tagcms:"0.65"},
	{catname:"Sporting Goods",	tagcms:"0.30"},
	{catname:"Toys",			tagcms:"0.30"},
	{catname:"Video Games",		tagcms:"0.30"},
	{catname:"Other",			tagcms:"0.20"}
];
function paintkatz1(){
	var cls = "mevenrow";
	for (var idx=1;idx < nhkatz.length; idx++){ // start with 1
		cls = cls == "mevenrow" ? "moddrow" : "mevenrow";
		document.write("<tr class='" + cls + "'>");
		document.write("<td>&nbsp;</td>");
		document.write("<td align='left'>" + nhkatz[idx].catname + "</td>");
		document.write("<td align='center'><input style='padding-right:4px;text-align:right;' id='nc" + idx + "' name='nc" + idx + "' type='text' size='8'></td>");
		idx++;
		if (idx < nhkatz.length) {
			document.write("<td>&nbsp;</td>");
			document.write("<td align='left'>" + nhkatz[idx].catname + "</td>");
			document.write("<td align='center'><input style='padding-right:4px;text-align:right;' id='nc" + idx + "' name='nc" + idx + "' type='text' size='8'></td>");
		} else {
			document.write("<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
		}
		document.write("</tr>");

	}
}
function paintkatz2(){
	var cls = "mevenrow";
	for (var idx=1;idx < nhkatz.length; idx++){ // start with 1
		cls = cls == "mevenrow" ? "moddrow" : "mevenrow";
		document.write("<tr class='" + cls + "'>");
		document.write("<td>&nbsp;</td>");
		document.write("<td align='left'>" + nhkatz[idx].catname + "</td>");
		document.write("<td align='center'>" + nhkatz[idx].tagcms + "</td>");
		idx++;
		if (idx < nhkatz.length) {
			document.write("<td>&nbsp;</td>");
			document.write("<td align='left'>" + nhkatz[idx].catname + "</td>");
			document.write("<td align='center'>" + nhkatz[idx].tagcms + "</td>");
		} else {
			document.write("<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
		}
		document.write("</tr>");

	}
}

var merchantportal = false;
function logobar(mportal){
   merchantportal = mportal;
	var enableSearch = false;
	
	document.write('<table cellspacing="0" cellpadding="0" style="width:960px"><tr>');
	if (mportal){
		document.write(' <td style="width:240px"><a href="index.htm"><img border="0" src="images/logo6.gif"></a><td>');
		document.write(' <td style="padding:20px 0 0 20px;width:240px;font-family:arial;color:rgb(0,100,220);font-size:24px;">Merchant Portal<td>');
	} else {
		document.write(' <td style="width:480px"><img src="images/logo6.gif"><td>');
	}
	document.write(' <td style="padding-top:6px;width:270px;" valign="middle">');
	
	if (enableSearch) {
		document.write('<form style="display:inline;" id="searchbox_002531112394832850047:wavmhqcdelk" action="http://www.nethaggler.com/search.htm">');
		document.write('<input type="hidden" name="cx" value="002531112394832850047:wavmhqcdelk" />');
		document.write('<nobr><input name="q" type="text" size="30" ID="q"/>&nbsp;<input type="submit" name="sa" value="Search" /></nobr>');
		document.write('<input type="hidden" name="cof" value="FORID:11" />');
		document.write('<br>Search Haggler-Enabled<sup style="font-size:9px">SM</sup> Stores');
		document.write('</form>');
	} else {
		document.write('&nbsp;');
	}
	
	document.write(' </td>');
	document.write(' <td style="text-align:center;width:210px;vertical-align:middle"><span id="authentic"></span></td>');
	document.write('</tr></table>');
}

function tmover(ev,el){
	if (el.src.indexOf("g1") < 0)
		el.src = el.src.replace("c1","b1");
}

function tmout(ev,el){
	if (el.src.indexOf("g1") < 0)
		el.src = el.src.replace("b1","c1");
}

var items = [
	{name:"home",link:"index.htm"},
	{name:"works",link:"howitworks.htm"},
	//{name:"tags",link:"mytags.htm"},
	{name:"tags",link:"Postlogin.htm"},
	/*{name:"heaven",link:"hagglerheaven.htm"},*/
	{name:"about",link:"about.htm"}
];

var myaccountmenu = [
	{label:"Dashboard",link:"merchant_dashboard.html"},
	{label:"Store Profile",link:"merchant_storeprofile.html"},
	{label:"My Profile",link:"merchant_profile.html"},
	{label:"Nag Fee",link:"merchant_nagfee.html"},
	{label:"Tag Fee",link:"merchant_tagfee.html"},
	{label:"Product Feed",link:"merchant_productfeed.html"},
   {label:"FAQs",link:"merchant_faqs.html"}
];

var mmenu = [
	{name:"merchanthome",link:"merchant_gateway.html"},
	{name:"solutions",link:"merchant_solutions.html"},
	{name:"register",link:"merchant_signup.html"},
	{name:"myaccount",link:"merchant_dashboard.html",submenu:myaccountmenu},
	{name:"contactus",link:"merchant_contact.html"}
];

function submenuHTML(menu, ind){
	var html = "<div id='tabsG'><ul >";
	for (var i = 0; i < menu.length; i++){
	   var cls = i===ind ? "class='curtab'" : "";
		html += "<li " + cls + "><a class='menubody' href='" + menu[i].link + "'><span>" + menu[i].label + "</span></a></li>";
	}
	
	return html + "</ul></div>";
}

var merchantportal = false;
function topnavbar(current_tab)
{
	//alert(current_tab);
	document.write('<table width="100%" border=0 style="border-bottom:1px solid #cccccc;"><tr>');
		document.write('<td width="191" style="padding-top:4px;padding-left:4px;" ><img src="logo.jpg" /></td>');
		document.write('<td width="37" >&nbsp;</td>');
		document.write('<td style="vertical-align:bottom;">');
			document.write('<table width="100%" border=0  cellpadding="0" cellspacing="0" >');
				document.write('<tr><td width=100% align="right"  style="padding-top:2px;padding-right:4px;" id="authentic"></td></tr>');
				document.write('<tr><td width=100% align=right valign="bottom">');
					document.write('<div id="tabs6">');
					document.write('<ul>');
					
					if(current_tab == "home")
						document.write('<li id="home" class="current" ><a href="default.jsp"><span>Home</span></a></li>');
					else
						document.write('<li id="home"><a href="default.jsp"><span>Home</span></a></li>');

					if(current_tab == "how_it_works")
						document.write('<li id="how_it_works" class="current"><a href="howitworks_new.jsp"><span>How it Works</span></a></li>');
					else
						document.write('<li id="how_it_works"><a href="howitworks_new.jsp"><span>How it Works</span></a></li>');
					
					if(current_tab == "my_tags")
						document.write('<li id="my_tags" class="current" onclick="authentiCall(1);"><a href="#" ><span>MyAccount</span></a></li>');
					else
						document.write('<li id="my_tags"><a href="Postlogin.htm"><span>MyAccount</span></a></li>');
					
					if(current_tab == "about_us")
						document.write('<li id="about_us" class="current"><a href="about_new.htm"><span>About Us</span></a></li>');
					else
						document.write('<li id="about_us" ><a href="#" temphref="about_new.htm"><span>About Us</span></a></li>');
					
					document.write('</ul>');
					document.write('</div>');
				document.write('</td></tr>');
			document.write('</table>');
		document.write('</td></tr>');
	document.write('</table>');

}

function header(cp,strt){
	doheader(strt,items);
}
function merchantmenu(){
	doheader(null,mmenu);
}


function doheader(strt,items){
   var url = document.URL;
   var level1 = -1;
   var level2 = -1;
   var bg = "images/menubg3.gif";
   var ht = "50px";
   var submenu;

   var i,j;
	for (i=0; i < items.length && level1 === -1; i++){
	   if (url.indexOf(items[i].link) !== -1) {
	      level1 = i;
	   }
	   if (items[i].submenu) {
	      var sub = items[i].submenu;
      	for (j=0; j < sub.length && level2 === -1; j++){
      	   if (url.indexOf(sub[j].link) !== -1) {
      	      level1 = i;
      	      level2 = j;
               bg = "images/menubg4.gif";
               ht = "75px";
               submenu = submenuHTML(sub, level2);
      	   }
      	}
	   }
	}
	
	document.write('<table class="panel" cellSpacing="0" cellPadding="0" ><colgroup><col width="750px"></col><col width="*"></col></colgroup>');
	document.write('<tr><td valign="top" style="padding-left:8px;padding-top:8px;height:' + ht + ';background-image:url(' + bg + ');background-repeat:no-repeat;text-align:left;">');
	document.write('<table><tr>');
	for (i=0; i < items.length; i++){
		var cls = i === level1 ? "-g1.gif" : "-c1.gif";
		document.write('<td><a href="' + items[i].link + '"><img onmouseover="tmover(event,this)" onmouseout="tmout(event,this)" border="0" src="images/' + 
			items[i].name + cls + '"><a></td>');
	}
	document.write("</tr></table>");
	if (submenu){
	   document.write(submenu);
	}
	
	document.write('</td><td align="center" style="padding-left:6px;padding-top:0px">');
	if (strt){
		document.write('<a href="toolbar/NetHaggler.exe"><img border="0" src="images/startnowbtn.gif"></a>');
	} else {
		document.write('<a href="download.htm"><img border="0" src="images/downloadbtn3.gif"></a>');
	}
	document.write('</td></tr></table>');
}

function advertise(){
		document.write('<a href="download.htm"><img border="0" src="images/toolbar.gif" ></a>');
}

function loginpop(inline){
   var title=merchantportal?"Merchant Login" : "Login";
   var cls = inline ? "inlinelogin" : "draglogin";
	document.write("<form onsubmit='dologin();return false;'> \
	<table class='" + cls + "' cellpadding=0 cellspacing=0 id='loginpanel'> \
	<colgroup><col width='108px'/><col width='252px'/></colgroup> \
	<tr><th colspan='2' style='background-color:gray' id='logintitle'><img onclick='hidelogin()' src='images/closebtn.gif' style='float:right;cursor:pointer;margin:2px 1px;' />" + title + "</th></tr> \
	<tr><td colspan='2' style='font-size:5px;'>&nbsp;</td></tr> \
	<tr><td align='right' width='107px'><span class='red'>*</span> Email Address :</td><td width='245px'  align='left'><input type='text' id='loginemail' style='width:90%'></td></tr> \
	<tr><td align='right' width='107px'><span class='red'>*</span> Password :</td><td align='left' width='245px'><input type='password' id='loginpassword' style='width:90%'></td></tr> \
	<tr><td>&nbsp;</td><td align='left' width='245px' ><button type='submit'>Login</button></td></tr> \
	<tr><td colspan='2' style='padding:6px;font-weight:bold;color:brown;' id='loginmessage'>&nbsp;</td></tr> \
	</table> \
	</form>");
}

function howItWorks(){
	document.write('<table width="200px" cellSpacing="0" cellPadding="0" >\
	<tr><td class="sidetop">How it Works</td></tr>\
	<tr><td class="sidemiddle"><table cellpadding="3" cellspacing="2" >\
	<colgroup><col width="10"></col><col width="*"></col></colgroup>\
	<tr><td><img src="images/one.gif"></td><td><b>Download</b> a small toolbar for your browser</td></tr>\
	<tr><td><img src="images/two.gif"></td><td><b>Start Shopping</b> on any site supported by NetHaggler</td></tr>\
	<tr><td><img src="images/three.gif"></td><td><b>Tag/Nag/Haggle</b> for an item that you would like to buy</td></tr>\
	<tr><td><img src="images/four.gif"></td><td><b>Get the Best Deal</b> when the item reaches your preferred price.</td></tr>\
	<tr><td colspan="2" align="right"><a href="howitworks.htm">Learn More &gt;&gt;</a></td></tr>\
	</table></td></tr><tr><td class="sidebottom"></td></tr><tr><td>&nbsp;</td></tr></table>');
}

function nhwhat(){
	document.write('<table width="200px" cellSpacing="0" cellPadding="0" >\
	<tr><td class="sidetop">What’s NetHaggler?</td></tr>\
	<tr><td class="sidemiddle"><table cellpadding="3" cellspacing="2" >\
	<colgroup><col width="10"></col><col width="*"></col></colgroup>\
	<tr><td colspan="2">NetHaggler is a shopping companion toolbar and a community of savvy shoppers.\
		<p>With NetHaggler\'s Hagglebar, shoppers can:</td></tr>\
	<tr><td><img src="images/one.gif"></td><td><b>Tag</b> an item at a price they desire</td></tr>\
	<tr><td><img src="images/two.gif"></td><td><b>Nag</b> the merchant for a lower price</td></tr>\
	<tr><td><img src="images/three.gif"></td><td><b>Haggle</b> as a group for bargain rates</td></tr>\
	</table></td></tr><tr><td class="sidebottom"></td></tr><tr><td>&nbsp;</td></tr></table>');
}
function nhwhy(){
	document.write('<table width="200px" cellSpacing="0" cellPadding="0" >\
	<tr><td class="sidetop">Why NetHaggler?</td></tr>\
	<tr><td class="sidemiddle"><table cellpadding="3" cellspacing="2" >\
	<colgroup><col width="10"></col><col width="*"></col></colgroup>\
	<tr><td><img src="images/one.gif"></td><td>No Upfront Costs</td></tr>\
	<tr><td><img src="images/two.gif"></td><td>Pay only for Leads and/or Transactions</td></tr>\
	<tr><td><img src="images/three.gif"></td><td>Innovative Concepts</td></tr>\
	<tr><td><img src="images/four.gif"></td><td>Generate incremental sales</td></tr>\
	</table></td></tr><tr><td class="sidebottom"></td></tr><tr><td>&nbsp;</td></tr></table>');
}
function nhnext(){
	document.write('<table width="200px" cellSpacing="0" cellPadding="0" >\
	<tr><td class="sidetop">Next Steps</td></tr>\
	<tr><td class="sidemiddle"><table cellpadding="3" cellspacing="2" >\
	<colgroup><col width="10"></col><col width="*"></col></colgroup>\
	<tr><td><img src="images/one.gif"></td><td style="cursor:pointer;" onclick="takeatour()"><u><b>View</b> a Tour</a></u></td></tr>\
	<tr><td><img src="images/two.gif"></td><td><a href="merchant_genfaqs.html"><b>Read</b> FAQs</a></td></tr>\
	<tr><td><img src="images/three.gif"></td><td><a href="merchant_contact.html"><b>Request</b> a Meeting</a></td></tr>\
	<tr><td><img src="images/four.gif"></td><td><a href="merchant_signup.html"><b>Register</b></a></td></tr>\
	</table></td></tr><tr><td class="sidebottom"></td></tr><tr><td>&nbsp;</td></tr></table>');
}

function nextSteps(){
	//<tr><td><img src="images/one.gif"></td><td><a href="#" onclick="showDemo()"><b>View</b> Demo</a></td></tr>
	document.write('<table width="200px" cellSpacing="0" cellPadding="0">\
	<tr><td class="sidetop">Next Steps</td></tr>\
	<tr><td class="sidemiddle"><table cellpadding="3" cellspacing="2" >\
	<colgroup><col width="10"></col><col width="*"></col></colgroup>\
	<tr><td><img src="images/one.gif"></td><td><a href="download.htm"><b>Download</b> Hagglebar</a></td></tr>\
	<tr><td><img src="images/two.gif"></td><td style="cursor:pointer;" onclick="takeatour()"><u><b>Take</b> a Tour</a><u></td></tr>\
	<tr><td><img src="images/three.gif"></td><td><a href="howitworks.htm"><b>Learn</b> How it Works</a></td></tr>\
	<tr><td><img src="images/four.gif"></td><td><a href="contactus.htm"><b>Contact</b> Us</a></td></tr>\
	</table></td></tr><tr><td class="sidebottom"></td></tr><tr><td>&nbsp;</td></tr></table>');
}

var dalist=null;
var datimer;
function activetopover(ev,el){
	el.className="activesidetop";
}
function activetopout(ev,el){
	el.className="sidetop";
}
function showstores(ev,el){
	window.location="stores.htm";
}
function supportedStores(){
	//<tr><td><img src="images/one.gif"></td><td><a href="#" onclick="showDemo()"><b>View</b> Demo</a></td></tr>
	var stores = getStores("availableVendorsForMainPage",{});
	var len = stores.length;
	if (stores && len>0){
		//document.write('<table width="200px" cellSpacing="0" cellPadding="0">\
		//<tr><td class="sidetop" style="cursor:pointer" onmouseover="activetopover(event,this)" onmouseout="activetopout(event,this)" onclick="showstores(event,this)">Supported Stores</td></tr>\
		//<tr><td class="sidemiddle" style="height:40px;padding:6px 6px 6px 12px;">');
		
		document.write('<div onmouseover="clearTimeout(datimer)" onmouseout="datimer=setTimeout(scrollit, 50)" style="border-bottom:2px lightgrey solid;line-height:20px;position:relative;width:100%;height:150px;overflow:hidden;"><div id="slist" style="position:absolute">');
		for (var i = 0; i < len + 15; i++) {
			var store = stores[i%len];
			document.write('<a class="topnavlink1" href="' + store.url + '">' + store.name + '</a><br>');	
		}
		document.write('</div></div><div>');
		//document.write('</td></tr><tr><td class="sidemiddle" style="padding-left:12px"></td></tr><tr><td class="sidebottom"></td></tr></table>');
		datimer=setTimeout(scrollit, 50);
	}
}

function contactUs(){
	document.write('<table width="200px" cellSpacing="0" cellPadding="0">\
	<tr><td class="sidetop">Contact Us</td></tr>\
	<tr><td class="sidemiddle"><table cellpadding="6" cellspacing="2" >\
	<colgroup><col width="10"></col><col width="*"></col></colgroup>\
	<tr><td><img src="images/one.gif"></td><td><a href="contactus.htm?type=pr">Press Inquiries</td></tr>\
	<tr><td><img src="images/two.gif"></td><td><a href="contactus.htm?type=merchant">Merchant Relations</td></tr>\
	<tr><td><img src="images/three.gif"></td><td><a href="contactus.htm?type=bizdev">Biz Dev Inquiries</td></tr>\
	<tr><td><img src="images/four.gif"></td><td><a href="contactus.htm?type=info">General Questions</td></tr>\
	<tr><td><img src="images/one.gif"></td><td><a href="contactus.htm?type=feedback">Feedback</td></tr>\
	</table></td></tr><tr><td class="sidebottom"></td></tr><tr><td>&nbsp;</td></tr></table>');
}


function scrollit(){
	if (!dalist)
		dalist = document.getElementById("slist");
	var par = dalist.parentNode || dalist.parentElement;
	if (dalist.offsetTop <= par.offsetHeight - dalist.offsetHeight)
		dalist.style.top = "0px";
	else 
		dalist.style.top = (dalist.offsetTop-1) + "px";
	datimer = setTimeout(scrollit, 50);
}

function showDemo(){
	window.open("media/demo.swf", "demo", "status=0,toolbar=0");
}

function gotQuestions(){
	//<tr><td><img src="images/one.gif"></td><td><a href="#" onclick="showDemo()"><b>View</b> Demo</a></td></tr>
	document.write('<table width="200px" cellSpacing="0" cellPadding="0" ID="Table6">\
	<tr><td class="sidetop">Got Questions?</td></tr>\
	<tr><td class="sidemiddle"><table cellspacing="3" style="font-size:12px" ID="Table3">\
	<colgroup><col width="20"></col><col width="*"></col></colgroup>\
	<tr><td><img src="images/two.gif"></td><td><a href="faq.htm"><b>Browse</b> FAQs</a></td></tr>\
	<tr><td><img src="images/three.gif"></td><td><a href="privacy.htm"><b>Read</b> Privacy Policy</a></td></tr>\
	<tr><td><img src="images/one.gif"></td><td><a href="addaddress.htm"><b>Add us</b> to your address book</a></td></tr>\
	<tr><td><img src="images/four.gif"></td><td><a href="contactus.htm?type=info">Contact Us</td></tr>\
	</table></td></tr><tr><td class="sidebottom"></td></tr><tr><td>&nbsp;</td></tr></table>');
}					

function takeatour(){
	window.open('http://www.nethaggler.com/tour.htm', 'tour','left=80,top=80,directories=no,width=800,height=440,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=yes,toolbar=no');
}

function tellfriend(){
	document.write('<table style="margin-bottom:8px;width:200px" cellSpacing="0" cellPadding="0" ID="Table6">\
	<tr><td style="text-align:center"><a href="tell_friends.htm"><img border="0" src="images/tell2.gif"></a></td></tr>\
	</table>');
}

function footer()
{
	document.write('<br /><a class="topnavlink1" href="terms.htm" title="coming soon">Terms of Use</a>&nbsp;|\
	<a class="topnavlink1" href="privacy.htms">Privacy Policy</a>&nbsp;|\
	<a class="topnavlink1" href="contact.htm">Contact Us</a>&nbsp;\
	<hr width="25%">&copy; 2007 NetHaggler.com. All Rights Reserved.<br />');
	
	//<a class="topnavlink1"  href="about.htm">About Us</a>&nbsp;|\
	//<a class="topnavlink1" href="faq.htm">FAQ</a>&nbsp;|\
	//<a class="topnavlink1" href="tips.htm">Safety Tips</a>&nbsp;|\
	//<a class="topnavlink1" href="promote.htm">Promote!</a>&nbsp;|\
	//<a class="topnavlink1" href="tell_friends.htm">Advertise</a>&nbsp;|\
	//<a class="topnavlink1" href="international.htm">NetHaggler International</a>&nbsp;<br />\
}
/**
* Open a connection to the specified URL, which is
* intended to respond with an XML message.
* 
* @param string url    The URL to connect to.
* @param string toSend The data to send to the server; must be URL encoded.
*/
var req;
function xmlOpen(url, toSend) {
	if (window.ActiveXObject) {
		// try XMLHTTP ActiveX (Internet Explorer) version
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		if (window.XMLHttpRequest) {
		// browser has native support for XMLHttpRequest object
			req = new XMLHttpRequest();
		}
	}
	if (req) {
		try {
			if (!toSend || toSend.length==0){
				toSend = "dummy=dummy";
			}
			req.open("POST", url, false);
			req.setRequestHeader("content-type", "application/x-www-form-urlencoded");
			req.send(toSend);
			
			/*var obj = document.getElementById("ajax_spn");
			obj.innerText += "url: " + url + "<br>";
			obj.innerText += "toSend: " + toSend + "<br>";*/
			
		}
		catch (e) {
		
			//alert("Ajax call to " + url + " failed");
		}
	} else {
		alert("Your browser does not seem to support XMLHttpRequest.");
	}
}
//return a value of the child tag in an xml
function getChildValue(parentNode, childTag) {
	var list = parentNode.getElementsByTagName(childTag);
	var val = list.length > 0 ? nodeValue(list[0]) : "";
	var xval = "x" + val;
	return (xval === "xnull" || xval === "xundefined" ? "" : val);
}
//value of a node called from getChildValue
function nodeValue(node) {
	var val = null;
	if (node && node.childNodes && node.childNodes.length > 0) {
		val = node.childNodes[node.childNodes.length - 1].nodeValue;
	}
	return val;
}

//we call this function to make an ajax call
function xmlCall(url, obj) {
	var toSend = "";
	for (var e in obj) {
		if (toSend.length > 0) {
			toSend += "&";
		}
		toSend += e + "=" + encodeURI(obj[e]);
	}
	//alert(url+"?"+toSend);
	xmlOpen(url, toSend);
	//alert("hi");
	//return "<name>dinesh</name>";
	return (req && req.readyState == 4 && req.status == 200) ? req.responseXML : null;
}
// this function is called when user retag a item from haggler heaven page. it returns all teh information abt the last tag
function getMyTagData(obj)
{
//alert('get my tag data');
	var xdoc = xmlCall(getBasePath()+"/getMyTagData",obj);
	
	if (xdoc)
	{
	  	var list = xdoc.getElementsByTagName("tag");
		
		if(list.length>0)
		{
		var tag = list.item(0);
		var vendorName = getChildValue(tag,"vendorName");
		var creationDate=getChildValue(tag,"creationDate");
		var priceWhenTagged=getChildValue(tag,"priceWhenTagged");
		var expired=getChildValue(tag,"expired");
		var currentPrice=getChildValue(tag,"currentPrice");
		var targetPrice=getChildValue(tag,"targetPrice");
		var shortDescription=getChildValue(tag,"shortDescription");
		var URL=getChildValue(tag,"URL");
		var imageUrl=getChildValue(tag,"imageUrl");
		var description=getChildValue(tag,"description");		
		if(description.length > 200)
			description = subStr(description,200);
		var listPrice=getChildValue(tag,"listPrice");		
		
		return {vendorName:vendorName,creationDate:creationDate,priceWhenTagged:priceWhenTagged,expired:expired,currentPrice:currentPrice,targetPrice:targetPrice,shortDescription:shortDescription,URL:URL,imageUrl:imageUrl,description:description,listPrice:listPrice};
		}
		
	}
	return null;
		
}
// this function is retrieving the data for the filled ocf form on the confirm click button (the data was saved last time when we clecked cancel)
// obj must contain product id ;
function getCancelNagData(obj)
{
//alert('getCancel nag data');
	//xdoc is an xml file got from ajax response  ..the xml file contains the temporary data of ocf form which was saved during cancelltaion or other tab click
	var xdoc = xmlCall("GetCancelNagData",obj);
	
	if (xdoc)
	{
	    //list object contains the ocf form data as there is only on head tag nag inside tghis tag we have all the data
		var list = xdoc.getElementsByTagName("nag");
		var done=false;
		if(list.length>0)
		{
		var tag = list.item(0);
		var date = getChildValue(tag,"date");
		var fname=getChildValue(tag,"fname");
		var lname=getChildValue(tag,"lname");
		var units=getChildValue(tag,"units");
		var pricePaid=getChildValue(tag,"pricePaid");
		var ocn=getChildValue(tag,"ocn");
		var email=getChildValue(tag,"email");
		var tempId=getChildValue(tag,"id");
		
		return {tempId:tempId,email:email,date:date,fname:fname,lname:lname,units:units,pricePaid:pricePaid,ocn:ocn};
		}
		return null;
	}
	return null;
		
}
//get the whole tags as an xml data
//returns array of tags objects
function getTags(url, obj, max, uniq)
{
	//xodc contains a no of tag node which has child node containg correspondign data of that node. this xml has all teh tags
	var xdoc = xmlCall(url,obj);
	var tags = [];
	var urls = [];
	if (xdoc)
	{
		var list = xdoc.getElementsByTagName("tag");
		//alert(list +" length="+list.length);
		max = Math.min(max?max:list.length, list.length);
		var done=false;
		//alert(max);
		for (var n = 0; tags.length < max && n < list.length; n++)
		{
			var tag = list.item(n);
			var producturl = getChildValue(tag,"producturl");
			if (!producturl || producturl.length == 0 || (uniq && urls[producturl])) 
			{
				continue;
			}
			
			if (uniq) {urls[producturl] = true;}
			var productid = getChildValue(tag,"productid");
			var shortdesc = getChildValue(tag,"shortdesc");
			var longdesc = getChildValue(tag,"longdesc");
			var tagdate = getChildValue(tag,"tagdate");
			var imageurl = getChildValue(tag,"imageurl");
			var tagid = getChildValue(tag,"tagid");
			var tagtype = getChildValue(tag,"tagtype");
			var vendorname = getChildValue(tag,"vendorname");
			var pricewhentagged = getChildValue(tag,"pricewhentagged");
			var targetPrice = getChildValue(tag,"targetPrice");
			var currentprice = getChildValue(tag,"currentprice");
			var expired = getChildValue(tag,"expired");
			pricewhentagged = parseFloat(pricewhentagged);
			targetPrice = parseFloat(targetPrice);
			currentprice = parseFloat(currentprice);
			
			tags.push({
				productid:productid,
				id:tagid,
				tagid:tagid,
				tagtype:tagtype,
				producturl:producturl,
				vendorname:vendorname,
				shortdesc:shortdesc,
				longdesc:longdesc,
				tagdate:tagdate,
				imageurl:imageurl,
				pricewhentagged:pricewhentagged,
				targetPrice:targetPrice,
				currentprice:currentprice,
				expired:expired
			});
		
		}
	}
	//alert(tags+"  --->tags length="+tags.length);
	return tags;
}


//used to return the articles
function getArticles()
{
	var xdoc = xmlCall("articles.xml",null);
	var articles = [];
	if(xdoc)
	{
		var list= xdoc.getElementsByTagName("article");		
		max = list.length;		
		var done=false;
		for (var n = 0; n < max; n++)
		{
			var article = list.item(n);
			var link = getChildValue(article,"link");
			var id = getChildValue(article,"id");
			link=link+'&id='+id				
			var details = getChildValue(article,"details");
			var author = getChildValue(article,"author");
			var header=	getChildValue(article,"header");
			var header=	getChildValue(article,"header");		
			articles.push({
				link:link,
				details:details,
				author:author,
				header:header				
			});
		
		}
	}
	return articles;	

}
function getTagsPriceDrope(url, obj, max, uniq)
{
	//xodc contains a no of tag node which has child node containg correspondign data of that node. this xml has all teh tags
	var xdoc = xmlCall(url,obj);
	var tags = [];
	var urls = [];
	if (xdoc)
	{
		var list = xdoc.getElementsByTagName("tag");
		max = Math.min(max?max:list.length, list.length);
		var done=false;
		for (var n = 0; tags.length < max && n < list.length; n++)
		{
			var tag = list.item(n);
			var producturl = getChildValue(tag,"producturl");
			//alert(producturl);
			/*if(producturl == 'SW52YWxpZCB0b2tlbiBzcGVjaWZpZWQuIA==')
			{
				alert('Due to some internal problem latest price drop can not be shown');
				break; 
			}	*/
			if (!producturl || producturl.length == 0 || (uniq && urls[producturl])) 
			{
				continue;
			}
			
			if (uniq) {urls[producturl] = true;}
			var productid = getChildValue(tag,"productid");
			var shortdesc = getChildValue(tag,"shortdesc");
			var longdesc = getChildValue(tag,"longdesc");
			var tagdate = getChildValue(tag,"tagdate");
			var imageurl = getChildValue(tag,"imageurl");
			var tagid = getChildValue(tag,"tagid");
			var tagtype = getChildValue(tag,"tagtype");
			var vendorname = getChildValue(tag,"vendorname");
			var pricewhentagged = getChildValue(tag,"pricewhentagged");
			var targetPrice = getChildValue(tag,"targetPrice");
			var currentprice = getChildValue(tag,"currentprice");
			var expired = getChildValue(tag,"expired");
			pricewhentagged = parseFloat(pricewhentagged);
			targetPrice = parseFloat(targetPrice);
			currentprice = parseFloat(currentprice);
			
			tags.push({
				productid:productid,
				id:tagid,
				tagid:tagid,
				tagtype:tagtype,
				producturl:producturl,
				vendorname:vendorname,
				shortdesc:shortdesc,
				longdesc:longdesc,
				tagdate:tagdate,
				imageurl:imageurl,
				pricewhentagged:pricewhentagged,
				targetPrice:targetPrice,
				currentprice:currentprice,
				expired:expired
			});
		
		}
	}
	return tags;
}

//get all teh haggles as an xml and return teh array of haggles object
function getHaggles(url, obj, max, uniq){
	var xdoc = xmlCall(url,obj);
	var haggles = [];
	var urls = [];
	if (xdoc){
		var list = xdoc.getElementsByTagName("haggle");
		max = Math.min(max?max:list.length, list.length);
		var done=false;
		for (var n = 0; haggles.length < max && n < list.length; n++){
			var haggle = list.item(n);
			var buyurl = getChildValue(haggle,"buyurl");
			
			if (!buyurl || buyurl.length == 0 || (uniq && urls[buyurl])) {
				continue;
			}
			
			if (uniq) {urls[buyurl] = true;}
			var shortdesc = getChildValue(haggle,"shortdesc");
			var longdesc = getChildValue(haggle,"longdesc");
			var hagaledate = getChildValue(haggle,"hagaledate");
			var targetPrice = getChildValue(haggle,"targetprice");
			var pricewhenhagged = getChildValue(haggle,"pricewhenhagged");
			var vendorname = getChildValue(haggle,"vendorname");
			var currentprice = getChildValue(haggle,"currentprice");
			var imageurl = getChildValue(haggle,"imageurl");
			var haggleid = getChildValue(haggle,"haggleid");
			var productid = getChildValue(haggle,"productid");
			//var expired = getChildValue(haggle,"expired");
			//var status = getChildValue(haggle,"status");
			var lastmodified  = getChildValue(haggle,"lastmodified");
			var quantity  = getChildValue(haggle,"quantity");
			var title = getChildValue(haggle,"title");
			var keywords = getChildValue(haggle,"keywords");
			var metadesc = getChildValue(haggle,"metadesc");
			var hagglegroupid = getChildValue(haggle,"hagglegroupid");
			var activesignup = getChildValue(haggle,"activesignup");
			var issystemgenrated = getChildValue(haggle,"issystemgenrated");
			var maxprice =  getChildValue(haggle,"maxprice");
			var minprice = getChildValue(haggle,"minprice");
			var signuprequried =  getChildValue(haggle,"signuprequried");
			var medianprice = getChildValue(haggle,"medianprice");
			var nagid = getChildValue(haggle,"nagid");
			var tagid = getChildValue(haggle,"tagid");
			
			targetPrice = parseFloat(targetPrice);
			pricewhenhagged = parseFloat(pricewhenhagged);
			currentprice = parseFloat(currentprice);
			haggleid =  parseInt(haggleid);
			productid = parseInt(productid);
			quantity = parseInt(quantity);
			hagglegroupid  = parseInt(hagglegroupid);
			activesignup = parseInt(activesignup);
			maxprice = parseFloat(maxprice);
			minprice = parseFloat(minprice);
			signuprequried = parseInt(signuprequried);
			medianprice = parseFloat(medianprice);
			nagid = parseInt(nagid);
			tagid = parseInt(tagid);
			if(longdesc.length > 100)longdesc = subStr(longdesc.trim(),100) + "&nbsp;<a target='_blank' href='buyurlhandler.jsp?uri=" + buyurl + "'>more..</a>";
			
			
			haggles.push({
				shortdesc: subStr(shortdesc,20),
				buyurl:buyurl,
				shortpopdesc:shortdesc,
				longdesc:longdesc,
				hagaledate: dateFormat(hagaledate,"/"),
				targetPrice: targetPrice.toFixed(2),
				pricewhenhagged: pricewhenhagged.toFixed(2),
				vendorname: vendorname.trim(),
				currentprice: currentprice.toFixed(2),
				imageurl: imageURL(imageurl),
				haggleid: haggleid,
				productid :productid,
				lastmodified : dateFormat(lastmodified,"/"),
				quantity :quantity,
				title :title,
				keywords :keywords,
				metadesc :metadesc,
				hagglegroupid :hagglegroupid,
				activesignup :activesignup,
				issystemgenrated :issystemgenrated,
				maxprice :maxprice.toFixed(2),
				minprice :minprice.toFixed(2),
				signuprequried :signuprequried,
				medianprice: medianprice.toFixed(2),
				nagid:nagid,
				tagid:tagid
			});
		}
	}
	return haggles;
}



function getNags(url, obj, max, uniq){
	var xdoc = xmlCall(url,obj);
	var nags = [];
	var urls = [];
	if (xdoc){
	//returns an array containing nag status
		var list = xdoc.getElementsByTagName("error-session");		
		if(list.length==1)
		{
			v= {session:'expired'};
			return v;
					
		}
		else
		{
		var list = xdoc.getElementsByTagName("nag");
		max = Math.min(max?max:list.length, list.length);
		var done=false;
		for (var n = 0; nags.length < max && n < list.length; n++){
			var nag = list.item(n);
			var producturl = getChildValue(nag,"producturl");
			
			if (!producturl || producturl.length == 0 || (uniq && urls[producturl])) {
				continue;
			}
			
			if (uniq) {urls[producturl] = true;}
			var shortdesc = getChildValue(nag,"shortdesc");
			var longdesc = getChildValue(nag,"longdesc");
			var nagdate = getChildValue(nag,"nagdate");
			var targetPrice = getChildValue(nag,"targetPrice");
			var pricewhennagged = getChildValue(nag,"pricewhennagged");
			var vendorname = getChildValue(nag,"vendorname");
			var currentprice = getChildValue(nag,"currentprice");
			var imageurl = getChildValue(nag,"imageurl");
			var nagid = getChildValue(nag,"nagid");
			var productid = getChildValue(nag,"productid");
			var expired = getChildValue(nag,"expired");
			
			var status = getChildValue(nag,"status");
			var messagetouser  = getChildValue(nag,"messagetouser");
			var messagetovendor  = getChildValue(nag,"messagetovendor");
			var confirmationemail = getChildValue(nag,"confirmationemail");
			var ouroffer = getChildValue(nag,"ouroffer");
			var discount = getChildValue(nag,"discount");
			var datepurchased = getChildValue(nag,"datepurchased");
			var dateclickthru = getChildValue(nag,"dateclickthru");
			var orderstatus = getChildValue(nag,"orderstatus");
			var buydayleft =  getChildValue(nag,"buydayleft");
			var ocfdayleft = getChildValue(nag,"ocfdayleft");
			var buyhourleft = getChildValue(nag,"buyhourleft");
			//alert(buyhourleft + " b4 parseint");
			targetPrice = parseFloat(targetPrice);
			pricewhennagged = parseFloat(pricewhennagged);
			currentprice = parseFloat(currentprice);
			nagid = parseInt(nagid);
			expired = parseFloat(expired);
			status = parseInt(status);
			ouroffer = parseInt(ouroffer);
			discount = parseFloat(discount);
			orderstatus = parseInt(getChildValue(nag,"orderstatus"));
			buyhourleft = parseInt(buyhourleft);
			//alert(buyhourleft + "after parse int");
			//buydayleft = parseInt(buydayleft);
			//ocfdayleft = parseInt(ocfdayleft);
			//alert(status);
			nags.push({
				productid:productid,
				id:nagid,
				producturl:producturl,
				vendorname:vendorname,
				shortdesc:shortdesc,
				longdesc:longdesc,
				nagdate:nagdate,
				imageurl:imageurl,
				pricewhennagged:pricewhennagged,
				targetPrice:targetPrice,
				currentprice:currentprice,
				expired:expired,
				status:status,
				messagetouser:messagetouser,
			  	messagetovendor:messagetovendor,
				confirmationemail:confirmationemail,
				ouroffer:ouroffer,
				discount:discount,
				datepurchased:datepurchased,
				dateclickthru:dateclickthru,
				orderstatus:orderstatus,
				buydayleft:buydayleft,
				ocfdayleft:ocfdayleft,
				buyhourleft:buyhourleft
			});
		}
		}
	}
	return nags;
}


var x54disabled = [];
x54disabled["hermes"]=true;
x54disabled["ashford"]=true;
x54disabled["ikea"]=true;
function getStores(url, obj){
	var xdoc = xmlCall(url,obj);
	var stores = [];
	if (xdoc){
		var list = xdoc.getElementsByTagName("store");
		for (var n = 0; n < list.length; n++){
			var store = list.item(n);
			var name = getChildValue(store,"name");
			var url = getChildValue(store,"url");
			stores.push({name:name,url:url});
			/*
			if (!x54disabled[url.split(".")[1].toLowerCase()]){			
				stores.push({name:name,url:url});
			}
			*/
		}
	}
	return stores;
}

function simpleCall(url,obj) {
	var xdoc = xmlCall(url,obj);
	//alert("xdoc"+xdoc)
	var status, message;

	if (xdoc){
		status = getChildValue(xdoc,"status");
		message = getChildValue(xdoc,"message");
	} else {
		status = "ERROR";
		message = "We are sorry, our web server is experiencing problems. Please try again later.";
	}
	return {status:status,message:message};
}

function centerIt(panel)
{
	if (typeof(panel)=="string")
	{
		panel = document.getElementById(panel);
		var st = panel.style;
		var spos = x54dom.spos();
		var cs = x54dom.clientsize();
		var ds = x54dom.docsize();
		st.display = "block";
		st.left = (spos.x + ((cs.w - panel.offsetWidth)>>1)) + "px";
		st.top = (spos.y + ((cs.h - panel.offsetHeight)>>1)) + "px";
		
	}
}

function whoami(){
	var name = "";
	var email = "";
	var xdoc = xmlCall(getBasePath()+"/whoami.jsp",{});	
	var stores = [];
	if (xdoc){
		name = getChildValue(xdoc,"name");
		email = getChildValue(xdoc,"email");
		var list = xdoc.getElementsByTagName("store");
		if (list) {
		   for (var i=0; i < list.length; i++) {
		      var store = list.item(i);
		      var id = getChildValue(store,"id");
		      var sname = getChildValue(store,"sname");
		      var url = getChildValue(store,"url");
		      stores.push({id:id,sname:sname,url:url});
		   }
		}
		
	}	
	return {name:name,email:email,stores:stores};
}

var x54_toolbar = null;
var x54_email = "";
var x54_toolbarid = "";
function ToolBarInit(tool){
	x54_toolbar = tool;
	x54_toolbarid = tool.toolbarid;
	x54_email = tool.userId;
}

var nostoresmsg = "There are no stores for this email. Please register a store or login with another email.";
function authentiCall(mode)
{ 
   if (!me) {
      me = whoami();
      //alert(me)
   }     
	var email = me.email;	
	if (!email || email.length == 0) {	
		showlogin();
	} else if (merchantportal && me.stores.length === 0) {
	   showlogin(nostoresmsg);
	} else if (typeof onlogin === 'function') 
	{
		if(mode){
			onlogin(x54_toolbarid, email,mode);
			}
		else{
		  //alert("on login method calling")
			onlogin(x54_toolbarid, email);
			}
	}
}
function authenticate()
{
   if (!me) {
      me = whoami();
   }
	var email = me.email;
	if (!email || email.length == 0) 
	{
		showlogin();
	} 
	else if (merchantportal && me.stores.length === 0) 
	{
	   showlogin(nostoresmsg);
	} 
	else if (typeof onlogin === 'function') 
	{
		return email;
	}
	return false;
}

function showlogin(msg){
	nhAcc = E('nhAccountSignIn');
	fbAcc = E('fbAccountSignIn');
	if(nhAcc != null && fbAcc != null)
	{
		nhAcc.style.display = "";
		fbAcc.style.display = "none";
	}
	var panel = document.getElementById("loginpanel");
	if (panel){
		centerIt("loginpanel");
		var emailfld = document.getElementById("loginemail");
		var pwdfld = document.getElementById("loginpassword");
		if(x54_email==undefined)
		x54_email=""
		emailfld.value = x54_email;
		pwdfld.value= "";
		if (x54_email.length == 0)
			emailfld.focus();
		else
			pwdfld.focus();
		document.getElementById("loginmessage").innerHTML = msg ? msg : "&nbsp;";
		if (typeof Drag === "object"){
		   Drag.enable(E("logintitle"), E("loginpanel"));
		}
	}
}

function dologin(){

	var email = document.getElementById("loginemail").value;
	var pwd = document.getElementById("loginpassword").value;
	var msgbox = document.getElementById("loginmessage");
	var msg = null;
	var focusfld = "loginemail";
	if (email == null || email.length == 0 || !validEmail(email)) {
		msg = "Please enter a valid email address.";
	} else if (pwd == null || pwd.length == 0) {
		msg = "Please enter your password.";
		focusfld = "loginpassword";
	} 
	else 
	{
		var xdoc = xmlCall(getBasePath()+"/signin.jsp",{email:email,password:pwd});
		if (!xdoc)
			msg = "Sorry, there was a problem. Please try again later.";
		else {
			var status = getChildValue(xdoc,"status");
			if (status != "OK") {
				msg = getChildValue(xdoc,"message");
			}
		}
	}
	if(msg=='This user is not authenticated yet.')
		msg +=' <a href="authenticate.jsp">Not Received Authentication mail</a>';
	if (msg) {
		msgbox.innerHTML = msg;
		document.getElementById(focusfld).focus();
	} else {
		if (x54_toolbar)
			x54_toolbar.userId = email;
		x54_email = email;
		
		hidelogin();
		fixup();
		if (typeof onlogin === 'function') {
			authentiCall();
		}
	}
}

function dologout(){
	xmlCall("signout.jsp",{});
	fixup();
	if (typeof onlogout === 'function') {
		onlogout();
	}
	
	if (typeof onlogin === 'function') {
	   showlogin();   
	}
}

function hidelogin(){
	document.getElementById("loginpanel").style.display="none";
}

function validEmail(s){

	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return filter.test(s);
}
function validUrl(url){
	var filter = /^(http|https):\/\/([\w-]+\.)+[\w-]+(:\d+)?(\/[\w- .\/?%&=#]*)?$/;
	return filter.test(url.toLowerCase());
}

function validUri(uri){
	var filter = /^(http|https|ftp):\/\/([\w-]+:.+@)?([\w-]+\.)+[\w-]+(:\d+)?(\/[\w- .\/?%&=#]*)?$/;
	return filter.test(uri.toLowerCase());
}

var me;
function fixup(){
	me = whoami();
	var spn = document.getElementById("authentic");
	var panel = document.getElementById("loginpanel");
	var searchArea = "<input id=\"searchCntlGlobal\" onkeypress=\"formSubmitGlobal(event,'globalSearch')\" type=\"text\" maxlength=\"35\" =\"heaven_tx_area\" value=\"Search\" onfocus=\"if(this.value == 'Search')this.value='';this.style.color='#000000'\" onblur=\"if(this.value == ''){this.value='Search';this.style.color='#999999'}\" /><input id=\"globalSearch\" type=\"button\" onclick=\"getGlobalSearch()\" class=\"heaven_go_btn\" />"
	if (spn && panel) {
		if (me.email.length>0){
			spn.innerHTML = searchArea+"Welcome <b>" + me.name + "</b>&nbsp;|&nbsp;<a href='Logout' class='topnavlink1' onclick='logoutFB();'>Logout</a>";
		} else{
			spn.innerHTML = searchArea+"<a class='topnavlink1' href='#' onclick='showlogin()'>Login</a> &nbsp;|&nbsp; <a class='topnavlink1' href='register.jsp' title=' Nethaggler- Online Shopping Store'>Register</a>";
		}
	}
}


function getBasePath()
{
	var basepath="";
	if(location.pathname.indexOf("home") != -1)
		basepath="http://"+window.location.host+"/home";
	else
		basepath="http://"+window.location.host;
	return basepath;
}
function tellFriends()
{
	if(whoami().email.length == "" || whoami().email == null)
		return authentiCall();
	else
		location.href = "TellFriend"; 
}

function signInAccountHandler(val)
{
	nhAcc = E('nhAccountSignIn');
	fbAcc = E('fbAccountSignIn');
	if(val == 0)
	{
		nhAcc.style.display = "";
		fbAcc.style.display = "none";
	}
	else
	{
		nhAcc.style.display = "none";
		fbAcc.style.display = "";
	} 
	
}
//For callback facebook   
 
function facebooklogin(fid,infb,productId,actionType,currentPrice,url,templateId,imageUrl,vendername,shortdesc,longdesc,hreflink)
{ 	
	var email="";		
	if(infb!="fbemailpop")
	{
		hidelogin();
		var xdoc = null;		
		xdoc = xmlCall(getBasePath()+"/facebook",{fid:fid,op:'checkemail'});	
		if (xdoc)		
			email = getChildValue(xdoc,"errMsg");		
		if(email=="")
			showEmailPopup(fid,infb);
		else
		{
			hm();
			fixup();
			javascript: self.close ();
		}
		//javascript: self.close ();
	}
	else
	{
		//alert("Else..");
		//document.getElementById("mbd").style.display="block";
		showEmailPopup(fid,infb,productId,actionType,currentPrice,url,templateId,imageUrl,vendername,shortdesc,longdesc,hreflink);
	}
	//javascript: self.close ();	
}
function showEmailPopup(fid,infb,productId,actionType,currentPrice,url,templateId,imageUrl,vendername,shortdesc,longdesc,hreflink)
{
	var mainDivRes = document.getElementById("popuptemp");		
	var html =" ";	
	html  = '<div class="dragloginFB" id="checkDiv">'
	if(infb=="fbemailpop")
	{
		html += '<div class="box_close"> <a style="cursor:pointer"><img src="http://www.nethaggler.com/images/login_closebtn.gif" alt="Close"  border="0" align="" onclick="hideloginFBin()"/></a></div>'
	}
	else
	{
		html += '<div class="box_close"> <a href="#"><img src="http://www.nethaggler.com/images/login_closebtn.gif" alt="Close"  border="0" align="" onclick="hideloginFB()"/></a></div>'
	}
	html += '	<div class="heading">'
	html += '		<h3> Email Address </h3>'
	html += '	</div>'
	html += '	<div class="login_backgroundfb">'	
	html += '		<center>	<span>*</span> Email Address : &nbsp;'
	html += '		<input type="text" onblur="trim_regExp(this);" onkeypress="formSubmit(\'submitbutton\' , event)"class="inpt_area" id="fbloginemail"><br />'
	html += '		<div class="error" align="center">'
	html += '			<span id="errMsg"></span>'
	html += '		</div> '
	if(infb=="fbemailpop")
		html += '		<input style="margin-top:5px;" onclick="fbUserStatus('+fid+',\''+infb+'\',\''+productId+'\',\''+actionType+'\',\''+currentPrice+'\',\''+url+'\',\''+templateId+'\',\''+imageUrl+'\',\''+vendername+'\',\''+shortdesc+'\',\''+longdesc+'\',\''+hreflink+'\');" id="submitbutton" value="Login" title="Login" alt="Login" type="submit" class="submitbutton" />'
	else
		html += '		<input style="margin-top:5px;" onclick="fbUserStatus('+fid+',\''+infb+'\');" id="submitbutton" value="Login" title="Login" alt="Login" type="submit" class="submitbutton" />'
	html += '		</center>'
	html += '		<div class="fl" style="margin-left:3px;width:400px;font-size:95%;"><span>*</span>To receive email alerts, Please enter email address.</div>'	
	html += '	</div>'
	html += '</div>'	
	mainDivRes.innerHTML =html;  	
	if(infb=="fbemailpop")
	{	
		showpoppasswordFBin(mainDivRes);
		//sm("popuptemp",100,100);
	}
	else
	{
		sm("popuptemp",390,200);
		E('mbox').style.backgroundColor = "transparent";
		E('mbox').style.border = "none";
	}
	
	if(infb=="fbemailpop")
	{	
	//	document.getElementById("ol").style.display="none";
		//document.getElementById("mbox").style.display="none";
	}
}

//used for popup any where just pass div
function showpoppasswordFBin(mainDivRes){
	if(x54dom.$(mainDivRes))
			{
				currentDlg.popup = x54dom.$(mainDivRes);
				window.onscroll = currentDlg.scroll
				currentDlg.scroll();
			}
}
function fbUserStatus(fid,infb,productId,actionType,currentPrice,url,templateId,imageUrl,vendername,shortdesc,longdesc,hreflink)
{	
	var msg="";
	var email="";
	var errfld="";
	E('errMsg').innerHTML = "";
	email = E('fbloginemail').value ;		
	email = trimChar(email);
	if (!email || email.length == 0 || !validEmail(email) )
	 {
	 		msg = "Please enter a valid email address like example@example.com";
			errfld = "fbloginemail";
			E('errMsg').innerHTML = msg;
					if (errfld.length > 0)
						E(errfld).focus();
	}
	else
	{		
		var xdoc = null;				
		xdoc = xmlCall(getBasePath()+"/facebookuser",{email:email,op:'emailvalidate',fid:fid});		
		msg = "";		
		msg = getChildValue(xdoc,"errMsg");			
		if(msg.indexOf("NH User") != -1)
		{
			msg  = "";			
			if(confirm("You are already a NetHaggler user, Do you want to access you account as a FaceBook user?"))
				xdoc = xmlCall(getBasePath()+"/facebookuser",{email:email,op:'nhUser',fid:fid});				
			else
				return;
							
		}
		if(msg!="" || msg.length != 0)
		{			
			errfld = "fbloginemail";
			E('errMsg').innerHTML = msg;	
		}
		else
		{			
			javascript: self.close ();
			if(infb != "fbemailpop")
			{
				fixup();				
				hm();
			}
			else
			{
			  
				hideloginFBin();	
				 if(actionType == "wishlist")	
				 {	
				   //added fbin variable for feed template should one time come		
				 	var fbin="fbin";
				 	//addToMyWishList(productId,currentPrice,fbin);
				 	if(addToMyWishList(productId,currentPrice,fbin))
				 		feedTemplate(templateId,imageUrl,productId,currentPrice,vendername,shortdesc,longdesc,hreflink);
				 }	
				 else if(actionType == "mytags")
				 {
				  currentDlg.showSharePopUP(productId,actionType);	
				  onTagClickWish(productId,0);
					 //setCurrentTag(currentPrice,productId,url);
				 	// authentiCall();	
				 	// feedTemplate(templateId,imageUrl,productId,currentPrice,vendername,shortdesc,longdesc,hreflink);			 	
				 }	
				 else if(actionType == "share")
				 currentDlg.showSharePopUP(productId,actionType);
				//location.reload();
			}
		}
	}
}
function hideloginFB()
{
	document.getElementById("ol").style.display="none";
	document.getElementById("mbox").style.display="none";
	authentiCall();
}

//for face book
function hideloginFBin()
{ 
	document.getElementById("popuptemp").style.display="none";	
	return;
}
 function checkobject(obj) {
 if (document.getElementById(obj)) { return true; } else { return false; }
 }
 
function mytagPopUp(pid)
{
	 var actionType = "mytags";	
	 currentDlg.showSharePopUP(pid,actionType);	
	 onTagClickWish(pid,0);	
}	
function pricedroppopup(pid)
{
	currentDlg.showPopUP(pid);
 	onTagClickWish(pid,0);	
 
}
	
 
