var cookies = document.cookie.split("; ");
function GetCookie(name) {
	for (var i=0; i < cookies.length; i++) {
		var cookie = cookies[i].split("=");
		if (cookie[0] == name) {
			return unescape(cookie[1]);
		}
	}
	return null;
}


function SetCookie(name, value, expiration) {
	if (name && value && name != "" && value != "") {
		cookies = name + "=" + escape(value) + ";";
		if (expiration) {
			cookies += " expires=" + expiration.toGMTString();
		}
		document.cookie = cookies;
		cookies = document.cookie.split("; ");
	}
}

function IsAgentLoggedIn () {
	if (GetCookie ("scaccess") == null) {
		location.href = "/page/span-classhidestgc-south-carolina-agent-login-spanstewart-title-guaranty-company";	
	}
}

var $j = jQuery.noConflict();

function GetObjectRef (ObjId) {
	if (document.getElementById) {
		return document.getElementById (ObjId);
	}
	else if (document.all) {
		return document.all[ObjId];
	}
	else {
		return null;
	}
}


function ValidateQuickSearchForm (thisForm) {
	if (thisForm.keywords.value == "") { 
		alert("Please enter one or more keyword."); 
		return false; 
	} else {
	thisForm.action="/searchResults.jsp?search=" + thisForm.keywords.value;
	}
}

function toggleMapChoice(show, hide) {
   GetObjectRef(show).style.display = "block";
   GetObjectRef(hide).style.display = "none";
   
   if (show == 'activeUsa') {
      GetObjectRef('mapchoice').style.padding = '5px 0 34px 0';
   } else {
      GetObjectRef('mapchoice').style.padding = '5px 0 20px 0';
   }
}

function verifyPartialZip(input) {
   var numOnly = input.value.replace(/[^0-9]/g, '');
   if (numOnly != input.value) {
      input.value = numOnly;
   }
}

function verifyZip(inputName) {
   var input = GetObjectRef(inputName);
   verifyPartialZip(input);
   if (input.value.match(/^[0-9]{5}$/)) {
      return true;
   } else {
      return false;
   }
}

var isSelectorMenuShown = false;
var isOverTitleServices = false;
function ToggleOrderTitleServices (e) {
	if (!e) {
		e = window.event;
	}
	e.cancelBubble = true;
	if (isSelectorMenuShown == false) {
		GetObjectRef("OrderOptions").style.display = "block";
		isSelectorMenuShown = true;
	}
	else {
		GetObjectRef("OrderOptions").style.display = "";
		isSelectorMenuShown = false;
	}
	return false;
}
function ShowOrderTitleServices (e) {
	if (!e) {
		e = window.event;
	}
	GetObjectRef("OrderOptions").style.display = "block";
	isSelectorMenuShown = true;
	isOverTitleServices = true;
}
function HideOrderTitleServices (e) {
	if (!e) {
		e = window.event;
	}
	window.setTimeout ('_HideOrderTitleServices ()', 3000);
	isOverTitleServices = false;
}
	function _HideOrderTitleServices (e) {
		if (isOverTitleServices == false) {
			GetObjectRef("OrderOptions").style.display = "";
			isSelectorMenuShown = false;
		}
	}
	function SetOverTitleServices () {
		isOverTitleServices = true;
	}
	function SetOutTitleServices () {
		window.setTimeout ('_HideOrderTitleServices ()', 3000);
		isOverTitleServices = false;
	}


