location.href="http://realestate.optimumhomes.com/";

function sw_img(img_name,file_name) {
	document.images[img_name].src=file_name;
}

function informationIsGood() {
	if (document.loginForm.userID.value == "") { errMsg = "User name is missing"; return false; }
	if (document.loginForm.passwd.value == "") { errMsg = "Password is missing"; return false; }
	return true;
}

//e is event object passed from function invocation
function checkEnter(e){ 
	//literal character code will be stored in this variable
	var characterCode;

	//if which property of event object is supported (NN4)
	if(e && e.which)
	{ 
		e = e;
		//character code is contained in NN4's which property
		characterCode = e.which;
	}
	else
	{
		e = event;
		//character code is contained in IE's keyCode property
		characterCode = e.keyCode ;
	}

	//if generated character code is equal to ascii 13 (if enter key)
	if(characterCode == 13)
	{ 
		//submit the form
		submitLogin();
		return false;
	}
	else
	{
		return true;
	}
}


		function submitLogin(){
			syncLogin(document.loginForm.userID.value, document.loginForm.passwd.value, 'syncLoginIframe');
			if(informationIsGood()){
				document.loginForm.submit();
			}
			else
				alert(errMsg);
		}

		var loginSyncWin;
		function openSpawner(url,name) {
			loginSyncWin = window.open(url,name,'width=10,height=10,top=5000,left=5000,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
		}
				
		function syncLogin(username, password){
			var url = "http://www.optimumautos.com/ocsweblogin?";
			var queryString;
			queryString = addToAssociativeArray(queryString,"userID",username);
			queryString = addToAssociativeArray(queryString,"passwd",password);
			queryString = addToAssociativeArray(queryString,"comingFrom","autos_home.jsp");
			queryString = addToAssociativeArray(queryString,"redirectpage","autos_home.jsp");
			url += createQueryStringFromArray(queryString);
//			openSpawner(url,'loginSync');
		}
		
		function syncLogout(){
			var url = "http://www.optimumautos.com/ocsweb_logout.jsp";
//			openSpawner(url,'loginSync');
		}

		function closeWin(winHandle){
		if (winHandle && !winHandle.closed)
		          {winHandle.close();}
		}
		
					
		function createQueryStringFromArray(arrayObj){
			var queryString = "";
			if(arrayObj != null){
				for ( key in arrayObj ){
						if(queryString != ""){
							queryString+= "&";
						}
						queryString = queryString + escape(key) + "=" +  escape(arrayObj[key]);
				}
			}
			return queryString;
		}

		function addToAssociativeArray(arrayObj, name, value){
			if(arrayObj == null){
				arrayObj = new Object();
			}
		
			// replace ' ' with +
			value = value.replace(' ','+')
		
			arrayObj[name] = value;
		
			return arrayObj;
		}

		function reloadIframe(iframeId, newSrc){
			var timeStamp = new Date();
			var iframeObj = document.getElementById(iframeId);
			if(iframeObj)
			{
				if(newSrc.indexOf("?") > -1)
					newSrc = newSrc + "&";
				else
					newSrc = newSrc + "?";
				newSrc += "cbreak" + timeStamp.getTime() + "=" + timeStamp.getTime();
				iframeObj.src = newSrc;
			}
		}


        window.name = "mainWin";
        var nWindow;
        var prgid="";
        function NewWindow(pageURL,pageName,w,h,scroll){
                //*** Auto Center Popup Window Generator
                LeftPosition    = (screen.width) ? (screen.width-w)/2 : 0;
                TopPosition             = (screen.height) ? (screen.height-h)/2 : 0;
                settings                = "height="+h+",width="+w+",top="+TopPosition+",left="+LeftPosition+",scrollbars="+scroll+",resizable";
                nWindow                 = window.open(pageURL,pageName,settings);
                nWindow.focus();
        }
        
        
   function popupcityselecta()
   {
		NewWindow('re_city_selection_multiple.jsp?searchtype=re_advance_buying&homeType=buy','city_selection',512,402,'no');
   }

		var bikky = document.cookie;

		function getCookie (name) {
		   var arg = name + "=";
		   var alen = arg.length;
		   var clen = document.cookie.length;
		   var i = 0;
		   while (i < clen) {
		      var j = i + alen;
		      if (document.cookie.substring(i, j) == arg) {
		         var end = document.cookie.indexOf (";", j);
		         if (end == -1)
		            end = document.cookie.length;
		         return unescape(document.cookie.substring(j, end));
		      }
		      i = document.cookie.indexOf(" ", i) + 1;
		      if (i == 0) break;
		   }
		   bikky = document.cookie; // update bikky
		   return null;
		}
		
		function setCookie (name, value, expires, path, domain, secure) {
		   document.cookie =
		      name + "="
		      + escape(value)
		      + ((expires) ? "; expires=" + expires.toGMTString() : "")
		      + ((path) ? "; path=" + path : "")
		      + ((domain) ? "; domain=" + domain : "")
		      + ((secure) ? "; secure" : "");
		    bikky = document.cookie; // update bikky
		}


		function clearCookieValue(name){
			document.cookie = name + "=";
		}
function newWin(pageUrl){
    newwin = window.open(pageUrl,'NewWin','status=0,width=275,height=135,screenX=500,screenY=175,left=500,top=175');
    newwin.focus();
 }
                function checkEnter(e){ //e is event object passed from function invocation
                var characterCode //literal character code will be stored in this variable

                if(e && e.which){ //if which property of event object is supported (NN4)
                e = e
                characterCode = e.which //character code is contained in NN4's which property
                }
                else{
                e = event
                characterCode = e.keyCode //character code is contained in IE's keyCode property
                }

                if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
                submitLogin() //submit the form
                return false
                }
                else{
                return true
                }
                }

                
function $(id) 
{
	return document.getElementById(id);
}

function getDDValue(dd) 
{
	if (!dd) return "";
	
	try {
		return dd.options[dd.selectedIndex].value;
	} catch (err) {		
		return "";
	}
}

function setSelectedDDValue(dd, val)
{
	if (!dd) return -1;
	
	for (var i = 0; i < dd.options.length; i++) {
	
		if (dd.options[i].value == val) {			
			dd.options[i].selected = true;
			dd.selectedIndex = i;			
			return i;
		}
	}
	
	return -1;
}

// (based on getArgs(), Example 145. Javascript the Definitive Guide.)
function getParams() 
{
	var params = new Array();
	var query = location.search.substring(1);	
	var pairs = query.split("&");
	
	for (var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf("=");

		if (pos == -1) {
			continue;
		}
		
		var param = pairs[i].substring(0, pos);
		var value = pairs[i].substring(pos + 1);
		params[param] = unescape(value);
	}
	
	return params;
}

function rnull(str, replacement) 
{	
	return (str == null || str == undefined)? replacement : str;
}