function RegisterImageMapGenerator()
{
	var ImageObj = document.getElementById("ImgImageMap");
	ImageObj.onclick = ImgPageClick;
	if (ImageObj.captureEvents) ImageObj.captureEvents(Event.CLICK);

}


function ImgPageClick(e)
{
  var XPosition = -1;
  var YPosition = -1;
  if (!e)   e= window.event;
  //alert("Here");
  //alert((event == null));
  var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
 var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1);
if (isIE)
{
	if (e.offsetX)
	{
		XPosition = e.offsetX;
		YPosition = e.offsetY;
	}
	else
	{
		alert("don't know how to get position out of event");
		return;
	}
}
else if (e.clientX || e.clientY)
	{
	//alert(e.clientX);
		//XPosition = e.clientX - 110;
		//YPosition = e.clientY - 243;
		XPosition = e.clientX;
		YPosition = e.clientY;
}
var ImgPositionX = 0;
var ImgPositionY = 0;
if (!isIE)
{
	//var ImageObj = document.getElementById("ImgImageMap")
	var ImageObj = document.getElementById("binding")
	//alert(ImageObj.offsetLeft)
	if (ImageObj.offsetLeft || ImageObj.offsetTop)
	{
	
		ImgPositionX = ImageObj.offsetLeft;
		ImgPositionY = ImageObj.offsetTop;
	}
	
}
	
var CoordinateX = XPosition - ImgPositionX;
var CoordinateY = YPosition - ImgPositionY;
	
	//var CoordinateX = XPosition;
	//var CoordinateY = YPosition;
	
	//alert(CoordinateX);
	
	//alert(CoordinateY);
	
	document.getElementById("hidCoordicate").value= CoordinateX + ", " + CoordinateY;
	//alert(document.getElementById("hidCoordicate").value);
	//alert(document.getElementById("ucCoordinatesAndLinkto_hidIndex").value);
	document.TemplateForm.submit();
	//var strIndex = document.getElementById("ucCoordinatesAndLinkto_hidIndex").value
	/*if (strIndex != "" && strIndex != "-1")
	{
	//var intIndex = parseInt(strIndex)+2;
	//alert("ucCoordinatesAndLinkto:MyDataGrid:_ctl" + (intIndex) + ":_ctl2");
	//document.getElementById("ucCoordinatesAndLinkto:MyDataGrid:_ctl" + intIndex + ":_ctl2").value += CoordinateX + "," + CoordinateY;
	
	}*/

}

function ShowHelp()
{
	var intWidth = screen.width;
	var width = 485;
	var height = 530;
	var strFileName = "Help.htm";
		
	var property = "top=0, left=0, scrollbars=yes, width=" + width + ", height=" + height;
	var strURL = strFileName;
	var winHelp = window.open(strURL, 'Help', property);
	winHelp.focus();
}

//function ShowTOC2(CatalogOID, subDir, width, height)
function ShowTOC2(CatalogOID, subDir)
{
	var intWidth = screen.width;
	var width = 970;
	var height = 656;
	if (intWidth > 1500)
	{
		width = 1415;
		height = 944;
	}
	
	if (intWidth < 1024)
	{
		width = 748;
		height = 512;
	}
	
	var strSubDir = "";
	if (subDir == true) 
	{	
		strSubDir = "../";
	}
	
	var property = "top=0, left=0, resizable=1, width=" + width + ", height=" + height;
	var strURL = strSubDir + "CatalogView.aspx?CatalogOID=" + CatalogOID + "&ShowPage=ViewCatalog.aspx?Left=1:amp:Right=-1:amp:CatalogOID=" + CatalogOID;
	var winCatalog = window.open(strURL, 'ActiveMerchandiser', property);
	winCatalog.focus();
	//alert("here");
}

function ShowTOC(CatalogOID)
{
	//width = width - 5;
	//ShowTOC2(CatalogOID, false, width, height, false);
	ShowTOC2(CatalogOID, false);
}

function ShowContent(PageNumber, CatalogOID)
{
		//document.getElementById('iframeCatalog').src = 'ViewCatalog.aspx?Left=' + PageNumber + '&Right=' + (PageNumber+1) + '&CatalogOID=' + CatalogOID;
		//MoveToTop();
		var strURL = "CatalogView.aspx?CatalogOID=" + CatalogOID + "&ShowPage=ViewCatalog.aspx?Left=" + PageNumber + ":amp:Right=" + (PageNumber+1) + ":amp:CatalogOID=" + CatalogOID;
		document.location.replace(strURL);
}

function showcontentinside(PageName, PageNumber, CatalogOID)
{
	//var strPageName = document.getElementById("hidPageName").value;
	//alert(PageNumber);
	var strURL = "CatalogView.aspx?CatalogOID=" + CatalogOID + "&ShowPage=" + PageName + "?Left=" + PageNumber + ":amp:Right=" + (PageNumber+1) + ":amp:CatalogOID=" + CatalogOID;
	//alert(strURL);
	window.parent.document.location.replace(strURL);
}

