
//Image Functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Standard Used Functions
function submitSearch()
{	
	document.frmSearch.submit();
}
function setSrchFocus()
{	
	document.frmSearch.txtSearch.focus; 
}
function goWhere(location)
{
	document.location.href = location//document.frmDefault.TopicsOfIntrest.value;
}

		function ShowGroups()
		{
				document.getElementById("TherapeuticGroups").style.display="block"
		}
		function HideGroups()
		{
				document.getElementById("TherapeuticGroups").style.display="none"
		}


	function makeVisible(somename)
	{
		document.getElementById(somename).style.display="block"
	}
	
	function makeInVisible(somename)
	{

		document.getElementById(somename).style.display="none"

	}	
	
	function changeBackGround(somename)
	{
		if(document.Form1.subselect.value != "")
		{
			document.getElementById(document.Form1.subselect.value).style.backgroundColor="whitesmoke"
		}
		
		if(document.Form1.subselect.value == somename)
		{
			document.getElementById(somename).style.backgroundColor="white"				
		}

		document.getElementById(somename).style.backgroundColor="white"		

		document.Form1.subselect.value  = somename
	
	}
	
	function check()
	{
		if (event.keyCode == 13) {
		__doPostBack('SEARCH','');	
		}		
	}
	

	
	
	function showDetail(divid)
	{
		document.getElementById(divid).style.display="block"
	}
	
	function hideDetail(divid)
	{
		document.getElementById(divid).style.display="none"
	}
	
	

	function logoff()
	{
		confirm("This will end your shopping session. Are you sure?\n\nThank you for using Medication Store.")
	
		window.close()
	}


	function showHint(someval,divid,searchid)
	{
		//AJAX related stuff
		
		var xmlHttp= new ActiveXObject("Msxml2.XMLHTTP"); 
		var sEnvelope = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><ProductName xmlns='http://tempuri.org/'><_com>" + someval + "</_com></ProductName></soap:Body></soap:Envelope>"
		var divtext = ""
		var xmlDoc = new ActiveXObject("Msxml2.DomDocument"); 

		var regexp = /\s+$/g

		someval = someval.replace(regexp,"")

		if (searchid == 0)  // do this only for product name
		{
			if(someval.length >= 2)
			{
				xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
					{
						xmlDoc.loadXML(xmlHttp.responseText)

						var valArray = xmlDoc.selectSingleNode("//ProductNameResult").text.split("|")
						
						if(valArray.length > 1)
						{
							divtext = "<ul><li><b>SEARCH SUGGESTIONS</b></li>"				
						
							for(i=0;i<valArray.length-1;i++)
							{
								divtext = divtext + "<li><a href='#' onclick=" + String.fromCharCode(34) + "javascript:document.getElementById('_ctl0_ItemBox1').value='" + valArray[i] + "';document.getElementById('" + divid + "').style.display='none';document.getElementById('_ctl0_ItemBox1').focus()" + String.fromCharCode(34) + ">" + valArray[i] + "</a></li>"				
							}
							divtext = divtext + "</ul>"
							document.getElementById(divid).innerHTML = divtext
							document.getElementById(divid).style.display ="block"
						}
						else
						{
							divtext = "<ul><li><b>SEARCH SUGGESTIONS</b></li>"				
							divtext = divtext + "<li>None</li>"				
							divtext = divtext + "</ul>"	
							document.getElementById(divid).innerHTML = divtext
							document.getElementById(divid).style.display ="block"
						}
					}	
				}	
			}
		}
		else
		{
			document.getElementById(divid).style.display ="none"		
		}

