
///////////////////////////////////////////////////////////////
////// Email validation Adopted from another website //////////
///////////////////////////////////////////////////////////////

function emailCheck(emailStr) {

/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ;: \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	//alert("Your Email address doesn't seems to be in proper format \""  +emailStr+ '" .')
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("The username doesn't seem to be valid. \""  +emailStr+ '"')
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        //alert("Destination IP address is invalid! \""  +emailStr+ '"')
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid. \""  +emailStr+ '"')
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   //alert("The address must end in a maximum of four-letter domain, or two letter country. \""  +emailStr+ '"')
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname! \""  +emailStr+ '"'
   //alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
	return true;
}
///////////////////////////////////////////////////////////////
////// TextArea characters count validation          //////////
///////////////////////////////////////////////////////////////
function GetObjID(ObjName)
{
  for (var ObjID=0; ObjID < document.all.length; ObjID++)
    if ( document.all[ObjID].name == ObjName )
    {  return(ObjID);
       break;
    }
  return(-1);
}

function getObject(obj)
 {
	var theObj;
	if(document.all)
	 {
		if(typeof obj=="string")
		{
			return document.all(obj);
		} 
		else
		{
			return obj.style;
		}
	}
	if(document.getElementById) 
	{
		if(typeof obj=="string") 
		{
			return document.getElementById(obj);
		}
		else 
		{
			return obj.style;
		}
	}
	return null;
}
function charcount(entrada,salida,texto,length)
 {
    var entradaObj=getObject(entrada);
	var salidaObj=getObject(salida);
	salidaObj.value=entradaObj.value.length;
	var longitud=length - salidaObj.value;
    
	if(longitud <= 0) 
	{
		longitud=0;
		texto='<span class="disable">&nbsp;'+texto+'&nbsp;</span>';
		entradaObj.value=entradaObj.value.substr(0,length);
	}
	salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}

function getObjectOpener(obj)
 {
	var theObj;
	if(window.opener.document.all)
	 {
		if(typeof obj=="string")
		{
			return window.opener.document.all(obj);
		} 
		else
		{
			return obj.style;
		}
	}
	if(window.opener.document.getElementById) 
	{
		if(typeof obj=="string") 
		{
			return window.opener.document.getElementById(obj);
		}
		else 
		{
			return obj.style;
		}
	}
	return null;
}


function SelectCompany(id, name, indexid, companyid, spanid)
{
    var indexidObj=getObjectOpener(indexid);
    var companyidObj=getObjectOpener(companyid);
    var spanidObj=getObjectOpener(spanid);
	var companystr
	companystr = "<a href=company-list.jsp?comp_id=" + id + " target = _blank><b>" + name + " (" + id + ")</b></a>";
    indexidObj.value = id;
   	companyidObj.value = companystr;
    spanidObj.innerHTML = companystr;
    alert(companyid + " selected.")
    window.close();
}
function SelectCompanyOrder(id, name, indexid, companyid, spanid)
{
    var indexidObj=getObjectOpener(indexid);
    var companyidObj=getObjectOpener(companyid);
    var spanidObj=getObjectOpener(spanid);
    var companystr
	companystr = "<a href=company-list.jsp?comp_id=" + id + " target = _blank><b>" + name + " (" + id + ")</b></a>";
     indexidObj.value = id;
     spanidObj.innerHTML = companystr;
     alert(companyid + " selected.")
     window.close();
}

function SelectChannelCompOrder(id, name, indexid, companyid, spanid)
{
    var indexidObj=getObjectOpener(indexid);
    var companyidObj=getObjectOpener(companyid);
    var spanidObj=getObjectOpener(spanid);
    var companystr
	companystr = "<a href=comp-list.jsp?comp_id=" + id + " target = _blank><b>" + name + " (" + id + ")</b></a>";
     indexidObj.value = id;
     spanidObj.innerHTML = companystr;
     alert(companyid + " selected.")
     window.close();
}

function SelectCompanyActivity(id, name, indexid, compid, spanid, ptcid, ptc, ph1id, ph1, ph2id, ph2)
{
	var indexidObj=getObjectOpener(indexid);
	var compidObj=getObjectOpener(compid);
	var spanidObj=getObjectOpener(spanid);
	var ptcidObj=getObjectOpener(ptcid);
	var ph1idObj=getObjectOpener(ph1id);
	var ph2idObj=getObjectOpener(ph2id);
	var compstr
	compstr = "<a href=company-list.jsp?comp_id=" + id + " target = _blank><b>" + name + " (" + id + ")</b></a>";
	alert('e'+compstr);
    indexidObj.value = id;
    //compidObj.value = compstr;
	spanidObj.innerHTML = compstr;
	ptcidObj.value = ptc;
	ph1idObj.value = ph1;
	ph2idObj.value = ph2;
	alert(compid + " selected.")
	window.close();
}