var isSelectorMenuShown = false;
function ToggleOrderTitleServicesInner (e) {
	if (!e) {
		e = window.event;
	}
	e.cancelBubble = true;
	if (isSelectorMenuShown == false) {
		GetObjectRef("OrderOptionsInner").style.display = "block";
		isSelectorMenuShown = true;
	}
	else {
		GetObjectRef("OrderOptionsInner").style.display = "";
		isSelectorMenuShown = false;
	}
	return false;
}
function ShowOrderTitleServicesInnerNew (e) {
	var target = e.element ();
	var popup = $("OrderOptionsInner");
	var d1 = target.cumulativeOffset  ();
	var d2 = popup.getDimensions ();
	popup.setStyle (
		{
			left: "90px",
			display: "block"
		}
	)
	isSelectorMenuShown = true;
	isOverTitleServices = true;
	e.stop ();
}
function ShowOrderTitleServicesInner (e) {
	if (!e) {
		e = window.event;
	}
	e.cancelBubble = true;
	GetObjectRef("OrderOptionsInner").style.display = "block";
	isSelectorMenuShown = true;
	isOverTitleServices = true;
	return false;
}
function HideOrderTitleServicesInnerNew (e) {
	e.stop ();
	window.setTimeout ('_HideOrderTitleServicesInner ()', 3000);
	isOverTitleServices = false;
}
function HideOrderTitleServicesInner (e) {
	if (!e) {
		e = window.event;
	}
	e.cancelBubble = true;
	window.setTimeout ('_HideOrderTitleServicesInner ()', 3000);
	isOverTitleServices = false;
	return false;
}
	function _HideOrderTitleServicesInner () {
		if (isOverTitleServices == false) {
			GetObjectRef("OrderOptionsInner").style.display = "";
			isSelectorMenuShown = false;
		}
	}
	function SetOverTitleServicesInner () {
		isOverTitleServices = true;
	}
	function SetOutTitleServicesInner () {
		window.setTimeout ('_HideOrderTitleServicesInner ()', 3000);
		isOverTitleServices = false;
	}






function closeNav(curPageNum, nextPageId, divName) {
   GetObjectRef(divName+'-'+curPageNum).className = divName;
   GetObjectRef(divName+'-'+nextPageId).className = divName+"-show";  
}

function redirect(href) {
   location.href = href;
}

