function is_empty(str)
{
	return ( str==null || str==0 || str=="" || str.length<1 );
} // is_empty

function $(id)
{
	return document.getElementById(id);
} // $

function is_numeric(str)
{
	regularExp = new RegExp("^[0-9-.]*$");
	return regularExp.test(str);
} // is_numeric



function is_email(str)
{
	return ( ( str.indexOf("@")>0 ) && ( str.indexOf(".")>0 ) );
} // is_email


function clear_form(frm) {
	frm.reset();
}

function populateSelects(optArray,obj,clear)
{
  var objSelect = document.getElementById(obj);
  var totalObjSelect = objSelect.options.length;
  var subOptionArray = new Array();
  var totalSubOption = 0;
  var resultArray = new Array();

  // firt of all, we have to clear the select option if its necessary
  if (clear == true)
  {
	  for (var i=totalObjSelect-1 ; i>=0 ; i--)
  		objSelect.options[i] = null;
  }

  // then we proced to add the options
  // NOTE: we have to spli the given optArray, because we get something like: 0=>1|1=>2|2=>3...
  subOptionArray = optArray.split('|');
  totalSubOption = subOptionArray.length;

  for( var i=0; i<totalSubOption;i++ )
  {
	var optNew = document.createElement('option');
	resultArray = subOptionArray[i].split('=>');
	optNew.value = resultArray[0];
	optNew.text = resultArray[1];

	// trying to add the option, depending of the internet brower
	try
	{
		objSelect.add(optNew, null); // standard way, doesn't work in IE
	}
	catch(ex)
	{
		objSelect.add(optNew); // for IE only
	}
  } // for
} // populateSelects




function buildSearch(site)
{
	var country = $('countrySelect').options[$('countrySelect').selectedIndex].text;
	var url_country = $('countrySelect').value;
	var state = $('stateSelect').options[$('stateSelect').selectedIndex].text;
	var url_state = $('stateSelect').value;
	var huntingType = $('huntingTypeSelect').options[$('huntingTypeSelect').selectedIndex].text;
	var url_hunting_type = $('huntingTypeSelect').value;
	var huntingService = $('huntingServiceSelect').options[$('huntingServiceSelect').selectedIndex].text;
	var url_hunting_service = $('huntingServiceSelect').value;
	var url = site;

	if ( !is_empty(url_country) && !is_empty(url_state) && !is_empty(url_hunting_type) && !is_empty(url_hunting_service) )
		url += "/"+trim(country).toLowerCase()+"/"+trim(url_state).toLowerCase()+"/"+trim(url_hunting_type).toLowerCase()+"/"+trim(url_hunting_service).toLowerCase()+".html";

	else if ( !is_empty(url_country) && !is_empty(url_state) && !is_empty(url_hunting_type) && is_empty(url_hunting_service) )
		url += "/hunting-guide/"+trim(country).toLowerCase()+"/"+trim(url_state).toLowerCase()+"/"+trim(url_hunting_type).toLowerCase()+".html";

	else if ( !is_empty(url_country) && !is_empty(url_state) && is_empty(url_hunting_type) && !is_empty(url_hunting_service) )
		url += "/hunting-services-guide/"+trim(country).toLowerCase()+"/"+trim(url_state).toLowerCase()+"/"+trim(url_hunting_service).toLowerCase()+".html";

	else if ( is_empty(url_country) && is_empty(url_state) && !is_empty(url_hunting_type) && !is_empty(url_hunting_service) )
		url += "/hunting-destination-guide/"+trim(url_hunting_type).toLowerCase()+"/"+trim(url_hunting_service).toLowerCase()+".html";

	else if ( !is_empty(url_country) && !is_empty(url_state) && is_empty(url_hunting_type) && is_empty(url_hunting_service) )
		url += "/hunting-world/"+trim(country).toLowerCase()+"/"+trim(url_state).toLowerCase()+".html";

	else if ( is_empty(url_country) && is_empty(url_state) && !is_empty(url_hunting_type) && is_empty(url_hunting_service) )
		url += "/hunting/"+trim(url_hunting_type).toLowerCase()+".html";

	else if ( is_empty(url_country) && is_empty(url_state) && is_empty(url_hunting_type) && !is_empty(url_hunting_service) )
		url += "/hunting-services/"+trim(url_hunting_service).toLowerCase()+".html";

	else if ( is_empty(url_country) || is_empty(url_state) || is_empty(url_hunting_type) || is_empty(url_hunting_service) )
	{
		alert("* Please Select State!.\n");
		return false;
	}
	else
		url = site;

	// Now lets build the query...
	window.location = url;

} // buildSearch




function trim(string)
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
		tstring += splitstring[i];
	return tstring;
} // trim