function SelectCity(id, name, indexid, indexname, cityname, spanid, countryname, countryid)
{

    var indexidObj=getObjectOpener(indexid);
	var indexnameObj=getObjectOpener(indexname);
	var spanidObj=getObjectOpener(spanid);	
	var citystr
	citystr = name;
    indexidObj.value = id;
	indexnameObj.value = name;
	spanidObj.innerHTML = citystr;

   if(countryname!=" ")
   {  var countryidObj=getObjectOpener(countryname);
	 countryidObj.selectedIndex.value == countryid; 
    }
	alert(cityname + " selected.")
	window.close();      
}


function SelectCategory(id, name, indexid, indexname, Category, spanid)
{
 alert('hello');
    var indexidObj=getObjectOpener(indexid);
	var indexnameObj=getObjectOpener(indexname);
	var spanidObj=getObjectOpener(spanid);	
	var catstr
	catstr = "<B>"+name+"</B>";
    indexidObj.value = id;
	indexnameObj.value = name;
	spanidObj.innerHTML = catstr;
	
	alert(Category + " selected.")
	window.close();      
}

function SelectCatMember(id,name,indexid,spanid)
{
    var indexidObj=getObjectOpener(indexid);
	//var indexnameObj=getObjectOpener(indexname);
	var spanidObj=getObjectOpener(spanid);	
	var catstr
	catstr = "<b>"+name+"</b>";
    indexidObj.value = id;
	//indexnameObj.value = name;
	spanidObj.innerHTML = catstr;
	alert("Category selected.")
	alert(name + " selected.")
   //alert(Category + " selected.")
	window.close();      
}
function SelectCatAdmin(id,name,indexid,spanid)
{
	   var indexidObj=getObjectOpener(indexid);
	//var indexnameObj=getObjectOpener(indexname);
	var spanidObj=getObjectOpener(spanid);	
	var catstr
	catstr = "<b>"+name+"</b>";
        indexidObj.value = id;
//	indexnameObj.value = name;
	spanidObj.innerHTML = catstr;
	alert("Category selected.")
//	alert(Category + " selected.")
	window.close();      
}
function SelectCatMem(catid)
{
     alert('a'+catid);
     var catidObj=getObjectOpener(catid);
     alert(catid + " selected.")
    window.close();
}

function SelectCat(id,name)
{
	alert("hai."+id);
	alert("hai1."+name);
	var catstr, catcheck, maxcount;
	//alert("Category==="+name);
	catcheck = true;
	maxcount = true;
	for(k=1;k<=10;k++)
	{
		var catid=getObjectOpener("cat"+k);
		if(catid.value == "")
		{
			maxcount = false;
			break;
		}
	}
	if(maxcount==true)
	{
		alert("Maximum of 10 categories can be associated.");
	}
	else
	{
		for(j=1;j<=10;j++)
		{
			var catid=getObjectOpener("cat"+j);
			if(catid.value == id)
			{
				catcheck = false;
				alert("Category has already been selected.");
				break;
			}
		}
	}
	if(catcheck==true)
	{
		for(i=1;i<=10;i++)
		{
			var field_val=getObjectOpener("span_cat_"+i);
			var catid=getObjectOpener("cat"+i);
				if(field_val.innerHTML == "")		
				{
				catstr = "<b>"+name+"</b><a href=javascript:DeselectCat("+i+")>(Delete)</a><br>";
				field_val.innerHTML = catstr;
				catid.value = id;
				alert("Category selected.");
				break;
				}
	     }
	}
	
}
function DeselectCat(id)
{
document.getElementById("span_cat_"+id).innerHTML="";
document.getElementById("cat"+id).value="";
}

function WinCompanySelector(group)
{
	var Id = "";
	remote=window.open('company-list.jsp?all=yes&group='+ group,'Contact', 'top=50,width=700,height=500,title=no,resizable=yes,scrollbars=yes,status=yes');
	remote.focus()
	if (remote != null)
	{
		if (remote.opener == null)
			remote.opener = self;
	}
}

function WinChannelCompSelector(group)
{
	var Id = "";
	remote=window.open('comp-list.jsp?all=yes&group='+ group,'Company', 'top=50,width=700,height=500,title=no,resizable=yes,scrollbars=yes,status=yes');
	remote.focus()
	if (remote != null)
	{
		if (remote.opener == null)
			remote.opener = self;
	}
}

