function checkClient()
{
	var bodyTag = document.getElementsByTagName( 'body' );

	if( navigator.appVersion.indexOf( 'Win' )!= -1 )
	{
		bodyTag[0].className = 'os_win';
	}
	else if( navigator.appVersion.indexOf( 'Mac' )!= -1 )
	{
		bodyTag[0].className = 'os_mac';
	}
	else if( navigator.appVersion.indexOf( 'X11' )!= -1 )
	{
		bodyTag[0].className = 'os_unix';
	}
	else if( navigator.appVersion.indexOf( 'Linux' )!= -1 )
	{
		bodyTag[0].className = 'os_linux';
	}

}

function loadFrame()
{
	if( document.cookie.indexOf( 'SittercitySession' ) >= 0 )
	{
		sendAjaxRequest( 'cms_header_info', '', 'loadFrameResult' );
	}
	else
	{
		document.getElementById( 'masthead_container' ).className = '';
		document.getElementById( 'footer_container' ).className = '';
	}
}

function loadFrameResult( result )
{
	if( result )
	{
		var processed = eval( '(' + unescape( result ) + ')' );
		
		if( processed[ 'state' ] )
		{
			window.location = "http://www.sittercity.com/mypage.html";
		}
		else
		{
			document.getElementById( 'masthead_container' ).className = '';
			document.getElementById( 'footer_container' ).className = '';
		}
	}
}

function imgLoad()
{
	var o_scanalert_img = document.images[ "scanalert_img" ];
    if( o_scanalert_img )
    {
        document.images[ "scanalert_img" ].src = "http://images.scanalert.com/meter/www.sittercity.com/13.gif";
    }
	
	if( document.images )
	{
		loginBox = new Image( 275, 218 );
		loginBox.src= "/templates/sittercity_homepage/images/masthead/login_box.gif"; 
	}
}

function displayLoginBox()
{
	var loginBox = document.getElementById( 'login' );
	
	if( loginBox.className != 'visible' )
	{
		loginBox.className = 'visible';
		setTimeout( "document.getElementById( 'sign_in_username' ).focus();", 200 );
	}
	else
	{
		loginBox.className = 'hidden';
		document.getElementById( 'login_button' ).focus();
	}
}

function trySearchOld(form_name)
{
	var F = document.forms[ form_name ];

	zipcode_val = F.search_permitted_zipcode.value;
	zipcode_length = zipcode_val.length;
	elem = F.care_type;
	ct = elem.options[elem.selectedIndex].value;

	if( zipcode_length < 5 )
	{
		alert( 'Please enter a zipcode' );
		return false;
	}

	action_fqn = "http://babysitters.sittercity.com/";
	a_fqns = new Array();
	a_fqns[2] = "http://petsitters.sittercity.com/";
	a_fqns[3] = "http://seniorcare.sittercity.com/";
	a_fqns[4] = "http://housekeepers.sittercity.com/";
	a_fqns[5] = "http://tutors.sittercity.com/";
	if ( a_fqns[ ct ] )
	{
		action_fqn = a_fqns[ ct ];
	}

	o_gen_avail = document.getElementById( 'general_availability' );
	if( o_gen_avail )
	{
		o_gen_avail.value = ( ct == '100' ? 'F' : '' );
	}
	
	F.action = action_fqn + 'sitter_search.html';
	F.submit();

	return false;
}

// Rotate photos
var listOfPics = new Array();
var picCount = 0;

function swapPic()
{
	buildPicArray();
	RotatePic( 0 );
}

function buildPicArray( imagePostFix )
{
	picCount = 6;
	var j = 0;
	for( i = 0; i < picCount; i++ )
	{
		j = 1 + i;
		if ( document.getElementById("photo"+j) )
		{
		 listOfPics[i] = "photo" + j;
		}
	}
}

function RotatePic( imageToHide )
{
	var imageToShow;
	if( imageToHide < picCount - 1  )
	{
		imageToShow = imageToHide + 1;
	}
	else
	{
		imageToShow=0;
	}
	
	if ( listOfPics.length > 1 )
	{
		effectTransition( listOfPics[imageToHide], listOfPics[imageToShow] );
	}
	
	setTimeout( "RotatePic(" + imageToShow + ")", 4000 )
}

function swapTrigger()
{
	imgLoadCount++;

	if( imgLoadCount == 24 )
	{
		swapPic();
		setTimeout( 'document.getElementById( "default_photo" ).style.display = "none"', 2000 );
	}
}