//function showexternal(url, width, height)
/*function showexternal(url)
{
	//var property = "top=0, left=0, width=" + width + ", height=" + height;
	var property = "";
	
	if (url.indexOf('http://') == -1)
	{
		url = 'http://' + url;
		
	}
	
	var winExternalURL = window.open(url, 'External', property);
	winExternalURL.focus();
}*/

function showexternal(externalurl, eventlogurl)
{
	//var property = "top=0, left=0, width=" + width + ", height=" + height;
	var property = "";
	
	if (externalurl.indexOf('http://') == -1)
	{
		externalurl = 'http://' + externalurl;
		
	}
	//alert(externalurl);
	var winExternalURL = window.open(externalurl, 'External', property);
	winExternalURL.focus();
	//alert(eventlogurl);
	window.document.location.replace(eventlogurl);
}

function showpagerefreshparent(PageNumber, CatalogOID)
{
	//window.parent.document.location.replace("ViewCatalog.aspx?Left=" + PageNumber + "&Right=" + (PageNumber+1) + "&CatalogOID=" + CatalogOID);
	var strURL = "CatalogView.aspx?CatalogOID=" + CatalogOID + "&ShowPage=ViewCatalog.aspx?Left=" + PageNumber + ":amp:Right=" + (PageNumber+1) + ":amp:CatalogOID=" + CatalogOID;
	window.parent.document.location.replace(strURL);
}

//function gotopage(LinkTo)
//{
//	document.location.replace("ViewDetail.aspx?LinkTo=" + LinkTo);
//}

// Mouseover related functions
function setalt(linkto, pagename)
{
	//alert(pagename);
	 //ViewCatalog is defined by Ajax.Net because that's the name of the type we registered
	 if (pagename.indexOf('catalog') != -1)
	 {
		viewcatalog.GetAlt(linkto, setalt_CallBack);
	 }
	 else
	 {
		if (pagename.indexOf('single') != -1)
		{
			viewsinglepage.GetAlt(linkto, setalt_CallBack);
		}
	 
	 }
}
//callback we told Ajax.Net to pass the response tos
function setalt_CallBack(response)
{
  //if the server side code threw an exception
  if (response.error != null)
  {    
    //alert(response.error); //we should probably do better than this
    return;
  }  
  
  var stralt = response.value; 
  //alert(stralt);
        //if the response wasn't what we expected  
  if (stralt == null)
  {
    return;  
  }
 //alert(stralt);
 // if  (document.getElementById("HidShowMO") != null)
 // {
	//if ((document.getElementById("HidShowMO").value == "true") & (stralt.indexOf('::') != -1 ))
	//{
		var strlinkto = stralt.substring(0,stralt.indexOf('::')); 
		//alert(strlinkto);
		stralt = stralt.substring(stralt.indexOf('::') + 2);
		//alert(strlinkto.replace("/", "_"));
		var strlinkto2 = strlinkto.replace("/", "_");
		//var strlinkto3 = strlinkto2.replace("\", "_");
		var strlinkto3 = strlinkto2.replace(" ", "_SPACE_");
		var lbl = document.getElementById("div" + strlinkto3);
		//alert(stralt);
		if (lbl != null)
		{
			lbl.innerHTML = stralt; 
		}
		//lbl.style.visibility = "visible";
	//}
  //}
}

function ChangeBGColor(divID)
{

	document.getElementById(divID).style.background = "#ffffff";
	//document.getElementById(divID).className = div2;
}

function ChangeBGColorBack(divID)
{

	document.getElementById(divID).style.background = "#eef6fe";
	//document.getElementById(divID).className = div1;
}



function settoc(CatalogOID, PageIndex)
{
	//alert("here");
	catalogview.GetTOC(CatalogOID,PageIndex, settoc_CallBack);
	 
}
//callback we told Ajax.Net to pass the response tos
function settoc_CallBack(response)
{
  //if the server side code threw an exception
  if (response.error != null)
  {    
    alert(response.error); //we should probably do better than this
    return;
  }  
  
  var strtoc = response.value; 
  //alert(strtoc);
        //if the response wasn't what we expected  
  if (strtoc == null)
  {
    return;  
  }
  var lbl = document.getElementById("divtoc");
 //alert(strtoc);
  lbl.innerHTML = strtoc; 

}

function showtoc()
{
	if (document.getElementById("divtoc").innerHTML != "")
	{
		document.getElementById("divtoc").style.visibility = "visible";
		document.getElementById("imgTOCClose").style.visibility = "visible";
	}
}

function hidetoc()
{
	document.getElementById("divtoc").style.visibility = "hidden";
	document.getElementById("imgTOCClose").style.visibility = "hidden";
	document.getElementById("imgTOC").src = "images/shared/table_of_contents_off.gif";
}
// Mouseover related functions

function showintro(linkto)
{
	//alert(linkto);
	if (document.getElementById("div" + linkto).innerHTML != "")
	{
		//alert(linkto);
		document.getElementById("div" + linkto).style.visibility = "visible";
	}
}

function hideintro(linkto)
{
	document.getElementById("div" + linkto).style.visibility = "hidden";
}
// Mouseover related functions




