// global variables
var applicationUrl = "http://www.e-ducan.com/b2b";

function closeWindow()
{
	window.close();
}

function updateParentRegistration(name, id)
{
	opener.document.forms[0].txtSubcategoryID.value = id
	opener.document.forms[0].txtSubcategory.value = name
	self.close()
	return false;
}

function showDescription(id)
{
	myWindow = window.open('../help/showDescription.aspx?id=' + id,'description',config='status=0,resizable=1,scrollbars=1,menubar=0,width=450,height=300');
	myWindow.focus();
	myWindow.moveTo(0, 0);
}

function openSubWindow(url)
{
	var category = document.getElementById('ddlCategory');
	var subcategory = document.getElementById('txtSubcategory');
	if (category.selectedIndex <= 0)
	{
		subcategory.value = "";
		return false;
	}
	var categoryID = category.value;
	var myWindow = window.open(url + '?categoryID=' + categoryID, 'subcategories', config='height=450,width=350,status=0,location=0,resizable=1,scrollbars=1')
	myWindow.moveTo(30, 30);
	myWindow.focus();
	return false;
}

function findUser()
{
	var file = 'pickUser.aspx'
	var window = "win2";
	childWindow=open(file,window,'screenX=0,screenY=0,width=300,height=380,resizable=no,scrollbars=no,toolbar=no,status=no,directories=no,menubar=no,location=no');
	if (childWindow.opener == null) childWindow.opener = self;
}

function viewProfile(customerID)
{
	win = window.open(applicationUrl + '/accountServices/viewProfile.aspx?profileID=' + customerID, 'profile', config='status=0,resizable=1,scrollbars=1,menubar=0,width=850');
	win.moveTo(0, 0);
	win.focus();
}

function selectDate()
{
    myWin = window.open('pickDate.aspx', 'selectDate', config='location=0,status=0,height=230,width=220')
    myWin.moveTo(15, 15);
    myWin.focus();
    return false
}

function showPicture(url, width, height)
{
	if (width == null)
	{
		width = 650;
	}
	if (height == null)
	{
		height = 400;
	}
    myWin = window.open(applicationUrl + '/offers/showPicture.aspx?url=' + url, 'picturePopUp', config='toolbar=0,menubar=0,width=' + width + ',height=' + height + ',location=0,status=0');
    myWin.opener = self;
    myWin.moveTo(15, 15);
    myWin.focus();
}

function openDetails(companyID)
{
	myWin = window.open(applicationUrl + '/sys/profile.aspx?customerID=' + companyID, 'profile', config='status=0,resizable=1,scrollbars=1,menubar=0,width=900,height=700');
	myWin.opener = self;
	myWin.moveTo(15, 15);
	myWin.focus();
}

function activateMyAccount(id)
{
	opener.location.href('../accountServices/activateMyAccount.aspx?id=' + id)
	self.close()
}

function textRemainedRegistration_description(maxLength)
{
	var remainedCh = parseInt(maxLength) - parseInt(document.all.txtDescription.value.length);
	var result;
	if (remainedCh < 0)
	{
		document.all.txtDescription.style.color = "#FE0101";
		document.all.txtChRemained.style.color = "#FE0101";
		document.all.txtChRemained.innerText = remainedCh;
	}
	else
	{
		//document.all.txtChRemained.value = remainedCh + '/' + maxLength;
		document.all.txtChRemained.innerText = "(" + remainedCh + "/" + maxLength + ")";
		document.all.txtDescription.style.color = "#000000";
		document.all.txtChRemained.style.color = "#000000";
	}
}

function gotoShopping(url)
{
	window.open(url, 'shoppingWindow');
	self.close();
}

function bold()
{
	control = document.all.txtOfferDesc;
	button = document.all.btnBold;
	control.focus();
	if (button.value == '  B  ')
	{
		control.value += '[b]';
		button.value = ' *B ';
	}
	else
	{
		control.value += '[/b]';
		button.value = '  B  ';
	}
}

