var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;
var siteurl="";
var win=null;
var isFlashRequired=true;
 var flashfile_path;
  var flashless_img_path;

  function showSurveyPopup(){
	  var eventBlocker=document.getElementById("eventBlocker");
	  var SurveyPopup=document.getElementById("SurveyPopup");
	  var viewportwidth=document.body.clientWidth || innerWidth;
	  var viewportheight=document.body.clientHeight || innerHeight;
	  SurveyPopup.style.display='block';
	  document.getElementById("flashhead").style.display='none';
	  document.getElementById("flashless_img_id").style.display='block';
	  eventBlocker.style.display='block';
	  eventBlocker.style.height=getDocumentHeight()+'px';
	  eventBlocker.style.width=getDocumentWidth()+'px';
	  var toppos=(parseInt(viewportheight)-parseInt(SurveyPopup.offsetHeight))/2;
	  var leftpos=(parseInt(viewportwidth)-parseInt(SurveyPopup.style.width))/2
	  SurveyPopup.style.top=toppos<0?0:toppos;
	  SurveyPopup.style.left=leftpos<0?0:leftpos;
  }

  function hideSurveyPopup(){
		document.getElementById("SurveyPopup").style.display='none';
		document.getElementById("eventBlocker").style.display='none';
		document.getElementById("flashless_img_id").style.display='none';
		document.getElementById("flashhead").style.display='block';
		sendSurveyCloseData(1);
	}

  function sendSurveyData(surveyId,result ) {
		var frmdemoreq=document.frmdemoreq;
		var returnValue,poststr;

		if(result=="yes"){
			poststr =  "surveyId=1&surveyYes=1";
		}else if(result=="no"){
			poststr =  "surveyId=1&surveyNo=1";
		}
	   makePOSTRequest('PopupSurvey.Action', poststr, surveyResultCallBack);
	}

  function responselessCallback(){
	  if (http_request.readyState == 4) {
  	      if (http_request.status == 200) {

  	      } else {

  	      }
  	   }
  }

  function sendSurveyCloseData(surveyId) {
		poststr =  "surveyId=1&surveyClose=1";
	   makePOSTRequest('PopupSurvey.Action', poststr, responselessCallback);
	}

  	function surveyResultCallBack(){
  		if (http_request.readyState == 4) {
  	      if (http_request.status == 200) {
  	    	drawSurveyGraph(http_request.responseText);
  	      } else {
  	         alert('Thanks for the response, please wait.');
  	      }
  	   }
  	}

  	function drawSurveyGraph(responseData){
  		document.getElementById("div_survey_yes_no").style.display='none';
  		var responseSplit =  responseData.split("|~|");
  		var yes=(parseInt(responseSplit[2])/(parseInt(responseSplit[2])+parseInt(responseSplit[3])))*100;
  		var no=(parseInt(responseSplit[3])/(parseInt(responseSplit[2])+parseInt(responseSplit[3])))*100;
  		document.getElementById("img_survey_graph_yes").height=Math.round(yes/1.5);
  		document.getElementById("img_survey_graph_no").height=Math.round(no/1.5);
  		document.getElementById("div_survey_graph").style.display='block';
  		document.getElementById("span_survey_graph_yes_value").innerHTML=Math.round(yes)+"%";
  		document.getElementById("span_survey_graph_no_value").innerHTML=Math.round(no)+"%";
  	}

 function ViewScreenShot(img){
 var img_path=document.getElementById("img_folder_path").value;
//  win= window.open("images/screenshots/FullScreen/"+img,"ImagePreview","resizable=yes,scrollbars=yes,height="+(screen.height-55)+",width="+(screen.width-10)+",top=0,left=0");
  //win.focus();
var titlename=img.split(".");
  win= window.open("","ImagePreview","resizable=yes,scrollbars=no,height=600,width=780,top=0,left=0");
  win.document.write ("<head><title>GlaceEMR - ModulesPreview ("+titlename[0]+") </title></head><BODY style='margin:0px;cursor:hand;' scroll='auto'  bgColor='#2172a1' onclick='self.close();' valign=middle>");
  win.document.write ("<CENTER><img  id='FullSreenImage' src='"+img_path+"/screenshots/FullScreen/"+img+"' title='click on the image to close this window.' onload='winresize();'></CENTER>");
  win.document.write ("</BODY>") ;
  win.document.write ("<script>function winresize(){var h=document.getElementById('FullSreenImage').height;") ;
  win.document.write ("var w=document.getElementById('FullSreenImage').width;") ;
  win.document.write ("if(document.getElementById('FullSreenImage')&&  h<"+screen.height+" && w<"+screen.width+"){window.resizeTo(w+12,h+32);}")
  win.document.write ("else{window.resizeTo("+screen.width+","+(screen.height-50)+");}}</script>")
  win.focus();

 }

 function drawHeader(){
 this.flashfile_path=document.getElementById("flashfile_path");
 this.flashless_img_path=document.getElementById("flashless_img_path");
if(isFlashRequired){
document.writeln("<div id=\"flashhead\" >  <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"550\" height=\"210\" >");
document.writeln("<param name=\"movie\" value=\""+flashfile_path.value+"\">");
document.writeln("<param name=\"wmode\" value=\"transparent\">");
document.writeln("<param name=\"quality\" value=\"high\">");
document.writeln("<embed src=\""+flashfile_path.value+"\" quality=\"high\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"550\" height=\"210\" wmode=\"transparent\"></embed>");
document.writeln("</object> </div> <img style=\"display:none;\" id=flashless_img_id src='"+flashless_img_path.value+"'>");
}
else{
document.writeln("<img src='"+flashless_img_path.value+"'>");
}
 }


 function drawJSPHeader(){
 this.flashfile_path=document.getElementById("flashfile_path");
 this.flashless_img_path=document.getElementById("flashless_img_path");
if(isFlashRequired){
document.writeln("<div id=\"flashhead\" > <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"518\" height=\"210\" >");
document.writeln("<param name=\"movie\" value=\""+flashfile_path.value+"\">");
document.writeln("<param name=\"wmode\" value=\"transparent\">");
document.writeln("<param name=\"quality\" value=\"high\">");
document.writeln("<embed src=\""+flashfile_path.value+"\" quality=\"high\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"518\" height=\"210\" wmode=\"transparent\"></embed>");
document.writeln("</object> </div>");
}
else{
document.writeln("<img src='"+flashless_img_path.value+"'>");
}
}

 function showRequestDemoDiv(errorString){
	 	window.scrollBy(0,-800);
		var eventBlocker=document.getElementById("eventBlocker");
		var RequestDemoPopup=document.getElementById("RequestDemoPopup");
		var viewportwidth=document.body.clientWidth || innerWidth;
		var viewportheight=document.body.clientHeight || innerHeight;
		RequestDemoPopup.style.display='block';
		document.getElementById("flashhead").style.display='none';
	 	eventBlocker.style.display='block';
		eventBlocker.style.height=getDocumentHeight()+'px';
		eventBlocker.style.width=getDocumentWidth()+'px';
		var toppos=(parseInt(viewportheight)-parseInt(RequestDemoPopup.offsetHeight))/2;
		var leftpos=(parseInt(viewportwidth)-parseInt(RequestDemoPopup.style.width))/2
		RequestDemoPopup.style.top=toppos<0?0:toppos;
		RequestDemoPopup.style.left=leftpos<0?0:leftpos;
}
function hideRequestDemoDiv(){
	document.getElementById("RequestDemoPopup").style.display='none';
	document.getElementById("eventBlocker").style.display='none';
	document.getElementById("flashhead").style.display='block';
}