//funtion value Form Contact
function contentVerificationContact()
{

	var finalMessage = "";
	var error = false;

	var quoteName = $('quoteName').value;
	var quoteEmail = $('quoteEmail').value;
	var quoteRe = $('quoteRe').value;
	var quoteDescription = $('quoteDescription').value;
	var quotecode = $('quotecode').value;

	if ( is_empty(quoteName) )
	{
		finalMessage += "* Please check Name.\n";
		error = true;
	}

	if ( is_empty(quoteEmail)  || !is_email(quoteEmail) )
	{
		finalMessage += "* Please check Email.\n";
		error = true;
	}

	 if (is_empty(quoteRe) )
	{
		finalMessage += "* Please check Re.\n";
		error = true;
	}
	if (is_empty(quoteDescription) )
	{
		finalMessage += "* Please check Comments.\n";
		error = true;
	}
	if ( is_empty(quotecode) )
	{
		finalMessage += "* Please check your code.\n";
		error = true;
	}
	if ( error == false )
	{
		return true;
	}
	else
	{
		alert("It seems there''s a problem sending the information, please take a look to the following error(s):\n\n"+finalMessage);
		return false;
	}

}// contentVerificationContact




//funtion value Form Site
function contentVerificationSite()
{

	var finalMessage = "";
	var error = false;

	var quoteName = $('quoteName').value;
	var quoteEmail = $('quoteEmail').value;
	var quotePhone = $('quotePhone').value;
	var quoteCity = $('quoteCity').value;
	var quoteState = $('quoteState').value;
	var quoteLikeHunt = $('quoteLikeHunt').value;
	var quoteComment = $('quoteComment').value;
	var quotecode = $('quotecode').value;

	if ( is_empty(quoteName) )
	{
		finalMessage += "* Please check Name.\n";
		error = true;
	}

	if ( is_empty(quoteEmail)  || !is_email(quoteEmail) )
	{
		finalMessage += "* Please check Email.\n";
		error = true;
	}
	 if (is_empty(quotePhone) )
	{
		finalMessage += "* Please check Phone.\n";
		error = true;
	}
	if (is_empty(quoteCity) )
	{
		finalMessage += "* Please check City.\n";
		error = true;
	}
	if (is_empty(quoteState) )
	{
		finalMessage += "* Please check State.\n";
		error = true;
	}
	if (is_empty(quoteLikeHunt) )
	{
		finalMessage += "* Please check You Like Hunt.\n";
		error = true;
	}
	if (is_empty(quoteComment) )
	{
		finalMessage += "* Please check Comment.\n";
		error = true;
	}
	if ( is_empty(quotecode) )
	{
		finalMessage += "* Please check Code.\n";
		error = true;
	}
	if ( error == false )
	{
		return true;
	}
	else
	{
		alert("It seems there''s a problem sending the information, please take a look to the following error(s):\n\n"+finalMessage);
		return false;
	}

}// contentVerificationSite



// fuction to use target blank in xhtml strict
function transformExternalAnchors()
{
	var i,a,f;
	if ( document.getElementsByTagName )
	{

		a = document.getElementsByTagName("a");
		i = 0;

		// for using in normal href tag, you you have to add: rel="external"
		// example: <a href="http://affiliate.dptsportsgroup.com" rel="external">Affiliate program</a>
		for(i=0;i<a.length;i++)
		{
			if ( a[i].getAttribute('href') && ( a[i].getAttribute("rel")=="external" ) )
			{
				a[i].target = "_blank";
			}
		} // for

		f = document.getElementsByTagName("form");
		i = 0;

		// for using in forms, you have to add in the form tag: title="external"
		// example: 		<form action=# id="frmId" title="external"></form>
		for(i=0;i<f.length;i++)
		{
			if ( f[i].getAttribute('action') && ( f[i].getAttribute("title")=="external" ) )
			{
				f[i].target = "_blank";
			}
		} // for
	} // if
} // transformExternalAnchors



/**
 *
 * @access public
 * @return void
 **/
function display(obj, imageObj)
{
	var currentImage = $(imageObj);

	if($(obj).style.display == 'none')
	{
		$(obj).style.display ='';
		currentImage.src = '/images/top/arrow_up.jpg';
	}
	else
	{
		$(obj).style.display='none';
		currentImage.src = '/images/top/question-mark.jpg';
	} // if


} // display




/**
 *	displayMoreOption
 *
 * @access public
 * @return void
 **/
function displayMoreOption(objShow, objHide, imageObj)
{
	var currentImage = $(imageObj);

	if($(objShow).style.display == 'none')
	{
		$(objShow).style.display ='';
		$(objHide).style.display ='none';
		currentImage.src = '/images/content/up.png';
	}
	else
	{
		$(objShow).style.display='none';
		$(objHide).style.display='';
		currentImage.src = '/images/content/down.png';
	} // if

} // displayMoreOption





window.onload = transformExternalAnchors;