/*************
Function Popup
*************/

if (document.all)
	var browser_ie=true
else if (document.layers) 
	var browser_nn4=true
else if (document.layers || (!document.all && document.getElementById))
	var browser_nn6=true

var scrX=200,scrY=200,pgeX=0,pgeY=0;
function getObj(n,d) {
  var p,i,x; 
  if(!d)
      d=document;
   if(n != undefined)    {
	   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=getObj(n,d.layers[i].document);
  if(!x && d.getElementById)
      x=d.getElementById(n);
  return x;
}

function findPosX(obj) {
	var curleft = 0;
	if (document.getElementById || document.all) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (document.layers) {
		curleft += obj.x;
	}
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if (document.getElementById || document.all) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (document.layers) {
		curtop += obj.y;
	}
	return curtop;
}

function openPopUp(winInst,currObj,baseURL,winName,width,height,features) {
	var left=parseInt(findPosX(currObj))
	var top=parseInt(findPosY(currObj))
	if (window.navigator.appName!="Opera") top+=parseInt(currObj.offsetHeight)
	else top+=(parseInt(currObj.offsetHeight)*2)+10
	if (browser_ie)	{
		
		top+=window.screenTop-document.body.scrollTop
		left-=document.body.scrollLeft
		if (top+height+30>window.screen.height) 
			top=findPosY(currObj)+window.screenTop-height-30 //30 is a constant to avoid positioning issue
		if (left+width>window.screen.width) 
			left=findPosX(currObj)+window.screenLeft-width
	} else if (browser_nn4 || browser_nn6) {
		top+=(scrY-pgeY)
		left+=(scrX-pgeX)
		if (top+height+30>window.screen.height) 
			top=findPosY(currObj)+(scrY-pgeY)-height-30
		if (left+width>window.screen.width) 
			left=findPosX(currObj)+(scrX-pgeX)-width
	}
	if (width==0 || height==0)	{
		features="top="+top+",left="+left+";"+features;
	}	else 	{
		features="width="+width+",height="+height+",top="+top+",left="+left+";"+features;
	}
	//window.open(baseURL,winName,features);
	eval(winInst+'=window.open("'+baseURL+'","'+winName+'","'+features+'")');
}

function gethttpzip() {
	var zipcode = document.getElementById("idTxtZipCode").value;
	///document.getElementById("zip123").value = zipcode;
	var zipcode_form = document.getElementById("zipFrm");
	var checkzipcode = false;
	var checkzipcode2 = false;
	//alert(zipcode);
	if (zipcode >= '01001' && zipcode <= '02791') {
		checkzipcode = true;
	} else if(zipcode >= '03031' && zipcode <= '03897') {
		checkzipcode = true;
	} else if(zipcode >= '07001' && zipcode <= '08989') {
		checkzipcode = true;
	} else if(zipcode >= '10001' && zipcode <= '14925') {
		checkzipcode = true;
	} else if(zipcode >= '57001' && zipcode <= '57799') {
		checkzipcode = true;
	} else if(zipcode >= '58001' && zipcode <= '58856') {
		checkzipcode = true;
	} else if(zipcode >= '59001' && zipcode <= '59937') {
		checkzipcode = true;
	} else if(zipcode >= '82001' && zipcode <= '83128') {
		checkzipcode = true;
	} else if(zipcode >= '96701' && zipcode <= '96898') {
		checkzipcode = true;
	} else if(zipcode >= '98001' && zipcode <= '99403') {
		checkzipcode = true;
	} else if(zipcode >= '99501' && zipcode <= '99950') {
		checkzipcode = true;
	} else if(zipcode >= '02801' && zipcode <= '02940') {
		checkzipcode2 = true;
	} else if(zipcode >= '03901' && zipcode <= '04992') {
		checkzipcode2 = true;
	} else if(zipcode >= '05001' && zipcode <= '05907') {
		checkzipcode2 = true;
	} 
	
	if (checkzipcode) {
		zipcode_form.action = 'https://www.ehealthinsurance.com/ehi/Alliance?allid=Hea23610&type=IFP&zip=' + zipcode;
		zipcode_form.submit();
	} else if(checkzipcode2) {
		document.getElementById("idTxtZipCode").value = "";
		var url='zippopup.php?zipcode=' + zipcode;
		if (document.all) {
			window.open(url, 'formzipcode', 'width=600,height=200');
		} else {
			openPopUp('formzipcode',this,url,'healthcareshopper.com',600,200,'menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes');
		}
		document.getElementById("zip").value = zipcode;
		return false;
	} else {
		//zipcode_form.action = 'http://www.healthcareshopper.com/webform';
		zipcode_form.submit();
	}
	
}