function WinCitySelector(group)
{
	var Id = "";
	remote=window.open('managecity.jsp?group='+ group,'City', 'top=50,width=800,height=600,title=no,resizable=yes,scrollbars=yes,status=no');
	remote.focus()
	if (remote != null)
	{
		if (remote.opener == null)
			remote.opener = self;
	}
}

function WinCatSelector(group)
{
	var Id = "";
	remote=window.open('catsearch1.jsp?group='+ group,'Category', 'top=50,width=650,height=500,title=no,resizable=yes,scrollbars=yes,status=no');
	remote.focus()
	if (remote != null)
	{
		if (remote.opener == null)
			remote.opener = self;
	}
}
function WinMemberCatSelector(group)
{
	var Id = "";
	remote=window.open('catsearch1.jsp?group='+ group,'Category', 'top=50,width=700,height=500,title=no,resizable=yes,scrollbars=yes,status=yes');
	remote.focus()
	if (remote != null)
	{
		if (remote.opener == null)
			remote.opener = self;
	}
}
function WinCategories(group)
{
	var Id = "";	
	remote=window.open('../home/catsearch2.jsp?group='+ group,'Category', 'top=50,width=650,height=500,title=no,resizable=yes,scrollbars=yes,status=no');
	remote.focus()
	if (remote != null)
	{
		if (remote.opener == null)
			remote.opener = self;
	}
}
function WinAdminCatSelector(group)
{
	var Id = "";
	remote=window.open('catsearch1.jsp?group='+ group,'Category', 'top=50,width=650,height=500,title=no,resizable=yes,scrollbars=yes,status=no');
	remote.focus()
	if (remote != null)
	{
		if (remote.opener == null)
			remote.opener = self;
	}
}



function ContactDeSelector(indexid, contactid, spanid)
{
	var indexidObj=getObject(indexid);
	var contactidObj=getObject(contactid);
	var spanidObj=getObject(spanid);
    indexidObj.value = "";
    contactidObj.value = "";
	spanidObj.innerHTML = "";
	alert(contactid + " cleared.");
}

function CompanyDeSelector(indexid, compid, spanid)
{
	var indexidObj=getObject(indexid);
	var compidObj=getObject(compid);
	var spanidObj=getObject(spanid);
    indexidObj.value = "";
    spanidObj.innerHTML = "";
	alert(compid + " cleared.");
}
function CategoryDeSelector(indexid, catid, spanid)
{
	var indexidObj=getObject(indexid);
	var catidObj=getObject(catid);
	var spanidObj=getObject(spanid);
    indexidObj.value = "";
    catidObj.value = "";
	spanidObj.innerHTML = "";
	alert(catid + " cleared.");
}

function SelectCompanyActivity(id, name, indexid, compid, spanid)
{
    var indexidObj=getObjectOpener(indexid);
	var compidObj=getObjectOpener(compid);
    var spanidObj=getObjectOpener(spanid);
	var compstr
	compstr = "<a href=company-list.jsp?comp_id=" + id + " target = _blank><b>" + name + " (" + id + ")</b></a>";
	indexidObj.value = id;
	spanidObj.innerHTML = compstr;
	alert(compid + " selected.")
	window.close();
}
function CityDeSelector(indexid, cityid, spanid)
{
	var indexidObj=getObject(indexid);
	var cityidObj=getObject(cityid);
	var spanidObj=getObject(spanid);
    indexidObj.value = "";
    //cityidObj.value = "";
	spanidObj.innerHTML = "";
	alert(cityid + " cleared.");
}
function WinPop(doc, name, top, left, width, height)
{
	remote=window.open(doc,name, 'top='+top+',left='+left+',width='+width+',height='+height+',title=no,resizable=no,scrollbars=yes,status=no');
	remote.focus()
	if (remote != null)
	{
		if (remote.opener == null)
			remote.opener = self;
	}
}


