var isIE = navigator.appName.indexOf("Explorer") != -1;
var isNav = navigator.appName.indexOf("Netscape") != -1;
var isW3C = (document.getElementById) ? true : false;

var isWin = navigator.userAgent.indexOf("Win") != -1;
var isMac = navigator.userAgent.indexOf("Mac") != -1;
var isUnix = navigator.userAgent.indexOf("X11") != -1;

//creates a form in a frame and submits it
// arguments[0]  is the frame to load
// arguments[1]  is the Action
// additional arguments pairs will be considered name value pairs
function postToFrame(){

   if(!arguments[0] || arguments[0] == "" || !arguments[1] || arguments[1] == "")
      return;

   var html = "<HTML><BODY BGCOLOR=#000000>\n";
      
   html += "<FORM NAME=PostForm METHOD=POST ACTION='" + arguments[1] + "'>\n";

   var ix;
   for(ix = 2; ix < arguments.length ; ix += 2){
      html += "  <INPUT TYPE=hidden NAME='" + arguments[ix] + "' VALUE=\"" + arguments[ix+1] + "\">\n";
   }

   html += "</form><SCRIPT LANGUAGE=JavaScript> document.PostForm.submit(); </script></body></html>";

   //if(!confirm("Post HTML:\r\n\r\n" + html)){
   	//return false;
   //}

   var doc = eval("top." + arguments[0] + ".document");
							    
   doc.close;

   doc.open; 

   doc.write(html);
}

//begins a form in a frame to be submitted
// arguments[0]  is the Action
// additional argument pairs will be considered name value pairs.
//
// - use postForm() to complete the form and submit it
//
function generateForm(){

   if(!arguments || arguments[0] == "")
      return "";

   var html = "<HTML><BODY BGCOLOR=#000000>\n";
									   
   html += "<FORM NAME=PostForm METHOD=POST ACTION='" + arguments[0] + "'>\n";

   var ix;
   for(ix = 1; ix < arguments.length ; ix += 2){
      html += "  <INPUT TYPE=hidden NAME='" + arguments[ix] + "' VALUE=\"" + arguments[ix+1] + "\">\n";
   }

   return html;
}

//Adds a name value pair to a form created by generateForm()
//  - use this to add more values before calling postForm()
function addToForm(name,value){
   return "  <INPUT TYPE=hidden NAME='" + name + "' VALUE=\"" + value + "\">\n";
}

//Submits a form that was created by generateForm();
function postForm(frame,html){

   if(!frame || frame == "" || !html || html == "")
      return;

   html += "</form><SCRIPT LANGUAGE=JavaScript> document.PostForm.submit(); </script></body></html>";

   //if(!confirm("post: " + html)){
   	//return false;
   //}

   var doc = eval("top." + frame + ".document");
   doc.close;
   doc.open; 
   doc.write(html);   
}

function getCookie(name){
   var value = "";

   var allcookies = document.cookie;
   var pos = allcookies.indexOf(name);

   if(pos != -1){
      var start = pos + name.length + 1;
      var end = allcookies.indexOf(";",start);
      if(end==-1) end = allcookies.length;
      value = allcookies.substring(start,end);
   }

   return value;
}

function setCookie(name,value){
   var nextyear = new Date();
   nextyear.setFullYear(nextyear.getFullYear()+1);
   document.cookie = name + "=" + value + "; path=/; expires=" + nextyear.toGMTString();
}

function clearCookie(name){
   document.cookie = name + "=deleted; path=/; expires=Mon, 01-Jan-2001 00:00:00 GMT";
}

function safe(str){
	// make sure str doesn't have any XSS hacks or other embedded html
	str = str.replace(/\r\n/g, "\n");
	str = str.replace(/\r/g, "\n");

	//strip embedded html
	str = str.replace(/&/g, "&amp;");
	str = str.replace(/\"/g, "&quot;");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");

	return str;
}

function get_element(doc, id){
	if(isW3C){
		return doc.getElementById(id);
	}

	var e = eval(doc + "." + id);
	if(e)
		return e;

	e = eval(doc + ".all." + id);
	if(e)
		return e;

	return null;
}

function safeQuotes(str){
	//this is an ugly way to do it... but I find it the most portable 
	//solution
  	var ix = 0, jx = 0;
	var cleanstr = "";
	while( (ix = str.indexOf('"',jx)) != -1){
		cleanstr += str.slice(jx,ix);
		cleanstr += "&quot;";
		jx = ix + 1;
	}

	cleanstr += str.slice(jx);

	return cleanstr;
}

function cleanQuotes(str){
	//this is an ugly way to do it... but I find it the most portable 
	//solution
  	var ix = 0, jx = 0;
	var cleanstr = "";
	while( (ix = str.indexOf('"',jx)) != -1){
		cleanstr += str.slice(jx,ix);
		cleanstr += "'";
		jx = ix + 1;
	}

	cleanstr += str.slice(jx);

	return cleanstr;
}
