/***
*  Switches the destination of the search bar if needed
*
***/
function getThisSite()
{
	if ( window.location.hostname.indexOf( 'centerfold.com' )  >= 0 ){
		return 'centerfold';
	}
	else {
		return 'adult';
	}
}

// Returns the corresponding adult.com subdomain given the specific centerfold.com subdomain
function getAdultDomain()
{
	if ( window.location.hostname.indexOf( 'wp.dev.centerfold.com' )  >= 0 ){
		return 'http://wp.dev.adult.com/';
	}
	if ( window.location.hostname.indexOf( 'www.centerfold.com' )  >= 0 ){
		return 'http://www.adult.com/';
	}
	if ( window.location.hostname.indexOf( 'wp-admin.centerfold.com' )  >= 0 ){
		return 'http://wp-admin.adult.com/';
	}
	if ( window.location.hostname.indexOf( 'www.centerfold.com' )  >= 0 ){
		return 'http://www.adult.com/';
	}
	// Shouldn't get here, but just in case
	if ( window.location.hostname.indexOf( 'centerfold.com' )  >= 0 ){
		return 'http://adult.com/';
	}	
}

// Returns the corresponding centerfold.com subdomain given the specific adult.com subdomain
function getCenterfoldDomain()
{
	if ( window.location.hostname.indexOf( 'wp.dev.adult.com' )  >= 0 ){
		return 'http://wp.dev.centerfold.com/';
	}
	if ( window.location.hostname.indexOf( 'www.adult.com' )  >= 0 ){
		return 'http://www.centerfold.com/';
	}
	if ( window.location.hostname.indexOf( 'wp-admin.adult.com' )  >= 0 ){
		return 'http://wp-admin.centerfold.com/';
	}
	if ( window.location.hostname.indexOf( 'www.adult.com' )  >= 0 ){
		return 'http://www.centerfold.com/';
	}
	// Shouldn't get here, but just in case
	if ( window.location.hostname.indexOf( 'adult.com' )  >= 0 ){
		return 'http://centerfold.com/';
	}
}

function get_radio_value(radiogroup)
{
for (var i=0; i < radiogroup.length; i++)
   {
   if (radiogroup[i].checked)
      {
        return radiogroup[i].value;
      }
   }
   return false;
}


function submitMySearch(searchform)
{
	if ( get_radio_value(searchform.siteToSearch) == 'adult')
	{
		if (getThisSite() == 'adult') {
		// No action needed. Continue search on this site submitting to /
		} else {
			searchform.action = getAdultDomain();
		}
		return true;
	}
	
	if ( get_radio_value(searchform.siteToSearch) == 'centerfold')
	{
		if (getThisSite() == 'centerfold') {
		// No action needed. Continue search on this site submitting to /
		} else {
			searchform.action = getCenterfoldDomain();
		}
		return true;
	}
	// shouldn't get here, but just do a regular submit in case we do
	return true;
}