/*----www.eSoftArena.com----*/
var isIE = false;


var backImg= new Array('Holistic-Dog-Food-Nutro-Ultra-Sammy.jpg','Holistic-Dog-Food-Nutro-Ultra-Rascal.jpg','Holistic-Dog-Food-Nutro-Ultra-Lulu.jpg');
var rand=get_random();

var pre_img_obj = document.createElement('img'); /*just for preLoading*/
pre_img_obj.src = 'images/'+backImg[rand];

function get_random(){
    var ranNum= Math.floor(Math.random()*3);
    return ranNum;
}

$(document).ready(function() {
	
	if(jQuery.support.cssFloat){
		$('html').css('overflow-y', 'scroll');
	}

    if ((typeof(swfobject) != 'undefined') && (swfobject.hasFlashPlayerVersion("8"))) {
	  //console.log('flash');
	  	//$('#fpoCont').css('min-height','653px');
    } else {
	    // no Flash
        //console.log('no flash');
		$('#fpoCont').css('min-height','653px');
		$('#fpoCont').css('height','653px');
	}
	
	if(!window.XMLHttpRequest) {
        isIE = true;
	}
	
});


$(function(){
	$('#menu li').hover(function(){
		$(this).find('ul').show();

		if(isIE) {
			$('select').css('visibility','hidden');
		}
		
	}, function(){
		$(this).find('ul').hide();
	
	});
	$('#menu').hover(function(){
	  //emptyß
	}, function(){
		if(isIE) {
			$('select').css('visibility','visible');	
		}	 
	});
	
	
	$('.navAdultTab li').hover(function(){
		if(!$(this).hasClass('slctTab'))
			$(this).find('a').css('background-position', 'left bottom')
	}, function(){
		if(!$(this).hasClass('slctTab'))
			$(this).find('a').css('background-position', 'left top')
	});
	
	$('.navAdultTab li').click(function(){
		if($('.navAdultTab li').hasClass('slctTab')){
			$('.navAdultTab li').removeClass('slctTab');
			$('.navAdultTab li').find('a').css('background-position', 'left top');
		}
		$(this).addClass('slctTab');
		$(this).find('a').css('background-position', 'left bottom');
		
		var index = $('.navAdultTab li').index(this);
		var mytabs = $('#tabs .tab');
		
		$('#tabs .tab').hide();
		
		$(mytabs[index]).show();
	})
	
});