function showRegisterForDemoPopup(txtDetail,specialityid){
 	window.scrollBy(0,-1800);
	var eventBlocker=document.getElementById("eventBlocker");
	var RequestDemoPopup=document.getElementById("RegisterForDemoPopup");
	var viewportwidth=document.body.clientWidth || innerWidth;
	var viewportheight=document.body.clientHeight || innerHeight;
	RequestDemoPopup.style.display='block';
	document.getElementById("flashhead").style.display='none';
 	eventBlocker.style.display='block';
	eventBlocker.style.height=getDocumentHeight()+'px';
	eventBlocker.style.width=getDocumentWidth()+'px';
	var toppos=(parseInt(viewportheight)-parseInt(RequestDemoPopup.offsetHeight))/2;
	var leftpos=(parseInt(viewportwidth)-parseInt(RequestDemoPopup.style.width))/2
	RequestDemoPopup.style.top=toppos<0?0:toppos;
	RequestDemoPopup.style.left=leftpos<0?0:leftpos;
	var demoDetail=document.getElementById('demoDetail');
	demoDetail.innerHTML=txtDetail;
	document.getElementById('txtDetail').value=txtDetail;
	var selElm=document.frmlivedemoreg.txtSpeciality;
	if(specialityid){
		//selElm.innerHTML="";
		if(specialityid==1){
			selElm.options[1].selected=true;
//			var opt=document.createElement("OPTION");
//			opt.value='1';
//			opt.text='Allergy';
//			selElm.options.add(opt);
		}
		else if(specialityid==3){
			selElm.options[3].selected=true;
//			var opt=document.createElement("OPTION");
//			opt.value='3';
//			opt.text='Cardiology';
//			selElm.options.add(opt);
		}
                else if(specialityid==15){
			selElm.options[15].selected=true;
//			var opt=document.createElement("OPTION");
//			opt.value='16';
//			opt.text='Internal Medicine';
//			selElm.options.add(opt);
		}
		else if(specialityid==26){
			selElm.options[26].selected=true;
//			var opt=document.createElement("OPTION");
//			opt.value='26';
//			opt.text='Pain Management';
//			selElm.options.add(opt);
		}
		else if(specialityid==27){
			selElm.options[27].selected=true;
//			var opt=document.createElement("OPTION");
//			opt.value='26';
//			opt.text='Pediatrics';
//			selElm.options.add(opt);
		}
	}else selElm.options[0].selected=true;
}
function hideRegisterForDemoPopup(){
document.getElementById("RegisterForDemoPopup").style.display='none';
document.getElementById("eventBlocker").style.display='none';
document.getElementById("flashhead").style.display='block';
}