function AnyQuantityEntered() 
{
	for (i=0; i < document.TemplateForm.elements.length; i ++)
	{
		if (document.TemplateForm.elements[i].id.indexOf("txt") != -1)
			if (document.TemplateForm.elements[i].value != "")
				return true;			
	}
	return false;
}
		
function AddToOrder()
{
	if (document.getElementById('HidSKUsforInvalid').value == "" )
	{
		if (AnyQuantityEntered())
		{
			document.getElementById("HidCommand").value="AddToOrder";
			document.TemplateForm.submit();
		}
		else
		{
			alert("Please enter quantity for at least one item.");
		}
	}
	else
	{
		alert("Invalid quantity entry for Item #" + document.getElementById('HidSKUsforInvalid').value + ".");
	}
}
			
function ValidateAll()
{
	var ListofData = document.getElementById("HidValidationInfo").value;
	alert(ListofData);
	while (ListofData.indexof(';') != -1)
	{
		var strSubstring = ListofData.substr(0, ListofData.indexof(';'))
					
		var sku = strSubstring.substr(0, strSubstring.indexof(','))
		strSubstring = strSubstring.substr(strSubstring.indexof(','))
		var min = strSubstring.substr(0, strSubstring.indexof(','))
		var incre = strSubstring.substr(strSubstring.indexof(','))
		alert('sku=' + sku + 'min' + min + 'incre' + incre);
		ValidateQuantity(sku, min, incre);
	}
}

function ValidateQuantity(sku, minimum, increment)
{
				//alert('ValidateQuantity');
	var Valid = true;
	var ErrorMessage = "";
	if (document.getElementById('txt' + sku).value != "")
	{
		Valid = IsInteger('txt' + sku);
               
		if (Valid == false)
		ErrorMessage = "Please enter an integer quantity for Item #" + sku + ".";
						
		//quantity must be a multiple of increment
		if (Valid == true)
		{
			intQuantity = parseInt(document.getElementById('txt' + sku).value);
			//quantity must be larger than Minimum
			if (intQuantity < minimum)
			{
				//Valid = false;
				ErrorMessage += "The quantity entered for Item #" + sku + " must be larger than " + minimum + "."
				document.getElementById('txt' + sku).value = minimum
			}
			intQuantity = parseInt(document.getElementById('txt' + sku).value);
			var Mode = 0;
			if (increment != 0) Mode = intQuantity % increment;
			if (Mode != 0)
			{
				Valid = false;
				ErrorMessage += "The quantity entered for Item #" + sku + " must be a multiple of " + increment + "."
			}
		}
	}
	var strHidSKUsforInvalid = document.getElementById('HidSKUsforInvalid').value;
	if (Valid==false)
	{	
		if (strHidSKUsforInvalid.indexOf(sku) == -1)
		{
			if (document.getElementById('HidSKUsforInvalid').value != "")
				document.getElementById('HidSKUsforInvalid').value += ", ";
			document.getElementById('HidSKUsforInvalid').value += "#" + sku;
						
		}
	}
	else
	{
		if (strHidSKUsforInvalid.indexOf("#" + sku) != -1)
		{
			if (strHidSKUsforInvalid.indexOf("#" + sku) == strHidSKUsforInvalid.length - sku.length - 1)
				if (strHidSKUsforInvalid.length != sku.length + 1)
					strHidSKUsforInvalid = strHidSKUsforInvalid.replace(", " + "#" + sku, "");
				else
					strHidSKUsforInvalid = strHidSKUsforInvalid.replace("#" + sku, "");
			else	
				strHidSKUsforInvalid = strHidSKUsforInvalid.replace("#" + sku + ", ", "");
							
			document.getElementById('HidSKUsforInvalid').value = strHidSKUsforInvalid;
						
		}
					
				
	}
	if (ErrorMessage != "")
		alert(ErrorMessage);
}
			
function IsInteger(ID)
{
				
	var intValue = parseInt(document.getElementById(ID).value);
	if (!isNaN(intValue))
	{
		//alert("true");
		document.getElementById(ID).value = intValue;
		return true;
	}

	if (isNaN(intValue))
	{
		//alert("false");
		return false;
	}
}


function ValidatePageNumber()
{
	var pageNo=document.TemplateForm.txtPageNo;
	if ((pageNo.value==null)||(pageNo.value==""))
	{
		alert("You did not enter a page number.\n\nPlease enter a page number and click on the Go button.\n");
		//pageNo.focus()
		return false;
	}
	
	if  (!IsNumeric(pageNo.value))
	{
		alert("You did not enter a numeric value.\n\nPlease enter a numeric value and click on the Go button.\n");
		return false;
	}
	
	return true;
}
 
function IsNumeric(strString)
{
	var strNumbers = "0123456789";
	var strEntry;
	var blnResult = true;
	
	if (strString.length == 0) return false;

   //check whether strString consists of valid numeric characters listed above in strNumbers
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strEntry = strString.charAt(i);
      if (strNumbers.indexOf(strEntry) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;

}