function loadState(countryValue) {
	with (document.forms[0]) {
		origLength = state.length;
		for (i = 0; i < origLength; i++) {
			state.options[0] = null;
		}
		if ('US' == countryValue) {
			state.options[state.length] = new Option('Select State', '');
			state.options[state.length] = new Option( 'Alabama', 'AL');
			state.options[state.length] = new Option('Alaska','AK');
			state.options[state.length] = new Option('Arkansas','AR');
			state.options[state.length] = new Option('Arizona','AZ');
			state.options[state.length] = new Option('California','CA');
			state.options[state.length] = new Option('Colorado','CO');
			state.options[state.length] = new Option('Connecticut','CT');
			state.options[state.length] = new Option('Delaware','DE');
			state.options[state.length] = new Option('Florida','FL');
			state.options[state.length] = new Option('Georgia','GA');
			state.options[state.length] = new Option('Hawaii','HI');
			state.options[state.length] = new Option('Iowa','IA');
			state.options[state.length] = new Option('Idaho','ID');
			state.options[state.length] = new Option('Illinois','IL');
			state.options[state.length] = new Option('Indiana','IN');
			state.options[state.length] = new Option('Kansas','KS');
			state.options[state.length] = new Option('Kentucky','KY');
			state.options[state.length] = new Option('Louisana','LA');
			state.options[state.length] = new Option('Massachusetts','MA');
			state.options[state.length] = new Option('Maryland','MD');
			state.options[state.length] = new Option('Maine','ME');
			state.options[state.length] = new Option('Michigan','MI');
			state.options[state.length] = new Option('Minnesota','MN');
			state.options[state.length] = new Option('Missouri','MO');
			state.options[state.length] = new Option('Mississippi','MS');
			state.options[state.length] = new Option('Montana','MT');
			state.options[state.length] = new Option('North Carolina','NC');
			state.options[state.length] = new Option('North Dakota','ND');
			state.options[state.length] = new Option('Nebraska','NE');
			state.options[state.length] = new Option('New Hampshire','NH');
			state.options[state.length] = new Option('New Jersey','NJ');
			state.options[state.length] = new Option('New Mexico','NM');
			state.options[state.length] = new Option('Nevada','NV');
			state.options[state.length] = new Option('New York','NY');
			state.options[state.length] = new Option('Ohio','OH');
			state.options[state.length] = new Option('Oklahoma','OK');
			state.options[state.length] = new Option('Oregon','OR');
			state.options[state.length] = new Option('Pennsylvania','PA');
			state.options[state.length] = new Option('Rhode Island','RI');
			state.options[state.length] = new Option('South Carolina','SC');
			state.options[state.length] = new Option('South Dakota', 'SD');
			state.options[state.length] = new Option('Tennessee','TN');
			state.options[state.length] = new Option('Texas','TX');
			state.options[state.length] = new Option('Utah', 'UT');
			state.options[state.length] = new Option('Virginia', 'VA');
			state.options[state.length] = new Option('Vermont', 'VT');
			state.options[state.length] = new Option('Washington', 'WA');
			state.options[state.length] = new Option('Wisconsin','WI');
			state.options[state.length] = new Option('West Virginia','WV');
			state.options[state.length] = new Option('Wyoming','WY');

		} else if ('CA' == countryValue) {
			state.options[state.length] = new Option('Select Province', '');
			state.options[state.length] = new Option('Alberta','AB');
			state.options[state.length] = new Option('British Columbia','BC');
			state.options[state.length] = new Option('Manitoba','MB');
			state.options[state.length] = new Option('New Brunswick','NB');
			state.options[state.length] = new Option('Newfoundland and Labrador','NL');
			state.options[state.length] = new Option('Northwest Territories','NT');
			state.options[state.length] = new Option('Nova Scotia','NS');
			state.options[state.length] = new Option('Nunavut','NU');
			state.options[state.length] = new Option('Ontario','ON');
			state.options[state.length] = new Option('Prince Edward Island','PE');
			state.options[state.length] = new Option('Quebec','QC');
			state.options[state.length] = new Option('Saskatchewan','SK');
			state.options[state.length] = new Option('Yukon','YT');
	
		} else {
			state.options[state.length] = new Option('Select','');
		}
	}
}