function showReportDiv(errorString){
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	 	//window.scrollBy(0,-800);
		var eventBlocker=document.getElementById("eventBlocker");
		var RequestDemoPopup=document.getElementById("ReportPopup");
		var viewportwidth=document.body.clientWidth || innerWidth;
		var viewportheight=document.body.clientHeight || innerHeight;
		RequestDemoPopup.style.display='block';
		document.getElementById("flashhead").style.display='none';
	 	eventBlocker.style.display='block';
		eventBlocker.style.height=getDocumentHeight()+'px';
		eventBlocker.style.width=getDocumentWidth()+'px';
		//var toppos=(parseInt(viewportheight)-parseInt(RequestDemoPopup.offsetHeight))/2;
		var toppos=posy-300;
		var leftpos=(parseInt(viewportwidth)-parseInt(RequestDemoPopup.style.width))/2
		RequestDemoPopup.style.top=toppos<0?0:toppos;
		RequestDemoPopup.style.left=leftpos<0?0:leftpos;
}

function hideReportDiv(){
	document.getElementById("ReportPopup").style.display='none';
	document.getElementById("eventBlocker").style.display='none';
	document.getElementById("flashhead").style.display='block';
}

function requestDemo(){
	requestdemo_parameter();
	hideRequestDemoDiv();
}

function registerDemo(){
	if(! registerDdemo_parameter()) return false;
	hideRegisterForDemoPopup();
}
function defined(o) {
	  return (typeof(o)!="undefined");
	}


// Get a reference to the body
// --------------------------------------------------------------------
function getBody() {
  if (document.body) {
    return document.body;
  }
  if (document.getElementsByTagName) {
    var bodies = document.getElementsByTagName("BODY");
    if (bodies!=null && bodies.length>0) {
      return bodies[0];
    }
  }
  return null;
}

function getDocumentWidth() {
  var width = 0;
  var body = getBody();
  if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
      var rightMargin = parseInt(CSS.get(body,'marginRight'),10) || 0;
      var leftMargin = parseInt(CSS.get(body,'marginLeft'), 10) || 0;
    width = Math.max(body.offsetWidth + leftMargin + rightMargin, document.documentElement.clientWidth);
  }
  else {
    width =  Math.max(body.clientWidth, body.scrollWidth);
  }
  if (isNaN(width) || width==0) {
    width = zero(self.innerWidth);
  }
  return width;
}

