// JavaScript Document
//----------------------------------------------------
// Create a new pop up window for a given URL and type
//----------------------------------------------------
function popUp(URL, type) 
{
    switch(type)
    {
	         case "unb":
	    width = 380;
	    height = 320;
	    break;	    
			  default:
            width = 340;
            height = 310;
			break;
			   case "highbandwidth":
			   width = 670;
			   height = 500;
			   break;
			   case "highest":
			   width = 670;
			   height = 550;
			   break;
			   case "nserc":
			   width = 510;
			   height = 410;
			   break;
			    case "saumon":
			   width = 370;
			   height = 295;
			   break;
			   case "lowbandwidth":
			   width = 340;
			   height = 280;
			   case "hd":
			   width = 730;
			   height = 420;

   }

   var token = URL.indexOf('?') > -1 ? '&amp;' : '?';
   uniqueId = genUniqueId();
   URL=URL+genUniqueParam(token);

   var leftPosition  = (screen.width - width - 20) / 2;
   var topPosition = (screen.height - height) / 4;

   //open centered
   eval("win = window.open(URL, '"+type+"', 'toolbar=0,scrollbars=0,location=0,status=0,resizable=0,menubar=0,width="+width+",height="+height+",left="+leftPosition+",top="+topPosition+"');");

   if (parseInt(navigator.appVersion) >= 4) 
   { 
      win.window.focus(); 
   }
}
// ----------------------
// Generate Unique Id
// ----------------------
function genUniqueId()
{
   day = new Date();
   return day.getTime();
}

// -------------------------------------------------
// Generate Unique parameter to be appended to the URL
// This will realoding the HTML from the server
// -------------------------------------------------
function genUniqueParam(parameter)
{
   return parameter+'unique_id='+genUniqueId();
}

//
// Display the target image for this thumbnail
//
function windowOpen(src, width, height, title)
{
   var winWidth = 400;
   var winHeight = 330;

   eval("win = window.open('','Thumb', 'toolbar=0,scrollbars=0,location=0,status=0,resizable=0,menubar=0,width="+winWidth+",height="+winHeight+"');");

   // clear the content of the document
   win.document.open();

   win.document.writeln('<html>');

   if(null != title && title != "")
   {
       win.document.writeln('<head><title>' + title + '</title></head>');
   }
   else
   {
       win.document.writeln('<head><title>Thumbnail Image</title></head>');
   }
   win.document.writeln('<body>');

   win.document.writeln('<center><table border="0">');
   if (width == 0)
   {
      win.document.writeln('<tr><td align="center"><img src="'+src+'"></td></tr>');
   }
   else if (height == 0)
   {
      win.document.writeln('<tr><td align="center"><img width="'+width+'" src="'+src+'"></td></tr>');   
   } 
   else
   {
      win.document.writeln('<tr><td align="center"><img width="'+width+'" height="'+height+'" src="'+src+'"></td></tr>');   
   } 

   if(null != title && title != "")
   {
       win.document.writeln('<tr><td align="center">'+title+'</td></tr>');
   }
   win.document.writeln('</table></center>');

   win.document.writeln('</body></html>');
   win.document.close();
}

    function genURL(action,formname)
    {
		var sa = document.getElementById(formname).elements[0].value;
		var cy = document.getElementById(formname).elements[1].value;
		var st = document.getElementById(formname).elements[2].value;
		var pc = document.getElementById(formname).elements[3].value;
		var ct = document.getElementById(formname).elements[4].value;
		var lat =document.getElementById(formname).elements[5].value;
		var lng =document.getElementById(formname).elements[6].value;
		var uid =document.getElementById(formname).elements[7].value;
		var wid =document.getElementById(formname).elements[8].value;
		if(pc=="")
		{
			if(cy=="" || st=="")
			{
				alert("Type a City and State, or a Postal/ZIP Code, and then click Continue.");
				return false;
			}
		}
		var url = action+"&street_address="+sa+"&city="+cy+"&state="+st+"&postal_code="+pc+"&country="+ct+"&latitude="+lat+"&longitude="+lng+"&userid="+uid+"&website_id="+wid;
		popUp(url);

   }