function checkData(){
	var msg = "";
	if(document.contact.COUNTRY.options[document.contact.COUNTRY.selectedIndex].value == ""){
		msg = msg + "\n" + "Country";
	}
	/*
	if(document.contact.TITLE.options[document.contact.TITLE.selectedIndex].value == ""){
		msg = msg + "\n" + "Title";
	}
	*/
	if (document.contact.FNAME.value == "") {
		msg =  msg + "\n" + "First Name";
	}
	if (document.contact.LNAME.value == "") {
		msg = msg + "\n" + "Last Name";
	}
	if (document.contact.ADDRESS.value == "") {
		msg = msg + "\n" + "Address";
	}
	if (document.contact.CITY.value == "") {
		msg = msg + "\n" + "City";
	}
	if (document.contact.state.options[document.contact.state.selectedIndex].value == "") {
		msg = msg + "\n" + "State/Province";
	}
	if (document.contact.ZIP.value == "") {
		msg = msg + "\n" + "Zip/Postal code";
	} else {
		var code = document.contact.ZIP.value;
		if(document.contact.COUNTRY.value == "US"){
			var exp=/^[0-9]{5}-[0-9]{4}$|^[0-9]{5}$/;
			var re = new RegExp(exp);
			var matched = re.test(code);
			if(matched){
			}else{
				msg = msg + "Please enter valid zip code";
			}
		}else{
		
		var exp=/^[A-Z][0-9][A-Z][ ]?[0-9][A-Z][0-9]$/;
			var re = new RegExp(exp);
			var matched = re.test(code.toUpperCase());
			if(matched){
			}else{
				msg =  msg + "Please enter valid postal code";
			}
	
		}
	}

/*	if (document.contact.AREACODE.value == "" || document.contact.PREFIX.value == "" || document.contact.SUFFIX.value == "" ) {
		msg = msg + "\n" + "Phone Number";
	}

	if (document.contact.AREACODE.value != "" || document.contact.PREFIX.value != "" || document.contact.SUFFIX.value != "" ) {
		if (isNaN(document.contact.AREACODE.value) || isNaN(document.contact.PREFIX.value) || isNaN(document.contact.SUFFIX.value)){
			msg = msg + "\n" + "Valid phone Number";
		}
	}*/

	if (document.contact.EMAIL.value == "") {
		msg = msg + "\n" + "E-mail Address";
	}
	if(document.contact.EMAIL.value != "") {
		invalidChars = " /:,;";
		for (i=0;i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i);
			if (document.contact.EMAIL.value.indexOf(badChar,0) > -1) {
				msg = msg + "\n" + 'Valid e-mail address';
			}
		}
			atPos = document.contact.EMAIL.value.indexOf("@",1);
		if (atPos == -1) {
			msg = msg + "\n" + 'Valid e-mail address';
		}
		else if (document.contact.EMAIL.value.indexOf("@", atPos+1) > -1) {
			msg = msg + "\n" + 'Valid e-mail address';
		}
		else if (document.contact.EMAIL.value.indexOf(".", atPos) == -1) {
			msg = msg + "\n" + 'Valid e-mail address';
		}
		else if (document.contact.EMAIL.value.indexOf(".", atPos) +3 > document.contact.EMAIL.value.length) {
			msg = msg + "\n" + 'Valid e-mail address';
		}
	}

	if(document.contact.TOPIC.value == "") {
		msg = msg + "\n" + 'Topic';
	}
	
	
	if(msg != ""){
		alert("Please fill in the following information:" + "\n" + msg);
		return false;
	}else{
			return true;
			/*document.contact.submit();
			window.location.href='thank-you-nutro-ultra-dog-food.html';*/
	}
} //end checkData function