// Get the height of the entire document
// --------------------------------------------------------------------
function  getDocumentHeight() {
  var body = getBody();
  var innerHeight = (defined(self.innerHeight)&&!isNaN(self.innerHeight))?self.innerHeight:0;
  if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
      var topMargin = parseInt(CSS.get(body,'marginTop'),10) || 0;
      var bottomMargin = parseInt(CSS.get(body,'marginBottom'), 10) || 0;
    return Math.max(body.offsetHeight + topMargin + bottomMargin, document.documentElement.clientHeight, document.documentElement.scrollHeight, zero(self.innerHeight));
  }
  return Math.max(body.scrollHeight, body.clientHeight, zero(self.innerHeight));
}

// Util function to default a bad number to 0
// --------------------------------------------------------------------
function zero(n) {
  return (!defined(n) || isNaN(n))?0:n;
}

var http_request = false;
function makePOSTRequest(url, parameters,callByFunction) {
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
	   if(http_request ){
		   http_request.abort();
	   }else{
		   http_request = new XMLHttpRequest();
	   }
      if (http_request.overrideMimeType) {
      	// set type accordingly to anticipated content type
         //http_request.overrideMimeType('text/xml');
         http_request.overrideMimeType('text/html');
      }
   } else if (window.ActiveXObject) { // IE
      try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
      }
   }
   if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
   }

   http_request.onreadystatechange = callByFunction;
   http_request.open('POST', url, true);
   http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http_request.setRequestHeader("Content-length", parameters.length);
   http_request.setRequestHeader("Connection", "close");
   http_request.send(parameters);
}

function alertContents() {
   if (http_request.readyState == 4) {
      if (http_request.status == 200) {
    	  alert("Thank you for your interest with our product. Our customer service will contact you very shortly.");
         //result = http_request.responseText;
         //document.getElementById('myspan').innerHTML = result;
      } else {
         alert('There was a problem with the request.');
      }
   }
}
function alertContentsLiveDemo() {
	   if (http_request.readyState == 4) {
		      if (http_request.status == 200) {
		    	  alert("Thank you for your interest with our product. Further Details will be mailed shortly to"+document.getElementById('txt_mail').value+".");
		         //result = http_request.responseText;
		         //document.getElementById('myspan').innerHTML = result;
		      } else {
		         alert('There was a problem with the request.');
		      }
		   }
}

