AttachEvent(window, "load", resizeWindow);
AttachEvent(window, "load", window_onload);
AttachEvent(window, "unload", window_onunload);
//window.attachEvent("onload", resizeWindow);
window.returnValue = false;

/* Cross-browser compatibility functions */
var isIE = document.all;
var isNetscape = !document.all && document.getElementById;

function EventTarget(e) {
	if(typeof(e.srcElement) != 'undefined')
		return e.srcElement;
	else if(typeof(e.target) != 'undefined')
		return e.target;
}
function EventType(e) {
	if(e.type)
		if(e.type.substring(0,2) == 'on')
			return e.type.substring(2);
		else 
			return e.type;
}
function AttachEvent(obj, eventType, eventHandler) {
	if (typeof(obj.attachEvent) == 'object')
		obj.attachEvent('on' + eventType, eventHandler);
	else if (typeof(obj.addEventListener) == 'function')
		obj.addEventListener(eventType, eventHandler, false);
}

function DetachEvent(obj, eventType, eventHandler) {
	if (typeof(obj.detachEvent) == 'object')
		obj.detachEvent('on' + eventType, eventHandler);
	else if (typeof(obj.removeEventListener) == 'function')
		obj.removeEventListener(eventType, eventHandler, false);	
}

function FireEvent(obj, eventType) {
	if (typeof(obj.fireEvent) == 'object')
		obj.fireEvent('on' + eventType);
	else if (typeof(obj.dispatchEvent) == 'function')
		obj.dispatchEvent(eventType);	
}
/* End of Cross-browser compatibility functions */

var frameWidth = 4;
var frameHeight = 30;
function window_onunload() 
{
	var x = window.screenLeft;
	var y = window.screenTop;
	
	window.dialogLeft = x - frameWidth;
	window.dialogTop = y - frameHeight;
}
function window_onload()
{
	//Do not count on these values as the dialog will be moved if outside of screen area and we have no way of knowing this
	//frameWidth = window.screenLeft - parseInt(window.dialogLeft);
	//frameHeight = window.screenTop - parseInt(window.dialogTop);
}

function openPopup(FrameUrl, showStatus)
{
	var dlgAttributes = "dialogTop:100px; dialogLeft:100px; dialogHeight:400px; dialogWidth:500px; resizable:yes; help:no; scroll:yes;";
	var dlgAttrMozilla = "top=100px, left=100px, height=220px, width=400px, resizable=yes, help=no, scroll=no, toolbar=no, titlebar=no, menubar=no, location=no,";
	if (isNetscape) {
		if (showStatus) {
			open(FrameUrl , "_blank", dlgAttrMozilla + "status=yes");
		} else {
			open(FrameUrl , "_blank", dlgAttrMozilla + "status=no");
		}
	} else {
		if (showStatus) {
			return window.showModalDialog(FrameUrl, '', dlgAttributes + " status: yes");
		} else {
			return window.showModalDialog(FrameUrl, '', dlgAttributes + " status: no");	
		}
	}
}

function openPopup(FrameUrl, showStatus, w, h)
{
	var dlgAttributes = "dialogTop:100px; dialogLeft:100px; dialogHeight:" + h + "; dialogWidth:" + w + "; resizable:yes; help:no; scroll:yes;";
	var dlgAttrMozilla = "top=100px, left=100px, height=" + h + ", width=" + w + ", resizable=yes, help=no, scroll=no, toolbar=no, titlebar=no, menubar=no, location=no,";
	if (isNetscape) {
		if (showStatus) {
			open(FrameUrl , "_blank", dlgAttrMozilla + "status=yes");
		} else {
			open(FrameUrl , "_blank", dlgAttrMozilla + "status=no");
		}
	} else {
		if (showStatus) {
			return window.showModalDialog(FrameUrl, '', dlgAttributes + " status: yes");
		} else {
			return window.showModalDialog(FrameUrl, '', dlgAttributes + " status: no");	
		}
	}
}

