function AddToWishlist ( strPartNo, strgrpID, strLinkID )
{
	d = document.getElementById ( "add_wl_div" + strPartNo );

	strHTML = '';

	objAjax = new CAjax (); objAjax.create ();
	d.innerHTML = '<input type="text" id="wl_qty" value="Quantity" size="15"/><input type="submit" onclick="javascript:AddToWishlist2(\'' + strPartNo + '\', \'' + strgrpID + '\', \'' + strLinkID + '\', \'N/A\' );" value="Add now">&nbsp;<input type="button" value="Cancel" onclick="window.location.reload( true );" >';

	d.disabled = true;

	if ( objAjax.open ( "http://www.terrafirma4x4.com/wishlist.php?op=getpartprice&p=" + strPartNo, true ) )
	{
		strPrice = objAjax.getResponse ();

		if ( strPrice != 'invalid' )
		{
			d.innerHTML = '<b>Your Price: ' + strPrice + '</b> <input type="text" id="wl_qty" value="Quantity" size="15"/><input type="submit" onclick="javascript:AddToWishlist2(\'' + strPartNo + '\', \'' + strgrpID + '\', \'' + strLinkID + '\', \'' + strPrice + '\' );" value="Add now">&nbsp;<input type="button" value="Cancel" onclick="window.location.reload( true );" >';
			
		qty = document.getElementById ( "wl_qty" );
		if (qty) { d.disabled = false; qty.select (); qty.focus (); }
		}
	}

	d.disabled = false;

	qty = document.getElementById ( "wl_qty" );
	if (qty) qty.select ();
	
	EnableWishlist ();
}

function AddToWishlist2 ( strPartNo, strgrpID, strLinkID, strPrice )
{
	lnk = document.getElementById ( "add_wl_div" + strPartNo );
	qty = document.getElementById ( "wl_qty" );

	if ( parseInt ( qty.value ) <= 0 ) 
	{
		alert ( "Please enter a valid number in the quantity field." );
		qty.focus ();
	}

	lnk.innerHTML = "<b>Adding...</b>";

	objAjax = new CAjax ();
	objAjax.create ();

	if ( objAjax.open ( "wishlist.php?op=ap&p=" + strPartNo + "&g=" + strgrpID + "&q=" + qty.value + "&pr=" + strPrice, true ) )
	{
		document.getElementById ( "wishlist_placeholder" ).innerHTML = objAjax.getResponse ();
	}

	lnk.innerHTML = "<b>Done</b>";

	setTimeout ( "ChangeLinkTextForAddPart ( '" +  strPartNo + "', '" + strgrpID +"', '" + strLinkID + "' )", 200 );

	return false;
}

function getPriceForTFPart ( strPart, strIndex )
{
	d = document.getElementById ( "hor_zebra_" + strIndex );

	objAjax = new CAjax (); objAjax.create ();

	if ( objAjax.open ( "wishlist.php?op=getpartprice&p=" + strPart, true ) )
	{
		strPrice = objAjax.getResponse ();
		d.innerHTML = strPrice;

//		oaj2 = new CAjax (); oaj2.create ();
//		oaj2.open ( "wishlist.php?op=updatepartprice&p=" + strPart + "&i=" + strIndex, true );
	}
}

function ChangeLinkTextForAddPart ( strPartNo, strgrpID, strLinkID )
{
	lnk = document.getElementById ( "add_wl_div" + strPartNo );
	lnk.innerHTML = '<a id="link_'+ strPartNo + '" href="#" onClick="javascript:AddToWishlist ( \'' + strPartNo + '\', \'' + strgrpID + '\', \'link_'+strPartNo + '\'); return false;">Add to Wishlist</a>';
//	lnk.innerHTML = "Add to Wishlist";
}

function ClearWishlist ()
{
	if ( confirm ( "Are you sure you want to empty your wishlist?" ) )
	{
		objAjax = new CAjax ();
		objAjax.create ();
	
		if ( objAjax.open ( "wishlist.php?op=c", true ) )
		{
			document.getElementById ( "wishlist_placeholder" ).innerHTML = objAjax.getResponse ();
		}
	}
}

function DisplayEMailPage ()
{
	objAjax = new CAjax ();
	objAjax.create ();

	if ( objAjax.open ( "wishlist.php?op=ep", true ) )
		document.getElementById ( "email_div" ).innerHTML = objAjax.getResponse ();
}

function HideEmailSupplierTag() { document.getElementById ( "email_div" ).style.display = "none"; }

function EMailSupplier ()
{
	strCustomerName = document.getElementById ( 'full_name' ).value;
	strCustomerMail = document.getElementById ( 'email_user' ).value;
	strCustomerPhone = document.getElementById ( 'phone_no' ).value;
	strCustomerName = document.getElementById ( 'full_name' ).value;
	strSupplierMail = document.getElementById ( 'supplieremail' ).value;

	objAjax = new CAjax ();
	objAjax.create ();

	if ( strCustomerPhone == '' || strCustomerName == '' || strCustomerMail == '' )
	{
		alert ( "Please fill in all the fields and select Send EMail option." );
		return;
	}

	if ( strCustomerPhone == '' ) strCustomerPhone = 'Not Provided';

	if ( objAjax.open ( "wishlist.php?op=ew&supperlieremail=" + strSupplierMail + "&customername=" + strCustomerName + "&customermail=" + strCustomerMail + "&phone=" + strCustomerPhone, true ) )
	{
		document.getElementById ( "email_div" ).innerHTML = objAjax.getResponse ();
		alert ( objAjax.getResponse () );
	}
}

function DisableWishlist ()
{
	if ( document.getElementById ( "wishlist_vp_id" ) )
	{
		element = document.getElementById ( "wishlist_vp_id" );
		element.disabled = true;
	}
}

function EnableWishlist ()
{
	if ( document.getElementById ( "wishlist_vp_id" ) )
	{
		element = document.getElementById ( "wishlist_vp_id" );
		element.disabled = false;
	}
}

function DisplayDistributorDetails ( country, area )
{
	aj = new CAjax (); aj.create ();
	div = document.getElementById ( "distributor_details_id" );	
	if ( aj.open ( "/wishlist.php?op=gdd&country=" + country + "&area=" + area, true ) ) 
	{
		div.innerHTML = aj.getResponse ();
		div.style.display = "";
	}
}

function logoutFromTP ()
{
	if ( ! confirm ( "Are you sure you want to logout from Trade Portal?" ) )
		return;
	aj = new CAjax (); aj.create ();
	if ( aj.open ( "/wishlist.php?op=logouttp", true ) ) 
	{
		window.location.reload ();
	}
}