function AddItem(ObjName, DesName, CatName)
{
  //GET OBJECT ID AND DESTINATION OBJECT
  ObjID    = getObject(ObjName);
  DesObjID = getObject(DesName);
//  window.alert(DesObjID.length);
  k=0;
  i = ObjID.options.length;
  if (i==0)
    return;
  maxselected=0
  for (h=0; h<i; h++)
     if (ObjID.options[h].selected ) {
         k=k+1;
         maxselected=h+1;
         }
  if (maxselected>=i)
     maxselected=0;
  //if ( DesObjID.length + k >100 ) {
  // window.alert("You can choose 10 items at most");
  // return;
  // }

  if (CatName != "")
    CatObjID = getObject(CatName);
  else
    CatObjID = 0;
  if ( ObjID != -1 && DesObjID != -1 && CatObjID != -1 )
  { jj = CatObjID.selectedIndex;
    if ( CatName != "")
    { CatValue = CatObjID.options[jj].text;
      CatCode  = CatObjID.options[jj].value;
    }
    else
      CatValue = "";
    i = ObjID.options.length;
    j = DesObjID.options.length;
    for (h=0; h<i; h++)
    { if (ObjID.options[h].selected )
      {  Code = ObjID.options[h].value;
         Text = ObjID.options[h].text;
         j = DesObjID.options.length;
         if (Text.indexOf('&')!=-1) {
            for (k=j-1; k>=0; k-- ) {
              DesObjID.options[k]=null;
            }
            j=0;
         }
         if (Text.substring(0,1)=='-' && Text.substring(1,2)!='-') {
            for (k=j-1; k>=0; k-- ) {
              if (((DesObjID.options[k].value).substring(0,2))==(Code.substring(0,2)))
                 DesObjID.options[k]=null;
            }
            j= DesObjID.options.length;
         }
         HasSelected = false;
         
	 for (k=0; k<j; k++ ) 
        {
 //        if ((DesObjID.options[k].text).indexOf('&')!=-1){
 //             HasSelected = true;
 //         window.alert('You have selected all countries & territories, so no more items can be added.');
 //          break;
 //        }

 //         if (ObjID.options[h].selected ==true && (ObjID.options[h].text).indexOf('-')!=-1){
 //         HasSelected = true;
 //         window.alert('Can not select separator.');
 //         break;
 //        }
	   
 //        if ((DesObjID.options[k].text).indexOf('[')!=-1){
 //          if((ObjID.options[h].text).indexOf('[')==-1)
 //              {HasSelected = true;
 //               window.alert('You have selected one or more continents, so no more specific country or territory can be added. You may delete selected continents then to add countries & territories.');
 //	   break;
 //              }
 //        }else{
 //          if((ObjID.options[h].text).indexOf('[')!=-1)
 //              {HasSelected = true;
 //               window.alert('You have selected one or more countries or territories, so no more specific continent can be added. You may delete selected countries or territories, then to add continents.');
 //           break;
 //              }
 //     }
           
         if (DesObjID.options[k].value == Code)
           {  HasSelected = true;
            break;
           }
     } // end of for loop
         
         
         if ( HasSelected == false)
         { if (CatValue !="")
           { Location = GetLocation(DesObjID, CatValue);
             if ( Location == -1 )
             { DesObjID.options[j] =  new Option("---"+CatValue+"---",CatCode);
               DesObjID.options[j+1] = new Option(Text, Code);
             }//if
             else
             { InsertItem(DesObjID, Location+1);
               DesObjID.options[Location+1] = new Option(Text, Code);
             }//else
           }
           else
             DesObjID.options[j] = new Option(Text, Code);
         }//if
         ObjID.options[h].selected =false;
       }//if
    }//for
    ObjID.options[maxselected].selected =true;
  }//if
}//end of function

function DeleteItem(ObjName)
{
  ObjID = getObject(ObjName);
  minselected=0;
  if ( ObjID != -1 )
  {
    for (i=ObjID.length-1; i>=0; i--)
    {  if (ObjID.options[i].selected)
       { // window.alert(i);
          if (minselected==0 || i<minselected)
            minselected=i;
          ObjID.options[i] = null;
       }
    }
    i=ObjID.length;

    if (i>0)  {
        if (minselected>=i)
           minselected=i-1;
        ObjID.options[minselected].selected=true;
        }
  }
}

//Validate float on lost focus &&
function ValidateFloat(textid, textname)
{
	var textidObj=getObject(textid);
	var field_val = textidObj.value;
	//alert(textidObj.value.length);
	if (textidObj.value.length != 0) {
	pat=/^[0-9.,]+$/
		if(field_val.match(pat)){return (true);}
		else{alert(textname + " is not numeric. \nShould consist numbers from 0 - 9 and . or ,!");
		textidObj.focus();
		return (false);}
	}
}

function toNumber(textid, textname)
{	
	var textidObj=getObject(textid);
     var newString = "";		 // REVISED/CORRECTED STRING
     var count = 0;			 // COUNTER FOR LOOPING THROUGH STRING 	
		       			 // LOOP THROUGH STRING
    for (i = 0; i < textidObj.value.length; i++) 
    {
        ch = textidObj.value.substring(i, i+1);  // CHECK EACH CHARACTER
        //if ((ch >= "0" && ch <= "9") || (ch == ".")) 
		if (ch >= "0" && ch <= "9")
        {
            newString += ch;
        }
    }
    textidObj.value = newString;
    return (false);
}