function openPopupLarge(FrameUrl, showStatus)
{
	var dlgAttributes = "dialogTop:100px; dialogLeft:100px; dialogHeight:500px; dialogWidth:550px; resizable:yes; help:no; scroll:yes;";
	var dlgAttrMozilla = "top=100px, left=100px, height=220px, width=400px, resizable=yes, help=no, scroll=no, toolbar=no, titlebar=no, menubar=no, location=no,";
	if (isNetscape) {
		if (showStatus) {
			open(FrameUrl , "_blank", dlgAttrMozilla + "status=yes");
		} else {
			open(FrameUrl , "_blank", dlgAttrMozilla + "status=no");
		}
	} else {
		if (showStatus) {
			return window.showModalDialog(FrameUrl, '', dlgAttributes + " status: yes");
		} else {
			return window.showModalDialog(FrameUrl, '', dlgAttributes + " status: no");	
		}
	}
}

function openPBPopup(popupPath, rootPath, controlID) {
	var result = openPopup(popupPath,rootPath);
	if(result) {
		alert(__doPostBack(controlID, result));
	}
	return true;
}
function openPBPopup(FrameUrl, controlID) {
	var result = openPopup(FrameUrl);
	if(result) {
		alert(__doPostBack(controlID, result));
	}
	return true;
}
function openNoPBPopup(FrameUrl) {
	window.showModalDialog(FrameUrl, "resizable: yes; help: no; dialogHeight: 100px; dialogWidth: 200px; scroll: no; status: no");
	return false;
}
function cancelPopup() {
	top.returnValue = false;
	top.close();
}
function closePopup() {
	top.returnValue = true;
	top.close();
}
function returnPopup(value) {
	top.returnValue = value;
	top.close();
}
function resizeWindow() {
	//correct with 8 by 47 pixels for the Titlebar, Statusbar and Window border
	top.dialogWidth  = (document.body.scrollWidth + 8) + "px";
	top.dialogHeight = (document.body.scrollHeight + 47) + "px";
	
}
function minWindowSizeSet(x,y){	
	if(parseInt(top.dialogWidth) < x && x != 0)
	{
		top.dialogWidth = x + "px";
	}
	if(parseInt(top.dialogHeight) < y && y != 0)
	{
		top.dialogHeight = y + "px"
	}
}
function windowSizeSet(x,y){	
	top.dialogWidth = x + "px";
	top.dialogHeight = y + "px";
	top.resizeTo(x,y);
}
function setFocus(control){
	if( control != null && typeof(control)!="undefined"){
		control.focus(); 
	}
}
function setImageSrc(imgID, newSrc) {
	var imgControl = document.getElementById(imgID);
	if (imgControl)
		imgControl.src = newSrc;
}
function setImageFromFile(imgID, fileID)
{
	if (document.getElementById(imgID) != null && document.getElementById(fileID) != null)
		document.getElementById(imgID).src = document.getElementById(fileID).value;
}

function rollover(imgID) {
	var img = document.getElementById(imgID);
	if (img != null)
	{
		if (img.src.indexOf("_on.gif") == -1)
		{
			img.src = img.src.substring(0, img.src.length - 4) + "_on.gif";
		}
	}
}

function rollout(imgID) {
	var img = document.getElementById(imgID);
	if (img != null)
		img.src = img.src.substring(0, img.src.length - 7) + ".gif";
}

function enterSubmit(id) {
	if(isIE && event && event.keyCode == 13) {
		if(document.getElementById(id) != null)
			document.getElementById(id).click();
		else
			id.click();
		return false;
	}
	return true;
}

function buttonPress(id) {
	if(event) {
		document.getElementById(id).click();
		return false;
	}
	return true;
}

function printDocument() {
	window.print(); 
	top.returnValue = true; 
	top.close();
}

function swapDisplay(toShow, toHide) {
	document.getElementById('div'+toShow).style.display = '';
	document.getElementById('div'+toHide).style.display = 'none';
	document.getElementById('link'+toShow).className = 'WhiteButActive';
	document.getElementById('link'+toHide).className = 'WhiteBut';
}