//		xmlHttp.open("POST","https://webservices.allscripts.com/AllscriptsCommon/webshopsearch.asmx?op=ProductName",false);
		xmlHttp.open("POST","webshopsearch.asmx?op=ProductName",false);		
		xmlHttp.setRequestHeader("Content-Type","text/xml")				
		xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/ProductName")		
		xmlHttp.send(sEnvelope);  
		
	}
	
	function showARP(sku,zipCode,divid)
	{
		//AJAX related stuff
		
		var xmlHttp= new ActiveXObject("Msxml2.XMLHTTP"); 
		var sEnvelope = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetARPPrice xmlns='http://tempuri.org/'><_prodno>" + sku + "</_prodno><_zipcode>" + zipCode + "</_zipcode></GetARPPrice></soap:Body></soap:Envelope>"
		var divtext = ""
		var xmlDoc = new ActiveXObject("Msxml2.DomDocument"); 
				
				xmlHttp.onreadystatechange=function()
				{
								
					if(xmlHttp.readyState==4)
					{
						xmlDoc.loadXML(xmlHttp.responseText)

						var sPrice = parseFloat(xmlDoc.selectSingleNode("//GetARPPriceResult").text)
						
						if(sPrice != "")
						{
							if (isNaN(sPrice))
							{
								divtext = "<table cellpadding='0' cellspacing='0' border='0' width='100%' bgcolor='gainsboro'><tr><td valign='top' class='small'><b>Average Retail Price:</b> Not Available</td><td valign='top' align='right'><a href=" + String.fromCharCode(34) + "javascript:hideDetail('ARP" + sku + "')" + String.fromCharCode(34) + "><img src='images/close.gif' border='0' ALT='CLOSE'></img></a></td></tr></table></DIV>"				
							}
							else
							{
								divtext = "<table cellpadding='0' cellspacing='0' border='0' width='100%' bgcolor='gainsboro'><tr><td valign='top' class='small'><b>Average Retail Price:</b> $" + sPrice.toFixed(2) + "</td><td valign='top' align='right'><a href=" + String.fromCharCode(34) + "javascript:hideDetail('ARP" + sku + "')" + String.fromCharCode(34) + "><img src='images/close.gif' border='0' ALT='CLOSE'></img></a></td></tr></table></DIV>"				
							}
							document.getElementById(divid).innerHTML = divtext
							document.getElementById(divid).style.display ="block"
						}
						else
						{
							divtext = "<table cellpadding='0' cellspacing='0' border='0' width='100%' bgcolor='gainsboro'><tr><td valign='top' class='small'><b>Average Retail Price:</b> Not Available</td><td valign='top' align='right'><a href=" + String.fromCharCode(34) + "javascript:hideDetail('ARP" + sku + "')" + String.fromCharCode(34) + "><img src='images/close.gif' border='0' ALT='CLOSE'></img></a></td></tr></table></DIV>"										
						
							document.getElementById(divid).innerHTML = divtext
							document.getElementById(divid).style.display ="block"
						}
					}
				}	
			

//		xmlHttp.open("POST","https://webservices.allscripts.com/AllscriptsCommon/webshopsearch.asmx?op=ProductName",false);
		xmlHttp.open("POST","webshopsearch.asmx?op=GetARPPrice",false);		
		xmlHttp.setRequestHeader("Content-Type","text/xml")				
		xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/GetARPPrice")		
		xmlHttp.send(sEnvelope);  
		
	}
	
	
	function applyHint(somehint)
	{
		alert(somehint)	
	}



	function checkObsolete(prodno)
	{
		//AJAX related stuff
		
		var xmlHttp= new ActiveXObject("Msxml2.XMLHTTP"); 
		var sEnvelope = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><CheckObsolete xmlns='http://tempuri.org/'><_prodno>" + prodno + "</_prodno></CheckObsolete></soap:Body></soap:Envelope>"
		var divtext = ""
		var xmlDoc = new ActiveXObject("Msxml2.DomDocument"); 


				xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
					{
						xmlDoc.loadXML(xmlHttp.responseText)

                        var bObslt =  xmlDoc.selectSingleNode("//CheckObsoleteResult").text
                
                        if(bObslt == "false")
                        {
                            __doPostBack('ADDQUICK','')
                        }
                        else
                        {
                            alert("This product is obsolete or unavailable. Please search for therapeutic equivalents.")
                        }

					}	
				}	

//		xmlHttp.open("POST","https://webservices.allscripts.com/AllscriptsCommon/webshopsearch.asmx?op=ProductName",false);
		xmlHttp.open("POST","webshopsearch.asmx?op=CheckObsolete",false);		
		xmlHttp.setRequestHeader("Content-Type","text/xml")				
		xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/CheckObsolete")		
		xmlHttp.send(sEnvelope);  
		
	}
	