function WriteHomePageFlashMovie () {
	document.write('		<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="850" height="269" id="/images.2007/mastheadV4.swf" align="center">');
	document.write('			<param name="movie" value="/images.2007/mastheadV4.swf" />');
	document.write('			<param name="quality" value="high" />');
	document.write('			<param name="bgcolor" value="#ffffff" />');
	document.write('			<param name="wmode" value="transparent" />');
	document.write('			<embed src="/images.2007/mastheadV4.swf" quality="high" bgcolor="#ffffff" ');
	document.write('				width="850" height="269" name="/images/mastheadV4.swf" ');
	document.write('				align="middle" allowscriptaccess="sameDomain" ');
	document.write('				wmode="transparent" ');
	document.write('				type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('			<noembed>');
	document.write('			</noembed>');
	document.write('		</object>');	
}

function performSearch(start) {
   var query = location.href.parseQuery();
   if (!query.search) {
      searchOnError({'statusText':'Empty search string'});
      return;
   }
   var tmp = query.search.split(/#/, 2);
   query = escape(tmp[0]);
   if (!start && start != 0) {
      try { start = 10 * (parseInt(tmp[1]) - 1); } catch (ignored) {}
   }
   start = start && start > 0 ? start : 0;
   var options = {
      asynchronous: true,
      method: 'get',
      onSuccess: searchOnSuccess,
      onError: searchOnError
   };
   if (start > 0) {
      location.href = location.href.replace(/#.*/, '') + '#' + ((start / 10) + 1);
   }
   new Ajax.Request('/search?rows=10&start=' + start + '&q=' + query, options);
}

function searchOnSuccess(request) {
   try {
      eval("var response = " + request.responseText);
      if (response.error) {
         searchOnError({'statusText':response.error});
         return;
      }
      var params = response.responseHeader.params;
      var docs = response.response.docs;
      var totalFound = response.response.numFound;
      var html = '';

      if (docs.length > 0) {
         docs.each(function(doc) {
            var href = '/page.jsp?id=' + doc.id;
            if (doc['class'] == 'com.chaffee.stewart.beans.PressRelease') {
               href = '/pressRelease.jsp?id=' + doc.id;
               doc.summary = '<i>' + doc.date.replace(/T.*/, '') + ' News Release</i><br>' + doc.summary;
            }
            html += '<div class="result"><h3><a href="' + href + '">' + doc.headline + '</a></h3><p>' + doc.summary + '</p></div>';
         });
      } else {
         html += '<br><i>No Results Found</i>';
      }

      // Pager HTML
      if (totalFound > 10) {
         html += '<div class="Pager" id="ResultsPager2"><div class="Text">' + totalFound + ' Results Found</div>'
               + '<div class="Batch">Showing <span class="Start">' + (eval(params.start) + 1) + '</span> - <span class="End">' + (eval(params.start) + eval(params.rows))
               + '</span> out of <span class="Total">' + totalFound + '</span></div><div class="Pages">';
         var curPage = Math.floor(params.start / 10) + 1;
         var lastPage = Math.floor((totalFound - 1) / 10) + 1;
         var startPage = Math.max(1, curPage - 7);
         var endPage = Math.min(curPage + 7, lastPage);
         if (startPage > 1) {
            html += '<a class="Page">...</a><span class="Separator">|</span>';
         }
         for (var i = startPage; i <= endPage; i++) {
            html += '<a class="Page"' + (i != curPage ? ' href="#" onclick="performSearch(' + ((i - 1) * 10) + '); return false"' : '') + '>' + i + '</a>';
            if (i < lastPage) {
               html += '<span class="Separator">|</span>';
            }
         }
         if (endPage < lastPage) {
            html += '<a class="Page">...</a>';
         }
         html += '</div>';
      }
   } catch (e) {
      searchOnError({'statusText':e});
   }

   document.getElementById('SearchResults').innerHTML = '<p><div class="query">You searched for: "' + params.q + '"</div></p>' + html;
}

function searchOnError(request) {
   document.getElementById('SearchResults').innerHTML = '<p><div class="query">The was an error processing your search request</div></p><br>' + request.statusText.replace(/[\r\n]/, '<br>');
}

function PrintAgent (thisLink) {
	if (thisLink.parentNode) {
		var td = thisLink.parentNode.parentNode.parentNode.parentNode.parentNode;
		var tableHtml = td.innerHTML;
		tableHtml = tableHtml.replace (/"*agent_print"*/, "agent_print\" style=\"display: none;\"");
		var win = window.open ("about:blank", "agentPop", "height=400,width=750");
		win.document.write ('<html>');
		win.document.write ('<head>');
		win.document.write ('<link rel="stylesheet" href="/css.2007/master.css" type="text/css" />');
		win.document.write ('</head>');
		win.document.write ('<body>');
			win.document.write ('<div id="pagewrapper">');
			win.document.write ('	<div id="wrapper">');
			win.document.write ('		<div id="masthead">');
			win.document.write ('			<div id="logo"><img width="167" height="40" border="0" alt="Stewart Logo" src="images/global/spacer.gif"/></div>');
			win.document.write ('		</div>');
			win.document.write ('		<div id="mainnav">&#xa0;</div>');
			win.document.write ('		<div id="candywrapper">');
			win.document.write ('			<div class="nosubnav" id="content">');
			win.document.write ('				<br/>');
			win.document.write ('				<div id="ctl00_ContentPlaceHolder1_UpdatePanel1">');
			win.document.write ('					<div align="left" id="ctl00_ContentPlaceHolder1_divFadeArea">');
			win.document.write ('<fieldset><table cellpadding="0" cellspacing="0" border="0"><tr><td>');
			win.document.write (tableHtml);
			win.document.write ('</td></tr></table></fieldset>');
			win.document.write ('					</div>');
			win.document.write ('				</div>');
			win.document.write ('			</div>');
			win.document.write ('			<hr class="clear"/>');
			win.document.write ('			<br clear="all"/>');
			win.document.write ('		</div>');
			win.document.write ('		<div id="footer">');
			win.document.write ('			<div id="footercontent">');
			win.document.write ('				<p>');
			win.document.write ('					&copy; COPYRIGHT 2007 STEWART TITLE GUARANTY COMPANY. ALL RIGHTS RESERVED.');
			win.document.write ('					<a href="http://www.stewart.com/privacypolicy/global.htm" target="blank">Privacy policy</a>  |  ');
			win.document.write ('					<a href="http://www.stewart.com/termsofuse/global.htm" target="blank">Terms of use</a>  |  ');
			win.document.write ('					<a href="/sitemap.jsp">Site Map</a><br/>');
			win.document.write ('					Site Development By <a target="blank" href="http://www.epublishing.com">ePublishing</a>.');
			win.document.write ('				</p>');
			win.document.write ('			</div>');
			win.document.write ('		</div>');
			win.document.write ('	</div>');
			win.document.write ('</div>');
		win.document.write ('</body>');
		win.document.write ('</html>');
		win.document.close ();
		win.focus ();
		win.print ();
	}
}

$j(document).ready (
	function () {
		if ($("OrderServicesTrigger")) {
			$("OrderServicesTrigger").observe ("mouseover", ShowOrderTitleServicesInnerNew, false);
			$("OrderServicesTrigger").observe ("mouseout", HideOrderTitleServicesInnerNew, false);
		}
	}			   
);