

var currentsec = 0;	
var currentmin = 0;
var currentmil = 0;
var keepgoin = false;	

var	Strsec = "00";
var Strmin = "00";
var Strmil = "00";


function openWin(fileName, width, height)
{

DispWin=window.open(fileName,"DispWin", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=auto, resizable=no, dependent, height=" + height + ",width=" + width + ", left=100, top=100") 

}

function openWind(fileName, width, height)
{

	w = parseInt((screen.availWidth - width)/2);
	h = parseInt((screen.availHeight - height)/2);

	DispWin=window.open(fileName,'DispWin', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=auto, resizable=yes, dependent, height=' + height + ',width=' + width + ', left='+w+', top='+h+"'") 

}

function openWindScroll(fileName, width, height)
{
DispWin=window.open(fileName,"DispWin", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, dependent, height=" + height + ",width=" + width + ", left=50, top=50") 

}


function getCookie(name) {
var start;
var end;
var result;

	start = document.cookie.indexOf(name);
    if (start >= 0) {
		start += name.length;
		end = document.cookie.indexOf(";", start);
		if (end == -1) 
	            end = document.cookie.length;
        result = document.cookie.substring(start + 1, end);
	}
	else {
		result = "";
	}
	return result;

}


function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function saveCookie(name,value,days) {
	if (days) {
		if (days == -1) {
			var date = new Date();
			date.setFullYear(date.getFullYear() + 1);
			var expires = "; expires="+date.toGMTString();		
		}
		else {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
	}
	else 
		expires = "";
		
	document.cookie = name+"="+escape(value)+expires+"; path=/";

}



function readCookie(name) {
	var name = name+"=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(name) == 0)
		return unescape(c.substring(name.length,c.length));
	}
		return null;
}


function getXmlResponse(url) {

	try {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttp.open("GET", url, false);
		//xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-1")	
		//xmlHttp.onreadystatechange = returnXmlResponse;
		//alert("url= "+url);
		xmlHttp.send();
		var xmlDoc=xmlHttp.responseText;	
		return xmlDoc;		
	}catch(e) {
		addToLog("getXmlResponse <b>Error:</b> "+e.description+"<br>url: "+url,10);
		alert("getXmlResponse Error: "+e.description+"\nurl: "+url);
		return "";
	}

}


function returnXmlResponse() {

	if(xmlHttp && xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200)
			alert("ready");
	//		return xmlDoc;
	}
	
	//if(xmlHttp.readyState == 4) {
	//	var xmlDoc=xmlHttp.responseText;	
	//	return xmlDoc;
	//}

}


function getXmlResponse_new(url) {

	
	txt = createFlash("loading_wave_stdwave_1.swf",140,56,"#f7efde");
	document.all.item("msgicon").innerHTML = txt;	
	
	myXmlDoc = "";
	myXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	myXmlHttp.open("GET", url, true);
	//xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-1")	
	myXmlHttp.onreadystatechange = xmlStateChange;
	myXmlHttp.send();
}


function sendXmlResponse() {
var response;
	
	try {
		if (myXmlHttp.readyState == 4) {
			response = myXmlHttp.responseText;	
			myXmlHttp = null;
	
			if (response.substring(0,2) == "ok") {
				//alert("Zone updated");
			}
			else {
				if (response == "0") {
					alert("Error: \n" + response);
				}
				else {
					alert("sendXmlResponse=\n "+response);
				}
			}	
		}
	}
	catch(e) {
		addToLog("sendXmlResponse <b>Error:</b> "+e.description,10);
		alert("Error in sendXmlResponse: "+e.description);
		response = "";
	}

		return response;
}


function xmlStateChange() {

	 if (myXmlHttp.readyState == 4) {
		myXmlDoc=myXmlHttp.responseText;	
		document.all.item("msgicon").innerHTML = "";
		return myXmlDoc;
	 }
	 
}


function sendXml(url,xml) {
	
	 myXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	 myXmlHttp.open("POST", url, true);
	 //myXmlHttp.setRequestHeader("Content-Type","text/xml");
	 myXmlHttp.onreadystatechange = sendXmlResponse;
	 myXmlHttp.send(xml);
  
}





function hexdec(f1) {
   f1.hexval.value = f1.hexval.value.toUpperCase();
   rval = parseInt(f1.hexval.value,16);
   f1.result.value=rval;
}

function dechex(f1) {
   rval= f1.redval.value;
   rhex = tohex(rval);
   f1.hexnot.value = rhex;
}

function tohex(i) {
   a2 = ''
   ihex = hexQuot(i);
   idiff = eval(i + '-(' + ihex + '*16)')
   a2 = itohex(idiff) + a2;
   while( ihex >= 16) {
      itmp = hexQuot(ihex);
      idiff = eval(ihex + '-(' + itmp + '*16)');
      a2 = itohex(idiff) + a2;
      ihex = itmp;
   } 
   a1 = itohex(ihex);
   return a1 + a2 ;
}

function hexQuot(i) {
   return Math.floor(eval(i +'/16'));
}

function itohex(i) {
   if( i == 0) {
      aa = '0' }
   else { if( i== 1) {
             aa = '1'}
      else {if( i== 2) {
               aa = '2'}
         else {if( i == 3) {
                  aa = '3' }
            else {if( i== 4) {
                     aa = '4'}
               else {if( i == 5) {
                        aa = '5' }
                  else {if( i== 6) {
                           aa = '6'}
                     else {if( i == 7) {
                              aa = '7' }
                        else {if( i== 8) {
                                 aa = '8'}
                           else {if( i == 9) {
                                     aa = '9'}
                              else {if( i==10) {
                                       aa = 'A'}
                                 else {if( i==11) {
                                          aa = 'B'}
                                    else {if( i==12) {
                                             aa = 'C'}
                                       else {if( i==13) {
                                                aa = 'D'}
                                          else {if( i==14) {
                                                   aa = 'E'}
                                             else {if( i==15) {
                                                      aa = 'F'}

                                             }
                                          }
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
   return aa
}


function createFlash(name,width,height,color) {
var txt;

	txt = "";
   	txt += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
	txt += "codebase='http://download.macromedia.com/pub/shockwave/cabs";
	txt += "/flash/swflash.cab#3,0,0,0' ";
	txt += "width='" + width + "' ";
	txt += "height='" + height + "'>";
	txt += "<param name='SRC' value='";
	txt += "../flash/";
	txt += name;
	txt += "'>";
	txt += "<param name=bgcolor value='";
	txt += color;
	txt += "'>";
	txt += "<embed src='";
	txt += "../flash/";
	txt += name;
	txt += "' ";
	txt += "pluginspage='http://www.macromedia.com/shockwave/download/";
	txt += " type='application/x-shockwave-flash' ";
	txt += "width='";
	txt += width;
	txt += "' ";
	txt += "height='";
	txt += height;
	txt += "' ";
	txt += "bgcolor='";
	txt += color;
	txt += "' ";
	txt += "quality=high ";
	txt += "play=true ";
	txt += "'>";
	txt += "</embed></object>";
	
	return txt;
	
}


function gotimer(){

	try {
		if(keepgoin){
			currentmil+=1;
			if (currentmil==10){	
			    currentmil=0;	
			    currentsec+=1;
			}
			if (currentsec==60){	
			    currentsec=0;	
			    currentmin+=1;	
			}
			Strsec=""+currentsec;	
			Strmin=""+currentmin;	
			Strmil=""+currentmil;	
			if (Strsec.length!=2){	
			    Strsec="0"+currentsec;
			}			
			if (Strmin.length!=2){	
			    Strmin="0"+currentmin;
			}
			document.timer.seconds.value=Strsec	
			document.timer.minutes.value=Strmin;	
			document.timer.milsecs.value=Strmil;
			setTimeout("gotimer()", 100);	
		}
	}catch(e) {
	}
	
}

function startover() {	 

	keepgoin = false;	
	currentsec = 0;
	currentmin = 0;
	currentmil = 0;
	Strsec = "00";
	Strmin = "00";
	Strmil = "00";
	
}

function createTimerGui() {
var txt;

	txt = "";
	txt += "<CENTER>";
	//txt += "<FONT SIZE=5 FACE='Tahoma,Arial,Arial Narrow,Sans Serif'></FONT>";
	txt += "<FORM NAME='timer' ONRESET=startover()>";
	txt += "<TABLE BORDER=1 BGCOLOR='#777777'>";
	txt += "<TR><TD BGCOLOR='#000000' COLSPAN=3>";
	txt += "<DIV STYLE='font-size:30px;font-family:LCD,Sans Serif;color:#00ff00'>";
	txt += "&nbsp;";
	txt += "<INPUT TYPE='text' NAME='minutes' VALUE='00' SIZE=3 STYLE='height:30px;border:0;font-size:30px;width:33px;font-family:LCD,Sans Serif;color:#00ff00;background:#000000'>";
	txt += ":";
	txt += "<INPUT TYPE='text' NAME='seconds' VALUE='00' SIZE=3 STYLE='height:30px;border:0;font-size:30px;width:35px;font-family:LCD,Sans Serif;color:#00ff00;background:#000000'>";
	txt += ":";
	txt += "<INPUT TYPE='text' NAME='milsecs' VALUE='0' SIZE=3 STYLE='height:30px;border:0;font-size:30px;width:30px;font-family:LCD,Sans Serif;color:#00ff00;background:#000000'>";
	txt += "</TD></TR><TR><TD CELLPADDING=5>";
	txt += "<INPUT TYPE='button' NAME='start' VALUE='Start' class='buttonCSS0' ONCLICK='keepgoin=true;gotimer()'>";
	txt += "</TD><TD>";
	txt += "<INPUT TYPE='button' NAME='pause' VALUE='Pause' class='buttonCSS0' ONCLICK='keepgoin=false;'>";
	txt += "</TD><TD>";
	txt += "<INPUT TYPE='reset' NAME='reset' VALUE='Reset' class='buttonCSS0'>";
	txt += "</TD></TR></TABLE>";
	txt += "</FORM>";
	txt += "</CENTER>";

	return txt;
}


function checkBrowser() {

	screenwidth = Math.floor(screen.availWidth);
	
    var agt = navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

	if (!is_ie5up) {
		alert("Game of Floy can only be run on MSIE 5.01 or higher");
		return false;
	}
	
	if (screenwidth < 1000) {
		alert("Game of Floys requires screen resolution of 1024x768 or higher");
		return false;
	}

	return true;
}


