function GetCookie(name)
{ var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0)
  { begin = dc.indexOf(cname);
    if (begin != -1)
    { begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
      return unescape(dc.substring(begin, end));
    }
  }
  return null;
}

function TestCookie() {

  user_name = GetCookie("oreo_user_name");
  session = GetCookie("oreo_session");

var i;
my_redirect = "yes";
var Urls = new Array();
Urls[0] = 'contact.html';
Urls[1] = 'metrent_us_map.html';
Urls[2] = 'ads/index.html';
	if ((user_name != null) && (session != null)) { 
	   if ((user_name != "") && (session != "")) { 
		for(i = 0; i < 3; i++) {
			if (window.location == location.protocol + "//" + location.host + "/" + Urls[i]) {
			//alert(location.protocol + "//" + location.host + "/" + Urls[i]);
				my_redirect = "no";
			}
		}
		if ((my_redirect == "yes") && (window.location != location.protocol + "//" + location.host + "/cgi-bin/index.pl")) {
			//alert(user_name);
			//alert(session);
			//alert(my_redirect);
			window.location = location.protocol + "//" + location.host + "/cgi-bin/index.pl";
		}
	    }
	}
}

function SignOut(user_name, ses_id, uid) {
  var oneWeek     = -1 * 24 * 60 * 60 * 1000;
  var rst_cookie_date = new Date();  // current date & time
  rst_cookie_date.setTime (rst_cookie_date.getTime() + (oneWeek));

 // document.cookie = cookie_name += "=; expires=" + rst_cookie_date.toGMTString();

document.cookie = "oreo_user_name=; path=/; domain=metrent.com; expires=" + rst_cookie_date.toGMTString();
document.cookie = "oreo_session=; path=/; domain=metrent.com; expires=" + rst_cookie_date.toGMTString();
document.cookie = "oreo_iid=; path=/; domain=metrent.com; expires=" + rst_cookie_date.toGMTString();
document.cookie = "oreo_zip=; path=/; domain=metrent.com; expires=" + rst_cookie_date.toGMTString();
document.cookie = "oreo_user_type=; path=/; domain=metrent.com; expires=" + rst_cookie_date.toGMTString();
document.cookie = "oreo_ses_id=; path=/; domain=metrent.com; expires=" + rst_cookie_date.toGMTString();
document.cookie = "oreo_realtor=; path=/; domain=metrent.com; expires=" + rst_cookie_date.toGMTString();
document.cookie = "create_login=; path=/; domain=metrent.com; expires=" + rst_cookie_date.toGMTString();

if ((user_name != null) && (ses_id != null)) {
	window.location = "http://" + location.host + "/cgi-bin/logout.pl?" + user_name +"&"+ ses_id +"&"+ uid +"";
}
else {
	window.location = "http://" + location.host + "/index.html";
}


}

function pop_saved(url)
{
   var newwindow;
   var features, w = 40, h = 20;
   var top = (screen.height - h)/2, left = (screen.width - w)/2;
   if(top < 0) top = 0;
   if(left < 0) left = 0;
   features = 'top=' + top + ',left=' +left;
   features += ',height=' + h + ',width=' + w + ',resizable=no';
        newwindow=window.open(url,'name', features);
        if (window.focus) {newwindow.focus()}
}

function pop_send(url)
{
   var newwindow;
   var features, w = 440, h = 350;
   var top = (screen.height - h)/2, left = (screen.width - w)/2;
   if(top < 0) top = 0;
   if(left < 0) left = 0;
   features = 'top=' + top + ',left=' +left;
   features += ',height=' + h + ',width=' + w + ',resizable=yes';
        newwindow=window.open(url,'name', features);
        if (window.focus) {newwindow.focus()}
}

function pop_contact(url)
{
   var newwindow;
   var features, w = 640, h = 340;
   var top = (screen.height - h)/2, left = (screen.width - w)/2;
   if(top < 0) top = 0;
   if(left < 0) left = 0;
   features = 'top=' + top + ',left=' +left;
   features += ',height=' + h + ',width=' + w + ',resizable=yes';
        newwindow=window.open(url,'name', features);
        if (window.focus) {newwindow.focus()}
}

function popup(url)
{
   var newwindow;
   var features, w = 640, h = 640;
   var top = (screen.height - h)/2, left = (screen.width - w)/2;
   if(top < 0) top = 0;
   if(left < 0) left = 0;
   features = 'top=' + top + ',left=' +left;
   features += ',height=' + h + ',width=' + w + ',resizable=yes';
        newwindow=window.open(url,'name', features);
        if (window.focus) {newwindow.focus()}
}

function pop_lookup(url)
{
   var newwindow;
   var features, w = 435, h = 485;
   var top = (screen.height - h)/2, left = (screen.width - w)/2;
   if(top < 0) top = 0;
   if(left < 0) left = 0;
   features = 'top=' + top + ',left=' +left;
   features += ',height=' + h + ',width=' + w + ',resizable=yes';
        newwindow=window.open(url,'name', features);
        if (window.focus) {newwindow.focus()}
}

function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]\\}\\{\\&\\^||$\\#\\!\\*\\+\\%"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

em_len=emailStr.length

if (em_len>100) {
   var errStr="This address is too long!"
   alert(errStr)
   return false
}

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    alert("The username doesn't seem to be valid.")
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

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>3) {
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

//document.getElementById('btSubmit').disabled=true;
return true;
}

function loadURL(URL)
{if(typeof URL!="undefined"&&URL!=null&&URL!="")
{window.location.href=URL;}}

function onQuickButton(selectThis)
{document.getElementById('sub_type').options[selectThis].selected=true;}

function countText(field,countIt,maxchars,linecounter)
{var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;
	if (charcnt > maxchars) { 
		field.value = field.value.substring(0, maxchars);
	}
	else { 
	var charsLeft = parseInt(maxchars - charcnt) ;
	document.getElementById(countIt).innerHTML="Avail Chars: "+charsLeft+""
		if (charsLeft==0) {
			document.getElementById(countIt).style.backgroundColor = "#FF0000";
		} else {
			document.getElementById(countIt).style.backgroundColor = "#99FFFF";
		}
	}
}

