var siteURL = "";
var kDebug = false;


function setSiteURL(url)
{
    siteURL = url;
}

function stripNonAlpha(elName) {
    //remove any non-numeric character from form element
    thisValue	= elName.value
    elName.value = thisValue.replace(/[^_a-zA-Z 0-9]+/g,'');
}

function stripNonDigits(elName) {
    //remove any non-numeric character from form element
    thisValue	= elName.value
    elName.value = thisValue.replace(/[^\d]*/gi, '');
}

function stripNonFloatDigits(elName) {
     //remove any non-numeric character from form element
     thisValue	= elName.value
     elName.value = thisValue.replace(/[^\d|\.]*/gi, '');
}

function cleanParseFloat(floatString) {
	floatString = floatString.replace(/[^\d|\.]*/gi, '');
	return parseFloat(floatString);
}

function multichoice(_object){
    // read status of radio button <m> set in form <n> and return value of selected button
    // _object=document.forms[n].elements[m];
    for ( var kaango_i=0; kaango_i<_object.length; kaango_i++ ) {
        if ( _object[kaango_i].checked==true ) {
            return _object[kaango_i].value;
        }
    }
    return 'null';
}

function setBgColor(ele) {
    color = "#FFFF66";
    ele.style.backgroundColor = color;
}

function chooseImage(msrc, lsrc)
{    
    img = document.getElementById("pImg");
    a = document.getElementById("apImg");

    img.src = msrc;              
    a.href = lsrc;
}


function updateStateProv(country)
{
    us = document.getElementById("us");
    canada = document.getElementById("canada");
    world = document.getElementById("world");

    us.style.display = "none";
    canada.style.display = "none";
    world.style.display = "none";

    if(country == 226)
        us.style.display = "block";
    else if(country == 38)
        canada.style.display = "block";
    else
        world.style.display = "block";
}

function validateRatingsSearch()
{
    if(feRatingsAndSecurity.search.value == "")
	{
		alert('You must enter some text to search!');
		return false;
	}
    else
		return true;
}

function setValueByID(docID,val)
{
	if (document.getElementById(docID) && (document.getElementById(docID).value))
	{
		document.getElementById(docID).value = val;
		return 0;
	}
	if (window.console && kDebug)
	{
		console.warn('setValueByID: '+docID+' not found');
	}
}

function setInnerHTMLByID(docID,val)
{
	if (document.getElementById(docID))
	{
		document.getElementById(docID).innerHTML = val;
		return 0;
	}
	if (window.console && kDebug)
	{
		console.warn('setInnerHTMLByID: '+docID+' not found');
	}
}

function setStyleDisplayByID(docID,val)
{
	if (document.getElementById(docID))
	{
		document.getElementById(docID).style.display = val;
		return 0;
	}
	if (window.console && kDebug)
	{
		console.warn('setStyleDisplayByID: '+docID+' not found');
	}
}

function disableByID(docID,val)
{
	if (document.getElementById(docID))
	{
		document.getElementById(docID).disabled = val;
		return 0;
	}
	if (window.console && kDebug)
	{
		console.warn('setStyleDisplayByID: '+docID+' not found');
	}
}

function isCheckedByID(docID)
{
	if (document.getElementById(docID) && document.getElementById(docID).checked)
	{
		return true;
	}
	if (window.console && kDebug)
	{
		console.warn('isCheckedByID: '+docID+' not found');
	}
	return false;
}

function getValidDataByID(docID)
{
	var notFound = true;
	// if element exists and a value is assigned...
	if (document.getElementById(docID) && (document.getElementById(docID).value))
	{
		notFound = false;
		var myVal = document.getElementById(docID).value;
	}
	// if element exists and no value, grab innerHTML
	else if (document.getElementById(docID) && (document.getElementById(docID).innerHTML))
	{
		notFound = false;
		var myVal = document.getElementById(docID).innerHTML;
	}
	// check for valid number then return
	if (typeof(myVal) == 'string')
	{
		return myVal;
	}
	if (window.console && kDebug && notFound)
	{
		console.warn('getValidDataByID: '+docID+' not found');
	}
	return 0;
}

function getValidNumericDataByID(docID)
{
	var notFound = true;
	// if element exists and a value is assigned...
	if (document.getElementById(docID) && (document.getElementById(docID).value))
	{
		notFound = false;
		var myVal = cleanParseFloat(document.getElementById(docID).value);
	}
	// if element exists and no value, grab innerHTML
	else if (document.getElementById(docID) && (document.getElementById(docID).innerHTML))
	{
		notFound = false;
		var myVal = cleanParseFloat(document.getElementById(docID).innerHTML);
	}
	// check for valid number then return
	if (!isNaN(myVal))
	{
		return myVal;
	}
	if (window.console && kDebug && notFound)
	{
		console.warn('getValidNumericDataByID: '+docID+' not found');
	}
	return 0;
}


/**
 * this function will open an informational popup window.
 */
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/*
 * Added By J.Scott on Dt. 07th Aug, 2006
 * Array.prototype extension

 * - Array#forEach
 * - Array#map
 * - Array#filter
 * - Array#every
 * - Array#some
 * - Array#indexOf
 * - Array#lastIndexOf
 *

for IE, Opera, and older Firefox.(I can't test safari)
you can find reference and sample code here
*/

if(!Array.prototype.forEach){
Array.prototype.forEach = function(callback,thisObject){
	for(var i=0,len=this.length;i<len;i++)
		callback.call(thisObject,this[i],i,this)
}
Array.prototype.map = function(callback,thisObject){
	for(var i=0,res=[],len=this.length;i<len;i++)
		res[i] = callback.call(thisObject,this[i],i,this);
	return res
}
Array.prototype.filter = function(callback,thisObject){
	for(var i=0,res=[],len=this.length;i<len;i++)
		callback.call(thisObject,this[i],i,this) && res.push(this[i]);
	return res
}
Array.prototype.indexOf = function(searchElement,fromIndex){
	var i = (fromIndex < 0) ? this.length+fromIndex : fromIndex || 0;
	for(;i<this.length;i++)
		if(searchElement === this[i]) return i;
	return -1
}
Array.prototype.lastIndexOf = function(searchElement,fromIndex){
	var max = this.length-1;
	var i = (fromIndex < 0)   ? Math.max(max+1 + fromIndex,0) :
			(fromIndex > max) ? max :
			max-(fromIndex||0) || max;
	for(;i>=0;i--)
		if(searchElement === this[i]) return i;
	return -1
}
Array.prototype.every = function(callback,thisObject){
	for(var i=0,len=this.length;i<len;i++)
		if(!callback.call(thisObject,this[i],i,this)) return false;
	return true
}
Array.prototype.some = function(callback,thisObject){
	for(var i=0,len=this.length;i<len;i++)
		if(callback.call(thisObject,this[i],i,this)) return true;
	return false
}
}
/*
  Array Prototype End here
 */
