﻿var loaded_panel = false;
var loaded_argument = "";
var firstTime = true;

function showAddPopup(argument, id) 
{
	if( document.getElementById("fhchatname") != null && document.getElementById("fhchatname").innerHTML == "") 
	{
	/*	if( argument == "Wishlist")
			argument = "AddWish";
		var url = "http://coolio.ro/?"+argument.toLowerCase();
		if (id != "" && id != null)
			url += "&id="+id;
		window.location = url;*/
		$find('ctl00_SidebarAnonymous_MPELoginUser').show();
		return;						    
	}
	
    var modalPopupBehavior = $find('ctl00_MPEAddPurchase');

    if (id != "" && id != null)
    	argument = argument + "/" + id;
    
    if( !loaded_panel || loaded_panel && loaded_argument != argument)
    {
		loaded_panel = true;
		// remove script
	/*	var scripts = document.getElementsByTagName("head")[0].getElementsByTagName("script");
		for( var i = 0; i < scripts.length; i++)
			if( scripts[i].src && scripts[i].src.indexOf("ChatService") > 0)
			{
				scripts[i].parentNode.removeChild(scripts[i]);
				break;
			}	  */
		__doPostBack('ctl00$upAddPurchase',argument);
		loaded_argument = argument;
	}
    modalPopupBehavior.show();
}
function OnFailure(error)
{ 
	alert(error.get_message());
}		
   
function getBrandText(ev) 
{ 
	var brand = $get('ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_ProductSelectorBrand_TextBoxSearch').value;
	var service = new BrandShopData();
	service.GetBrandData( brand, onGetBrandTextSuccess, OnFailure);
}
function onGetBrandTextSuccess( result)
{
	var brandDescriptionTextBox = $get('ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_PaneBrand_content_TextBoxBrandDescription');
	var brandLogoImg = $get( 'ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_PaneBrand_content_PicBrand');
	
	brandDescriptionTextBox.value = result.description;
	if( result.imageurl != "")
		brandLogoImg.src = result.imageurl;
}

function getShopText(ev) 
{ 
	var shop = $get('ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_ProductSelectorShop_TextBoxSearch').value;
	var location = $get('ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_ProductSelectorLocation_TextBoxSearch').value;
	if( location != '')
	{
		var service = new BrandShopData();
		service.GetShopData( shop, location, onGetShopTextSuccess, OnFailure);
	}
}
function onGetShopTextSuccess( result)
{
	var shopAddressTextBox = $get('ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_PaneShop_content_TextBoxLocation');
	var shopUrlTextBox = $get('ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_PaneShop_content_TextBoxShopUrl');
	var shopDescriptionTextBox = $get('ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_PaneShop_content_TextBoxShopDescription');
	var shopLogoImg = $get( 'ctl00_AddPurchaseControl_ListViewPurchase_ctrl0_PaneShop_content_PicShop');
	
	shopDescriptionTextBox.value = result.description;
	if( result.imageurl != "")
		shopLogoImg.src = result.imageurl;
	shopAddressTextBox.value = result.address;
	shopUrlTextBox.value = result.url;
}
var timer = null;
function showAddDropdown()
{
	$find("ctl00_PopExDropdown").showPopup();
}
function addLinkMouseOver()
{
	timer = setTimeout( "showAddDropdown();", 500);
}
function addLinkMouseOut()
{
	clearTimeout( timer);
}

if( typeof(Sys.WebForms) != "undefined")
{
	var prm = Sys.WebForms.PageRequestManager.getInstance();

	prm.add_initializeRequest(InitializeRequest);
	prm.add_endRequest(EndRequest);
}		 

function InitializeRequest(sender, args) 
{
	document.body.style.cursor = 'wait'; 
}

function EndRequest(sender, args) 
{
	document.body.style.cursor = 'auto';
}