function show(controlId) {
	var control = document.getElementById(controlId);
	if (control) control.style.display = '';
}

function hide(controlId) {
	var control = document.getElementById(controlId);
	if (control) control.style.display = 'none';
}

function updateTotalPrice(MinQuantity, tbQuantityId, singlePrice, lbTotalPriceId) {
	var tbQuantity		= document.getElementById(tbQuantityId);
	var lbTotalPrice	= document.getElementById(lbTotalPriceId);
	var quantity		= parseFloat(tbQuantity.value);
	var price			= parseFloat(singlePrice.replace(',', '.'));

	if (tbQuantity && lbTotalPrice && !isNaN(quantity) && !isNaN(price)) {
		if (quantity < parseFloat(MinQuantity)) quantity = parseFloat(MinQuantity);
		tbQuantity.value		= quantity;
		lbTotalPrice.innerText	= (quantity * price).toFixed(2).replace('.', ',');
	} else {
		tbQuantity.value		= '';
		lbTotalPrice.innerHTML	= '';
	}
}
function setColorOfOrderProduct(color, colorId, sizeId) {
	var colorSelect = document.getElementById(colorId);
	if (colorSelect && colorSelect.value != color) {
		colorSelect.value = color;
		FireEvent(colorSelect, 'change');
	}
}

/* SITEMAP JS FUNCTIONS START */
var Sitemap_MouseOverStyle = 'nav_active';

function showSitemapItem(imgExpandId, imgCollapseId, parentId, childId) {
	var imgExpand	= document.getElementById(imgExpandId);
	var imgCollapse = document.getElementById(imgCollapseId);
	var parent		= document.getElementById(parentId);
	var child		= document.getElementById(childId);
	
	if (imgExpand && imgCollapse && child) {
		imgExpand.style.display		= 'none';
		imgCollapse.style.display	= '';
		parent.className			= parent.className + Sitemap_MouseOverStyle;
		child.style.display			= '';
	}
}

function hideSitemapItem(imgExpandId, imgCollapseId, parentId, childId) {
	var imgExpand	= document.getElementById(imgExpandId);
	var imgCollapse = document.getElementById(imgCollapseId);
	var parent		= document.getElementById(parentId);
	var child		= document.getElementById(childId);

	if (imgExpand && imgCollapse && child) {
		imgExpand.style.display		= '';
		imgCollapse.style.display	= 'none';
		parent.className			= parent.className.substring(0, parent.className.length - Sitemap_MouseOverStyle.length);
		child.style.display			= 'none';
	}
}
/* SITEMAP JS FUNCTIONS END */

function resetArticleImage(imgID, fileID, hiddenId)
{
	document.getElementById(imgID).src = '';
	document.getElementById(fileID).value = '';
	document.getElementById(hiddenId).value = '';
}

function validateEmail(emailId, validatorId) {
	var tbEmail		= document.getElementById(emailId);
	var validator	= document.getElementById(validatorId);	
	if (tbEmail && validator && tbEmail.value == '') {
		validator.isvalid = false;
		validator.style['visibility'] = 'visible';
		return false;
	} else {
		return true;
	}
}

function validateLogin(loginId, passId, validatorId) {
	var tbLogin = document.getElementById(loginId);
	var tbPassword = document.getElementById(passId);
	var validator = document.getElementById(validatorId);
	if (tbLogin.value == '' || tbPassword.value == '') {
		validator.isvalid = false;
		validator.style['visibility'] = 'visible';
		return false;
	} else {
		return validator.isvalid;
	}
}

var dropDown;
function selectRegion(id) {
	dropDown = document.getElementById("DropDownStores")
	//dropDown.style.display = "none";
	dropDown.value = id;
	__doPostBack('DropDownStores','id');
}

function openModeless (varURL)
{
    window.open(varURL);
}