﻿
//Jquery Functions initailizer
$(function() {

    // Initalizing the Superfish menu plugin 
    $('ul.sf-menu').superfish({
        onInit: function() {
            $(this).find('ul').append("<div class='sf-menu-ul-bottom'></div>");
        }
    });


    /*************  Custom Script for the Accordions ******************;*/
     $('ul#accordion div.container').hide();
    
    // Run this function when any of the accordion links is clicked.
    $('ul#accordion li a.activator').click(function() {

        //Gets the next div with classname "container" after the cliked link.
        var ContainerDiv = $(this).next('div');
        
        //This function runs if the div with classname "container" after the clicked link is visible.
        if ((ContainerDiv.is(':visible'))) {
            ContainerDiv.slideUp('fast');
            $(this).parent('li').removeClass('active');
            return false;
        }
        else {
            // Otherwise this function runs when the div with classname "container" after the link is not visible
            $('ul#accordion li').removeClass('active');
            $('ul#accordion li div.container').filter(':visible').slideUp('fast');
            $(this).parent('li').addClass('active');
            ContainerDiv.slideDown('fast');
            return false;
        }
    })
    
    /***  End Of Custom Script for accordion ***/
});

function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function writestateindex(val)
{
	// alert('val'+val);
	document.signup.custstateindex.value = val;
	
	return;
}

function removeAllOptions(selectbox)
{
var i;
 
for(i=selectbox.options.length-1;i>=0;i--)
{
selectbox.remove(i);
}
}

// function addOption_list(selectbox, target, selected_state, change_state, target_drop_element, target_text_element){
function addOption_list(selectbox, target_text_element,this_match_val){
	target = target_text_element;
	
	
	// alert(target_text_element);
//	var state_object = document.getElementById('stateDropBox');
	//state_object.selectedIndex = num;  - get the num value by find it the array key index value.
	// alert('target: ' +target + ' state:' + state_object);
	//alert(document.getElementById('stateDropBox').value);
	// alert(selected_state);
	//alert('selectbox:'+selectbox);
	//alert('target'+target_text_element);
	if(target_text_element == 'undefined') { return;}
	
	if(target == 'CA' || target == 'US')	
	{
		
		 document.getElementById('stateTextBox').style.display = "none";
		 document.getElementById('stateDropBox').style.display = "block";
		
		//eval("document.getElementById('"+target_text_element+"').style.display = 'none'");
		//eval("document.getElementById('"+target_drop_element+"').style.display = 'block'");
		
		removeAllOptions(selectbox);
		addOption(selectbox, 'Please Choose', '')
		var month = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var CA_val_arr = new Array("AB","BC","MB","NB","NF","NT","NS","NU","ON","PE","QC","SK","YT");
		var CA_text_arr = new Array("Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland","Northwest Territories","Nova Scotia","Nunavut","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon and Northern Territories");
		var US_val_arr = new Array("AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","PR","RI","SC","SD","TN","TX","UT","VT","VI","VA","WA","WV","WI","WY","AE","AA","AP");
		var US_text_arr = new Array("Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District of Columbia","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virgin Islands","Virginia","Washington","West Virginia","Wisconsin","Wyoming","Military - Africa, Canada, Europe and Middle East","Military - Americas (except Canada)","Military - Pacific");
		target_length = eval(target+'_val_arr.length');
		match_val = 0;
		for (var i=0; i < target_length ;++i){
			this_val = eval(''+target+'_val_arr[i]');
			eval('addOption(selectbox, '+target+'_text_arr[i], '+target+'_val_arr[i])');
			// if(selected_state == this_val){ match_val = i + 1; }
		}
		// for selection if selected_state has a value and change_state is false.
		// alert(match_val);
		// selectbox.selectedIndex = match_val; //   - get the num value by find it the array key index value.
		selectbox.selectedIndex = this_match_val; //   - get the num value by find it the array key index value.
		

	}
	else 
	{
		 document.getElementById('stateDropBox').style.display = "none";
		 document.getElementById('stateTextBox').style.display = "block";
		
		// was stateDropBox and stateTextBox changed to support multiple state boxes within a single form.
		// 
//	eval("document.getElementById('"+target_drop_element+"').style.display = 'none'");
//	eval("document.getElementById('"+target_text_element+"').style.display = 'block'");
	
	
	}
}

function showdiv(target)
{
	eval('document.getElementById("'+target+'").style.display = "block";');
	
}

function hidediv(target)
{
	eval('document.getElementById("'+target+'").style.display = "none";');
}

function addCompanyUrl(url)
{

}

function test(t)
{
	
	alert(t);
}


function contract_nav(his)
{

	eval("document.location.href = '+his+'");
}

var xmlhttp;

function loadXMLDoc(url)
{
  //alert('loadingXMLDoc:'+ url) good good... next check xml

xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for all new browsers
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5 and IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}


function checkLength(limitField,limit){
	this_value = limitField.value.length;
	eval("document.forms[0].ccount.value='"+this_value+"/"+limit+"'");
    if (limitField.value.length > limit){
         showhide('notes_error','block');
         // alert('test');
    }
    else
    {
        showhide('notes_error','none');
    }
}

function limitText(limitField, limitNum) {
	this_value = limitField.value.length;
	eval("document.forms[0].ccount.value='"+this_value+"/"+limitNum+"'");
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
         showhide('notes_error','block');
    }
    else
    {
        showhide('notes_error','none');
    }
}


function showhide(layer_ref,state){

	if(document.all){ //IS IE 4 or 5 (or 6 beta)
	eval("document.all." +layer_ref+ ".style.display = state");

	}
	if (document.layers) { //IS NETSCAPE 4 or below
	document.layers[layer_ref].display = state;

	}
	if (document.getElementById && !document.all) {

	hza = document.getElementById(layer_ref);
	hza.style.display = state;
	}
	}






/* Cufon custom font replacement scripts */
Cufon.replace('.boxHolder.gray ul li span, .boxHolder.bigGray ul li span', { fontFamily: 'HelveticaNeue LT 47 LightCn' });
Cufon.replace('h3.round', { fontFamily: 'HelveticaNeue LT 47 LightCn' });
Cufon.replace('#accordion a.activator', { fontFamily: 'HelveticaNeue LT 47 LightCn' });