function toFloat(textid, textname)
{	
	var textidObj=getObject(textid);
     var newString = "";		 // REVISED/CORRECTED STRING
     var count = 0;			 // COUNTER FOR LOOPING THROUGH STRING 	
		       			 // LOOP THROUGH STRING
    for (i = 0; i < textidObj.value.length; i++) 
    {
        ch = textidObj.value.substring(i, i+1);  // CHECK EACH CHARACTER
        if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == ",")) 
        {
            newString += ch;
        }
    }
    textidObj.value = newString;
    return (false);
}

//Validate date on lost focus &&
function ValidateDate(textid, textname)
{
	var textidObj=getObject(textid);
	var field_val = textidObj.value;
	//alert(textidObj.value.length);
	if (textidObj.value.length != 0) {
	pat=/^[0-9/]+$/
		if(field_val.match(pat)){return (true);}
		else{alert(textname + " is not a valid date. \nShould be in the format dd/mm/yyyy!");
		textidObj.focus();
		return (false);}
	}
}

function charcount(entrada,salida,texto,length)
 {
    var entradaObj=getObject(entrada);
	var salidaObj=getObject(salida);
	salidaObj.value=entradaObj.value.length;
	var longitud=length - salidaObj.value;
    
	if(longitud <= 0) 
	{
		longitud=0;
		texto='<span class="disable">&nbsp;'+texto+'&nbsp;</span>';
		entradaObj.value=entradaObj.value.substr(0,length);
	}
	salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}

function confirmdelete(form)
 {
 var ans;
 ans=window.confirm('Sure you want to delete!');
 //alert (ans);                      
 if (ans==true)
  {
    //alert('Yes');
	//document.Form1.hdnbox.value='Yes';
   }
 else
 {
    //alert('No');
	return(false); 
    //document.Form1.hdnbox.value='No';
 }
 }
 
 
 
 function CheckAll(frm)
{

var field_val=eval('document.'+frm+'.elements');

count = field_val.length;
    for (i=0; i < count; i++) 
	{
    field_val[i].checked = 1;
	}
}
function UncheckAll(frm){
var field_val=eval('document.'+frm+'.elements');
count = field_val.length;
    for (i=0; i < count; i++) 
	{
	field_val[i].checked = 0;
	}
	
	
	function confirmdelete(form)
 {
 var ans;
 ans=window.confirm('Sure you want to delete!');
 //alert (ans);                      
 if (ans==true)
  {
    //alert('Yes');
	//document.Form1.hdnbox.value='Yes';
   }
 else
 {
    //alert('No');
	return(false); 
    //document.Form1.hdnbox.value='No';
 }
 }
	}
	
function confirmdelete(form)
 {
 var ans;
 ans=window.confirm('Sure you want to delete!');
 //alert (ans);                      
 if (ans==true)
  {
    //alert('Yes');
	//document.Form1.hdnbox.value='Yes';
   }
 else
 {
    //alert('No');
	return(false); 
    //document.Form1.hdnbox.value='No';
 }
 }
 
 
 // to generate of thumbnail of webpage
 
 
 
 function update() {
  var w = content.innerWidth + content.scrollMaxX;
  var h = content.innerHeight + content.scrollMaxY;
  if (w > 10000) w = 10000;
  if (h > 10000) h = 10000;

  var container = document.getElementById("win");
  var canvasW = container.boxObject.width;
  var scale = canvasW/w;
  var canvasH = Math.round(h*scale);

  var canvas = document.getElementById("canvas");
  canvas.style.width = canvasW+"px";
  canvas.style.height = canvasH+"px";
  canvas.width = canvasW;
  canvas.height = canvasH;
  var ctx = canvas.getContext("2d");
  ctx.clearRect(0, 0, canvasW, canvasH);
  ctx.save();
  ctx.scale(canvasW/w, canvasH/h);
  ctx.drawWindow(content, 0, 0, w, h, "rgb(0,0,0)");
  ctx.restore();
}

var NavLoadObserver = {
  observe: function(aWindow)
  {
    update();
  }
};


function start() {
  var obs = Components.classes["@mozilla.org/observer-service;1"].
    getService(Components.interfaces["nsIObserverService"]);
  obs.addObserver(NavLoadObserver, "EndDocumentLoad", false);
}