function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function pleaseWait( susan_url ){box_height = 400; box_width = 400; window_height = ( pageHeight() / 2 ) - ( box_height / 2 ) + posTop(); window_width = ( pageWidth() / 2 ) - ( box_width ) + posLeft(); document.getElementById("search_status").innerHTML="<table id='searching_box' style=\"position:absolute; top:" + window_height + "px; left:" + window_width + "px; z-index: 10000; background-color: white; border: 1px solid black; width: " + box_width + "px; height: " + box_height + "px;\"><tr><td align='center' valign='middle'><br /><br /><br /><br /><div style='color: #c90;font-size: 26px;font-weight:normal;'>Please wait as we run your search...</div><img src=\"" + susan_url + "\"></td></tr></table>"; fixIESelect( 'searching_box', true );}
function fixIESelect(id, state){ var DivRef = document.getElementById(id); var IfrRef = document.getElementById('ie_div'); if(state){ DivRef.style.display = "block"; IfrRef.style.width = DivRef.offsetWidth; IfrRef.style.height = DivRef.offsetHeight; IfrRef.style.top = DivRef.style.top; IfrRef.style.left = DivRef.style.left; IfrRef.style.zIndex = DivRef.style.zIndex - 1; IfrRef.style.display = "block"; } else { DivRef.style.display = "none"; IfrRef.style.display = "none"; }}
function setOpacity(obj, opacity) {opacity = (opacity == 100)?99.999:opacity; obj.style.filter = "alpha(opacity:"+opacity+")"; obj.style.KHTMLOpacity = opacity/100; obj.style.MozOpacity = opacity/100; obj.style.opacity = opacity/100;}
function effectTransition( fadeOutElem, fadeInElem) { fadeOut(fadeOutElem, 100); fadeIn(fadeInElem, 0);}
function replace(element1, element2) {fadeOut(element1, 100, 'fadeIn("'+element2+'",0);');}
function fadeIn(objId,opacity) {if (document.getElementById) { obj = document.getElementById(objId); if (opacity <= 100){setOpacity(obj, opacity); opacity += 20; window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100); obj.style.display="block";}}}
function fadeOut(objId,opacity,callback){if (document.getElementById) { obj = document.getElementById(objId); if (opacity >= 0) {setOpacity(obj, opacity); opacity -= 20; window.setTimeout("fadeOut('"+objId+"',"+opacity+",'"+callback+"')", 100);} else {obj.style.display="none";if(callback!=null)eval(callback);}}}

function createAjaxObject() 
{
	var ajax_object;

	try
	{	// Try the standard way
		ajax_object = new XMLHttpRequest();

	} catch( trymicrosoft )
	{	// Standard way is a no go!
		try
		{	// Try Microsoft variant 1
			ajax_object = new ActiveXObject( "Msxm12.XMLHTTP" );

		} catch( othermicrosoft )
		{	// Still failure!
			try
			{	// Try Microsoft variant 2
				ajax_object = new ActiveXObject( "Microsoft.XMLHTTP" );

			} catch( failed )
			{	// Well we're just incompetent now, aren't we
				ajax_object = null;

			}
		}
	}

	if( ajax_object == null )
	{
		alert( "Error creating request object!" );
	}

	return ajax_object;
}

function sendAjaxRequestSSL( ajax_include, parameters, send_result_to ) 
{
	var ajax = createAjaxObject();
	var resistCache = new Date().getTime();
	
    url = 'http://www.sittercity.com/ajax_dispatcher_ssl.html?ajax_include=' + ajax_include + '&' + parameters + '&send_result_to=' + send_result_to + '&dummy=' + resistCache;
	ajax.open( 'get', url, true );
    ajax.onreadystatechange = function () { handleAjaxResponse( ajax ); };
    ajax.send( null );
}

function sendAjaxRequest( ajax_include, parameters, send_result_to ) 
{
	var ajax = createAjaxObject();
	var resistCache = new Date().getTime();
	
    url = 'http://www.sittercity.com/ajax_dispatcher.html?ajax_include=' + ajax_include + '&' + parameters + '&send_result_to=' + send_result_to + '&dummy=' + resistCache;
	ajax.open( 'get', url, true );
    ajax.onreadystatechange = function () { handleAjaxResponse( ajax ); };
    ajax.send( null );
}

function handleAjaxResponse( ajax )
{
    if( ajax.readyState == 4 )
    {
		if( ajax.status == 200 )
		{
			var response = ajax.responseText;
			var update = new Array();
			
			if( response.indexOf( '|' ) != -1 )
			{
				update = response.split( '|' );
				function_return = update[0] + '( "' + escape( update[1] ) +  '" )';
				eval( function_return );
			}
		}
		else
		{
			alert( "Error: Requested URL can not be accessed." );
		}
    }
}