function italic()
{
	control = document.all.txtOfferDesc;
	button = document.all.btnItalic;
	control.focus();
	if (button.value == '  I  ')
	{
		control.value += '[i]';
		button.value = ' *I ';
	}
	else
	{
		control.value += '[/i]';
		button.value = '  I  ';
	}
}

function underline()
{
	control = document.all.txtOfferDesc;
	button = document.all.btnUnderline;
	control.focus();
	if (button.value == '  U  ')
	{
		control.value += '[u]';
		button.value = ' *U ';
	}
	else
	{
		control.value += '[/u]';
		button.value = '  U  ';
	}
}

function email()
{
	control = document.all.txtOfferDesc;
	button = document.all.btnEmail;
	control.focus();
	if (button.value == 'Email')
	{
		control.value += '[email]';
		button.value = '*Email';
	}
	else
	{
		control.value += '[/email]';
		button.value = 'Email';
	}
}

function url()
{
	control = document.all.txtOfferDesc;
	button = document.all.btnUrl;
	control.focus();
	if (button.value == 'Hyperlink')
	{
		control.value += '[url]';
		button.value = '*Hyperlink';
	}
	else
	{
		control.value += '[/url]';
		button.value = 'Hyperlink';
	}
}

function addToFavorites()
{
    window.external.AddFavorite(location.href, "e-ducan B2B - " + document.title);
}

function viewTemplateOffer(url)
{
	myWin = window.open(url, 'templateOffer', config='width=' + screen.width-screen.width/3 + ',height=' + screen.height-screen.height/3 + ',resizable=1,status=0,scrollbars=1');
	myWin.moveTo(30, 30);
	myWin.focus();
}

function PageIsLoading()
{
	var div = document.getElementById("divMessage");
	div.style.position = "absolute";
	div.style.background = "#ffffff";
	div.style.border = "1px solid #666666";
	div.style.width = "250px";
	// image preloading
	var imgLogo = new Image();
	imgLogo.src = applicationUrl  + "/images/duca_02.gif";
	
	var imgProgressBar = new Image();
	imgProgressBar.src = applicationUrl  + "/images/progressBar_1.gif";
	
	div.innerHTML = "<table border=0 width=100% style='color:#666666;' cellpadding=10><tr><td align=center valign=middle><img src='" + imgLogo.src + "'><p><font size=2>Stranica se u&#269;itava...</font></p><p><font size=2>Page is loading...</font></p><br><img src='" + imgProgressBar.src + "'></td></tr></table>";
	/*div.style.top = screen.height/2 - 160;
	div.style.left = screen.width/2 - 125;*/
	div.style.zIndex = "999";
	div.style.top = document.body.offsetHeight/2 - 160;
	div.style.left = document.body.offsetWidth/2 - 125;
	div.style.visibility = "visible";
}

function PageIsLoaded()
{
	var div = document.getElementById("divMessage");
	div.style.visibility = "hidden";
}

function PreloadImages()
{
	var images = new Array();
	images[0] = "images/buttons/about_over.gif";
	images[1] = "images/buttons/contact_over.gif";
	images[2] = "images/buttons/contactNow_over.gif";
	images[3] = "images/buttons/home_out.gif";
	images[4] = "images/buttons/index_over.gif";
	images[5] = "images/buttons/offerList_over.gif";
	images[6] = "images/buttons/productList_over.gif";
	images[7] = "images/buttons/sendInquiry_over.gif";
	images[8] = "images/buttons/sendCancel/cancel_over.gif";
	images[9] = "images/buttons/sendCancel/send_over.gif";
	
	for (i=0; i<images.length; i++)
	{
		var image = new Image();
		image.src = images[i];
	}
}

function CreateXmlHttpRequestObject()
{
    var xmlObj;
    if (window.ActiveXObject)
    {
        try
        {
           xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e)
        {
           xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
        }
    }
    else
        xmlObj = new XMLHttpRequest();
        
    return xmlObj;
}