function requestdemo_parameter() {
	var frmdemoreq=document.getElementById("frmdemoreq");
	var poststr =  "txtFName="+frmdemoreq.txtFName.value+"&txtMidName="+frmdemoreq.txtMidName.value+"&txtLName="+frmdemoreq.txtLName.value+"&txt_mail="+frmdemoreq.txt_mail.value+
	"&txtJobTitle="+frmdemoreq.txtJobTitle.value+"&txtPractice="+frmdemoreq.txtPractice.value+
	"&txtSpeciality="+frmdemoreq.txtSpeciality.options[frmdemoreq.txtSpeciality.selectedIndex].value+"&txtPracticeSize="+frmdemoreq.txtPracticeSize.options[frmdemoreq.txtPracticeSize.selectedIndex].value+
	"&txtAddr1="+frmdemoreq.txtAddr1.value+"&txtAddr2="+frmdemoreq.txtAddr2.value+"&txtCity="+frmdemoreq.txtCity.value+
	"&txtState="+frmdemoreq.txtState.options[frmdemoreq.txtState.selectedIndex].value+"&txtZip="+frmdemoreq.txtZip.value+
	"&txtPhone="+frmdemoreq.txtPhone.value+"&txtFax="+frmdemoreq.txtFax.value+"&txtBestTime="+frmdemoreq.txtBestTime.value;
   makePOSTRequest('RequestDemo.Action', poststr, alertContents);
}
function  registerDdemo_parameter() {
	var frmdemoreq=document.getElementById("frmlivedemoreg");
	var fname=frmdemoreq.txtFName.value;
	if(fname.length<1){
		alert("First Name should not be empty");
		return false;
	}
	var lname=frmdemoreq.txtLName.value;
	if(lname.length<1){
		alert("Last Name should not be empty");
		return false;
	}
	var mailId=frmdemoreq.txt_mail.value;
	if(!CheckSingleEmailAddress(mailId)){
		alert("Not valid email address.");
		return false;
	}
	var prName=frmdemoreq.txtPracticeOrCompany.value;
	if(prName.length<1){
		alert("Practice or Company Name should not be empty");
		return false;
	}
	if(frmdemoreq.txtPhone.value.length<6){
		alert("Phone number not valid");
		return false;
	}
	var poststr =  "txtFName="+fname+"&txtLName="+lname+"&txt_mail="+mailId+
	"&txtJobTitle="+frmdemoreq.txtJobTitle.value+
	"&txtAddr1="+frmdemoreq.txtAddr1.value+"&txtAddr2="+frmdemoreq.txtAddr2.value+"&txtCity="+frmdemoreq.txtCity.value+
	"&txtState="+frmdemoreq.txtState.options[frmdemoreq.txtState.selectedIndex].value+"&txtZip="+frmdemoreq.txtZip.value+
	"&txtPhone="+frmdemoreq.txtPhone.value+"&txtFax="+frmdemoreq.txtFax.value+"&txtPractice="+prName+
	"&txtSpeciality="+frmdemoreq.txtSpeciality.options[frmdemoreq.txtSpeciality.selectedIndex].value+"&txtDetail="+frmdemoreq.txtDetail.value;
   makePOSTRequest('RequestDemo.Action', poststr, alertContentsLiveDemo);
   return true;
}
function getAllTrackingLinks(){
	var anchors=document.getElementsByTagName("a");
	windowurl =window.location.href;
	siteurl = (windowurl.split("//")[1].split("/")[0]);
	regex = eval("/"+siteurl+"/");
	for(i=0;i<anchors.length;i++){
		if(anchors[i].href.search(regex)==-1 && anchors[i].href.length>0){
			anchors[i].onclick=trackExtLnk;
		}
	}
}


function trackExtLnk(){
	var nullFunc = function(){};
	var poststr = "URL="+this.href;
	makePOSTRequest('LogMe.Action', poststr, nullFunc);
	return true; //CAUTION make this false to disable the all external links
}

function set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
function onloadFn(){
	getAllTrackingLinks();
	if (siteurl == "")	siteurl= (window.location.href.split("//")[1].split("/")[0]);
	set_Cookie("REQ_DOMAIN",siteurl);
}

window.onload=onloadFn;


//Copyright 2006-2007 javascript-array.com

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 


function showImagePopup()
{
	  var check_cookie=checkCookie();
	  if(check_cookie!=null && check_cookie!="")
	     return true;
	
	  var eventBlocker=document.getElementById("eventBlocker");
	  var SurveyPopup=document.getElementById("ImagePopup");
	  var viewportwidth=document.body.clientWidth || innerWidth;
	  var viewportheight=document.body.clientHeight || innerHeight;
	  SurveyPopup.style.display='block';
	  document.getElementById("flashhead").style.display='none';
	  document.getElementById("flashless_img_id").style.display='block';
	  eventBlocker.style.display='block';
	  eventBlocker.style.height=getDocumentHeight()+'px';
	  eventBlocker.style.width=getDocumentWidth()+'px';
	  var toppos=(parseInt(viewportheight)-parseInt(SurveyPopup.offsetHeight))/2;
	  var leftpos=(parseInt(viewportwidth)-parseInt(SurveyPopup.style.width))/2
	  SurveyPopup.style.top=toppos<0?0:toppos;
	  SurveyPopup.style.left=leftpos<0?0:leftpos;
}

function hideImagePopup(){
		document.getElementById("ImagePopup").style.display='none';
		document.getElementById("eventBlocker").style.display='none';
		document.getElementById("flashless_img_id").style.display='none';
		document.getElementById("flashhead").style.display='block';
		setCookie("ImagePopup","ImagePopupCookie",1);
	}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var cookiename=getCookie("ImagePopup");
return cookiename;
}
