function ImgPageClick()
{
  var XPosition = -1;
  var YPosition = -1;
  var event = window.event;
 if (event.offsetX)
  //if (event.pageX)
	{
		XPosition = event.offsetX;
		YPosition = event.offsetY;
	}
	else
	{
		alert("don't know how to get position out of event");
		return;
	}

	var ImageObj = document.getElementById("ImgPage")
	var ImgPositionX = 0;
	ImgPositionX = ImageObj.clientLeft;
	var ImgPositionY = 0;
	ImgPositionY = ImageObj.clientTop;
	
	var CoordinateX = XPosition - ImgPositionX;
	var CoordinateY = YPosition - ImgPositionY;
	
	//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 ShowTOC(CatalogIndex)
{
	//document.location.replace("ViewCatalog.aspx?Left=1&Right=-1&CatalogIndex=" + CatalogIndex);
	//window.parent.getElement('selCatalog').value = CatalogIndex + 1;
	//document.location.replace("CatalogView.aspx?CatalogIndex=" + CatalogIndex + "&ShowPage=ViewCatalog.aspx?Left=1:amp:Right=-1");
	//window.open("CatalogView.aspx?CatalogIndex=" + CatalogIndex + "&ShowPage=ViewCatalog.aspx?Left=1:amp:Right=-1", 'CatalogViews', 'top=0, left=0, width=970, height=610');
	document.location.replace("CatalogView.aspx?CatalogIndex=" + CatalogIndex + "&ShowPage=ViewCatalog.aspx?Left=1:amp:Right=-1");
	//var winCatalog = window.open("CatalogView.aspx?CatalogIndex=" + CatalogIndex + "&ShowPage=ViewCatalog.aspx?Left=1:amp:Right=-1", 'CatalogViews', 'top=100, left=100, width=910, height=590');
	//winCatalog.focus();
	//winCatalog.location.reload(true);
	
}

function movetotop()
{
	if (navigator.userAgent.toLowerCase().indexOf( 'win' ) + 1) 
	{
		var csLoc = new String(window.parent.document.location);

		if (csLoc.toLowerCase().indexOf('#_top') == -1)
		{
			window.parent.document.location.replace(csLoc + '#_top');
		}
		else
		{
			window.parent.document.location.replace(csLoc);
		}
	}
}

function ShowContent(PageNumber, CatalogIndex)
{
		document.getElementById('iframeCatalog').src = 'ViewCatalog.aspx?Left=' + PageNumber + '&Right=' + (PageNumber+1) + '&CatalogIndex=' + CatalogIndex;
		//MoveToTop();
}

function showcontentinside(PageNumber, CatalogIndex)
{
	var strPageName = document.getElementById("hidPageName").value;
	document.location.replace(strPageName + "?Left=" + PageNumber + "&Right=" + (PageNumber+1) + "&CatalogIndex=" + CatalogIndex);
	//window.parent.getElement('selCatalog').value = CatalogIndex + 1;
}

function showpagerefreshparent(PageNumber)
{
	document.location.replace("ViewCatalog.aspx?Left=" + PageNumber + "&Right=" + (PageNumber+1));
}

function gotopage(LinkTo)
{
	document.location.replace("ViewDetail.aspx?LinkTo=" + LinkTo);
}

// Mouseover related functions
function setalt(linkto, catalogindex, 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,catalogindex, setalt_CallBack);
	 }
	 else
	 {
		if (pagename.indexOf('single') != -1)
		{
			viewsinglepage.GetAlt(linkto,catalogindex, 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);
		var lbl = document.getElementById("div" + strlinkto);
		//alert(stralt);
		lbl.innerHTML = stralt; 
		//lbl.style.visibility = "visible";
	//}
  //}
}

function showintro(linkto)
{
	if (document.getElementById("div" + linkto).innerHTML != "")
	{
		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("Please enter page number");
		//pageNo.focus()
		return false;
	}
	return true;
}
 