function checkRegData(){
	var msg = "";

	if (document.specialOfferRegistration.FNAME.value == "") {
		msg =  msg + "\n" + "First Name";
	}
	if (document.specialOfferRegistration.LNAME.value == "") {
		msg = msg + "\n" + "Last Name";
	}
	/*
	if (document.specialOfferRegistration.CITY.value == "") {
		msg = msg + "\n" + "City";
	}
	*/
	if (document.specialOfferRegistration.state.options[document.specialOfferRegistration.state.selectedIndex].value == "") {
		msg = msg + "\n" + "State/Province";
	}
	/*
	if (document.specialOfferRegistration.ZIP.value == "") {
		msg = msg + "\n" + "Zip/Postal code";
	} else {
		var code = document.specialOfferRegistration.ZIP.value;
		if(document.specialOfferRegistration.COUNTRY.value == "US"){
			var exp=/^[0-9]{5}-[0-9]{4}$|^[0-9]{5}$/;
			var re = new RegExp(exp);
			var matched = re.test(code);
			if(matched){
			}else{
				msg = msg + "Please enter valid zip code";
			}
		}else{
		
		var exp=/^[A-Z][0-9][A-Z][ ]?[0-9][A-Z][0-9]$/;
			var re = new RegExp(exp);
			var matched = re.test(code.toUpperCase());
			if(matched){
			}else{
				msg =  msg + "Please enter valid postal code";
			}
	
		}
	}
    */
	
	if (document.specialOfferRegistration.EMAIL.value == "") {
		msg = msg + "\n" + "E-mail Address";
	}
	if(document.specialOfferRegistration.EMAIL.value != "") {
		invalidChars = " /:,;";
		for (i=0;i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i);
			if (document.specialOfferRegistration.EMAIL.value.indexOf(badChar,0) > -1) {
				msg = msg + "\n" + 'Valid e-mail address';
			}
		}
			atPos = document.specialOfferRegistration.EMAIL.value.indexOf("@",1);
		if (atPos == -1) {
			msg = msg + "\n" + 'Valid e-mail address';
		}
		else if (document.specialOfferRegistration.EMAIL.value.indexOf("@", atPos+1) > -1) {
			msg = msg + "\n" + 'Valid e-mail address';
		}
		else if (document.specialOfferRegistration.EMAIL.value.indexOf(".", atPos) == -1) {
			msg = msg + "\n" + 'Valid e-mail address';
		}
		else if (document.specialOfferRegistration.EMAIL.value.indexOf(".", atPos) +3 > document.specialOfferRegistration.EMAIL.value.length) {
			msg = msg + "\n" + 'Valid e-mail address';
		}
	}

	if (document.specialOfferRegistration.EMAILCONFIRM.value == "") {
		msg = msg + "\n" + "Confirm E-mail Address";
	}
	if(document.specialOfferRegistration.EMAILCONFIRM.value != "") {
		invalidChars = " /:,;";
		for (i=0;i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i);
			if (document.specialOfferRegistration.EMAILCONFIRM.value.indexOf(badChar,0) > -1) {
				msg = msg + "\n" + 'Valid confirm e-mail address';
			}
		}
			atPos = document.specialOfferRegistration.EMAILCONFIRM.value.indexOf("@",1);
		if (atPos == -1) {
			msg = msg + "\n" + 'Valid confirm e-mail address';
		}
		else if (document.specialOfferRegistration.EMAILCONFIRM.value.indexOf("@", atPos+1) > -1) {
			msg = msg + "\n" + 'Valid confirm e-mail address';
		}
		else if (document.specialOfferRegistration.EMAILCONFIRM.value.indexOf(".", atPos) == -1) {
			msg = msg + "\n" + 'Valid confirm e-mail address';
		}
		else if (document.specialOfferRegistration.EMAILCONFIRM.value.indexOf(".", atPos) +3 > document.specialOfferRegistration.EMAILCONFIRM.value.length) {
			msg = msg + "\n" + 'Valid confirm e-mail address';
		}
	}
	
	if (document.specialOfferRegistration.EMAIL.value !== document.specialOfferRegistration.EMAILCONFIRM.value) {
		msg = msg + "\n" + "Matching E-mail Addresses";
	}

	
	if(msg != ""){
		alert("Please fill in the following information:" + "\n" + msg);
		return false;
	}else{
			return true;
			/*document.contact.submit();
			window.location.href='special-offers-coupon-ultra-dog-food.html';*/
	}
	alert('end');
} //end checkRegData function


function checkNumber(tmpvalue, msg){
	if (isNaN(tmpvalue)){
		alert("Please enter a number for " + msg);
		return false;
	}
	return true;
}

function initDropdowns() {
	with(document.forms[0]) {
		TOPIC.options[0].selected = true;
		COUNTRY.options[0].selected = true;
		TITLE.options[0].selected = true;
	}
}

function ismaxlength(obj) {
		var objValue = obj.value;
		var charCounter = 0;

		for (var i = 0; i < objValue.length; i++) {	
			// don't remove box character (if present), it is used for TM character
			if(objValue.charAt(i) == 'T' || objValue.charAt(i) == '&reg;') {
				++charCounter;
			}
		}

		var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
		mlength = mlength - charCounter;
	
		if (obj.getAttribute && obj.value.length>mlength) {
			obj.value=obj.value.substring(0,mlength);
		} 
	}
