addLoadListener(paging);
addLoadListener(userLogin);
addLoadListener(hoverDelete);
addLoadListener(showSubnav);
addLoadListener(hoverCheckout);
addLoadListener(openSizeChart);
addLoadListener(addCartHover);
addLoadListener(goSizeHover);;
addLoadListener(openSideSizeChart);
//addLoadListener(countryDropdown);
addLoadListener(showStatesList);
addLoadListener(showCityList);
addLoadListener(setHeight);
addLoadListener(pressHover);
addLoadListener(hoverArrow);
addLoadListener(viewHover);
addLoadListener(seeAllHover);
//addLoadListener(productHovers);


/* ---------------------------- */
/* Begin org scripts.js */
/* ---------------------------- */

/*
	This uses the NEW form field names that work with the NEW shopping cart code.
*/
function enableOnCheckCopyShippingNew(formName) {
	var copy = eval('document.' + formName + '.copy_address');

	var billing_address_1 = eval('document.' + formName + '.BILLING_ADDRESS_1');
	var billing_address_2 =eval('document.' + formName + '.BILLING_ADDRESS_2');
	var billing_city = eval('document.' + formName + '.BILLING_CITY');
	var billing_country_id = eval('document.' + formName + '.BILLING_COUNTRY_ID');
	var billing_zip_code = eval('document.' + formName + '.BILLING_ZIP_CODE');
	var billing_state_id = eval('document.' + formName + '.BILLING_STATE_ID');
	var billing_company_name = eval('document.' + formName + '.BILLING_COMPANY_NAME');

	var shipping_address_1 = eval('document.' + formName + '.shipping_address_1');
	var shipping_address_2 = eval('document.' + formName + '.shipping_address_2');
	var shipping_city = eval('document.' + formName + '.shipping_city');
	var shipping_country_id = eval('document.' + formName + '.shipping_country_id');
	var shipping_zip_code = eval('document.' + formName + '.shipping_zip_code');
	var shipping_state_id = eval('document.' + formName + '.shipping_state_id');
	var shipping_company_name = eval('document.' + formName + '.shipping_company_name');

	var shipping_first_name = eval('document.' + formName + '.shipping_first_name');
	var shipping_last_name = eval('document.' + formName + '.shipping_last_name');

	var name_on_card = eval('document.' + formName + '.BILLING_NAME');

	if (copy.checked) {
		billing_address_1.value = shipping_address_1.value;
		if (billing_address_2) {
			billing_address_2.value = shipping_address_2.value;
		}
		billing_city.value = shipping_city.value;

		billing_zip_code.value = shipping_zip_code.value;
		billing_state_id.value = shipping_state_id.value;

		if (billing_country_id) {
			billing_country_id.value = shipping_country_id.value;
		}

		if (shipping_first_name && shipping_last_name){
			name_on_card.value = shipping_first_name.value + ' ' + shipping_last_name.value;
		} else {
			var noc = "";
			if (shipping_first_name.value != "")
				noc = noc + shipping_first_name.value + " ";
			if (shipping_middle_name.value != "")
				noc = noc + shipping_middle_name.value + " ";
			if (shipping_last_name.value != "")
				noc = noc + shipping_last_name.value + " ";
			name_on_card.value= noc;
		}

		if (billing_company_name && shipping_company_name) {
			billing_company_name.value = shipping_company_name.value;
		}
	} else {
		billing_address_1.value = "";
		if (billing_address_2) {
			billing_address_2.value = "";
		}
		billing_city.value = "";

		billing_zip_code.value = "";
		billing_state_id.value = 0;

		if (billing_country_id) {
			billing_country_id.value = 0;
		}

		if (billing_company_name)	{
			billing_company_name.value="";
		}
		name_on_card.value = "";
	}
}


/*
	This uses the NEW form field names that work with the NEW shopping cart code.
*/
function enableOnCheckCopyShippingFormField(formName) {
	var copy = eval('document.' + formName + '.copy_address');

	var billing_address_1 = eval('document.' + formName + '.BILLING_ADDRESS_1');
	var billing_address_2 =eval('document.' + formName + '.BILLING_ADDRESS_2');
	var billing_city = eval('document.' + formName + '.BILLING_CITY');
	var billing_country_id = eval('document.' + formName + '.BILLING_COUNTRY_ID');
	var billing_zip_code = eval('document.' + formName + '.BILLING_ZIP_CODE');
	var billing_state_id = eval('document.' + formName + '.BILLING_STATE_ID');
	var billing_company_name = eval('document.' + formName + '.BILLING_COMPANY_NAME');

	var shipping_address_1 = eval('document.' + formName + '.SHIPPING_ADDRESS_1');
	var shipping_address_2 = eval('document.' + formName + '.SHIPPING_ADDRESS_2');
	var shipping_city = eval('document.' + formName + '.SHIPPING_CITY');
	var shipping_country_id = eval('document.' + formName + '.SHIPPING_COUNTRY_ID');
	var shipping_zip_code = eval('document.' + formName + '.SHIPPING_ZIP_CODE');
	var shipping_state_id = eval('document.' + formName + '.SHIPPING_STATE_ID');
	var shipping_company_name = eval('document.' + formName + '.SHIPPING_COMPANY_NAME');

	var shipping_first_name = eval('document.' + formName + '.SHIPPING_FIRST_NAME');
	var shipping_last_name = eval('document.' + formName + '.SHIPPING_LAST_NAME');

	var name_on_card = eval('document.' + formName + '.BILLING_NAME');

	var billing_first_name = eval('document.' + formName + '.BILLING_FIRST_NAME');
	var billing_last_name = eval('document.' + formName + '.BILLING_LAST_NAME');

	var shipping_phone_number_1 = eval('document.' + formName + '.SHIPPING_PHONE_NUMBER_PART_1');
	var shipping_phone_number_2 = eval('document.' + formName + '.SHIPPING_PHONE_NUMBER_PART_2');
	var shipping_phone_number_3 = eval('document.' + formName + '.SHIPPING_PHONE_NUMBER_PART_3');

	var billing_phone_number_1 = eval('document.' + formName + '.BILLING_PHONE_NUMBER_PART_1');
	var billing_phone_number_2 = eval('document.' + formName + '.BILLING_PHONE_NUMBER_PART_2');
	var billing_phone_number_3 = eval('document.' + formName + '.BILLING_PHONE_NUMBER_PART_3');

	if (copy.checked) {
		billing_address_1.value = shipping_address_1.value;
		if (billing_address_2) {
			billing_address_2.value = shipping_address_2.value;
		}
		billing_city.value = shipping_city.value;

		billing_zip_code.value = shipping_zip_code.value;
		billing_state_id.value = shipping_state_id.value;

		if (billing_country_id) {
			billing_country_id.value = shipping_country_id.value;
		}

		if (shipping_first_name && shipping_last_name){

			if(name_on_card) {
				name_on_card.value = shipping_first_name.value + ' ' + shipping_last_name.value;
			} else if(billing_first_name && billing_last_name) {
				billing_first_name.value = shipping_first_name.value;
				billing_last_name.value = shipping_last_name.value;
			}
		} else {
			var noc = "";
			if (shipping_first_name.value != "")
				noc = noc + shipping_first_name.value + " ";
			if (shipping_middle_name.value != "")
				noc = noc + shipping_middle_name.value + " ";
			if (shipping_last_name.value != "")
				noc = noc + shipping_last_name.value + " ";
			name_on_card.value= noc;
		}

		if (billing_company_name && shipping_company_name) {
			billing_company_name.value = shipping_company_name.value;
		}

		if (billing_phone_number_1 && shipping_phone_number_1) {
			billing_phone_number_1.value = shipping_phone_number_1.value;
		}
		if (billing_phone_number_2 && shipping_phone_number_2) {
			billing_phone_number_2.value = shipping_phone_number_2.value;
		}
		if (billing_phone_number_3 && shipping_phone_number_3) {
			billing_phone_number_3.value = shipping_phone_number_3.value;
		}
	} else {
		billing_address_1.value = "";
		if (billing_address_2) {
			billing_address_2.value = "";
		}
		billing_city.value = "";

		billing_zip_code.value = "";
		billing_state_id.value = 0;

		if (billing_country_id) {
			billing_country_id.value = 0;
		}

		if (billing_company_name)	{
			billing_company_name.value="";
		}

		if(name_on_card) {
			name_on_card.value = "";
		}

		if(billing_first_name) {
			billing_first_name.value="";
		}
		if(billing_last_name) {
			billing_last_name.value="";
		}

		if (billing_phone_number_1) {
			billing_phone_number_1.value = "";
		}
		if (billing_phone_number_2) {
			billing_phone_number_2.value = "";
		}
		if (billing_phone_number_3) {
			billing_phone_number_3.value = "";
		}
	}
}

/* Clears all values from a form except for few types (hidden, submit, button, etc). */
function resetForm(formName) {
	var form = eval('document.' + formName);
	var no_elements = form.elements.length;

	/* Select boxes start with "select"; seems select boxes are named "select-one", etc. */
	var select_pattern = /select.*/;

	for (var i = 0; i < no_elements; i++) {
		var element = form.elements[i];
		if (element.type != 'hidden' && element.type != 'submit' && element.type != 'button') {
			if (element.type == 'checkbox') {
				element.checked = false;
			} else if (element.type == 'radio') {
				var group = form[element.name];

				if (group) {
					var group_count = group.length;
					for (var e = 0; e < group_count; e++) {
						group[e].checked = false;
					}
				}
			} else if (element.type.match(select_pattern)) {
				element.value = 0;
			} else {
				element.value = '';
			}
		}
	}
}

/* Clears a form's field. */
function clearText(formName, fieldName) {
	var field = eval('document.' + formName + '.' + fieldName);
	if (field) {
		field.value = '';
	}
}

/* Gives focus to the search text box - used in body.onload for constructioncomplete */
function setFocusOnSearchBox() {
	var textbox = eval('document.dosearch.searchterm');

	if (textbox) {
		textbox.focus();
	}
}

/* Copies shipping address to billing address on check. */
function enableOnCheckCopyShipping(formName) {
	var copy = eval('document.' + formName + '.copy_address');

	var billing_address = eval('document.' + formName + '.billing_address');
	var billing_address2 =eval('document.' + formName + '.billing_address2');
	var billing_city = eval('document.' + formName + '.billing_city');
	var billing_country = eval('document.' + formName + '.billing_country');
	var billing_country_id = eval('document.' + formName + '.billing_country_id');
	var billing_zip_code = eval('document.' + formName + '.billing_zip_code');
	var billing_state_id = eval('document.' + formName + '.billing_state_id');
	var billing_company_name = eval('document.' + formName + '.billing_company_name');

	var shipping_address = eval('document.' + formName + '.shipping_address');
	var shipping_address2 = eval('document.' + formName + '.shipping_address2');
	var shipping_city = eval('document.' + formName + '.shipping_city');
	var shipping_country = eval('document.' + formName + '.shipping_country');
	var shipping_country_id = eval('document.' + formName + '.shipping_country_id');
	var shipping_zip_code = eval('document.' + formName + '.shipping_zip_code');
	var shipping_state_id = eval('document.' + formName + '.shipping_state_id');
	var shipping_company_name = eval('document.' + formName + '.shipping_company_name');

	var first_name = eval('document.' + formName + '.first_name');
	var last_name = eval('document.' + formName + '.last_name');

	var shipping_first_name = eval('document.' + formName + '.shipping_first_name');
	var shipping_middle_name = eval('document.' + formName + '.shipping_middle_name');
	var shipping_last_name = eval('document.' + formName + '.shipping_last_name');

	var name_on_card = eval('document.' + formName + '.name_on_card');
	if (copy.checked) {

		billing_address.value = shipping_address.value;
		if(billing_address2)
		{
			billing_address2.value = shipping_address2.value;
		}
		billing_city.value = shipping_city.value;

		if (billing_country) {
			billing_country.value = shipping_country.value;
		}

		billing_zip_code.value = shipping_zip_code.value;
		billing_state_id.value = shipping_state_id.value;

		if (billing_country_id) {
			billing_country_id.value = shipping_country_id.value;
		}

		if(first_name && last_name)
		{
			name_on_card.value = first_name.value + ' ' + last_name.value;
		}else if(shipping_first_name && shipping_last_name){
			name_on_card.value = shipping_first_name.value + ' ' + shipping_last_name.value;
		}else
		{
			var noc = "";
			if(shipping_first_name.value != "")
				noc = noc + shipping_first_name.value + " ";
			if(shipping_middle_name.value != "")
				noc = noc + shipping_middle_name.value + " ";
			if(shipping_last_name.value != "")
				noc = noc + shipping_last_name.value + " ";
			name_on_card.value= noc;
		}

		if(billing_company_name && shipping_company_name)
		{
			billing_company_name.value = shipping_company_name.value;
		}
	} else {
		billing_address.value = "";
		if(billing_address2)
		{
			billing_address2.value = "";
		}
		billing_city.value = "";

		if (billing_country) {
			billing_country.value = "";
		}

		billing_zip_code.value = "";
		billing_state_id.value = 0;

		if (billing_country_id) {
			billing_country_id.value = 0;
		}

		if(billing_company_name)
		{
			billing_company_name.value="";
		}
		name_on_card.value = "";
	}
}


function checkforcounty(formName, body_id) {
	var id = eval('document.' + formName + '.shipping_state_id.value');
	var county = eval('document.' + formName + '.shipping_county_id');
	var county_element = document.getElementById(body_id);
	if(id  == '37'){
		if (county_element) {
			county_element.className = "tbody_show";
		}
	}else{
		if (county_element) {
			county_element.className = "tbody_hide";
		}
		if (county) {
			county.value = "0";
		}
	}
}

/*
	this allows you to have a second submit button for a form that does something totally different by changing the
	form values onClick
*/
function changeForm(formName, new_action, new_action_call, new_success, new_failure) {
	var form = eval('document.' + formName);

	if (form) {
		form.action = new_action;
		form.action_call.value = new_action_call;
		form.success.value = new_success;
		form.failure.value = new_failure;
	}
}



function bookmark(url, description)
{
	msg ="Please hit CTRL+D to add a bookmark to this site."
	if (navigator.appName=='Microsoft Internet Explorer')
	{
		window.external.AddFavorite(url, description);
	}
	else if (navigator.appName=='Netscape')
	{
		alert(msg);
	}
}

function getQueryStringValue(field)
{
	var query = location.search.substring(1);
	var pairs = query.split(",");
	for(var i=0; i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');
		if(pos == -1) continue;
		var argname = pairs[i].substring(0, pos)
		var value = pairs[i].substring(pos+1);
		if(argname == field)
			return value;
	}
	return "";
}

function popUpWindow(url, title, a_width, a_height) {
	var newwindow='';
	newwindow = window.open(url, title, "width=" + a_width + ",height=" + a_height + ",status=0, toolbar=0,location=0,status=0,resizable=1");
	newwindow.focus();
}

function popUpWindowWithScrollbar(url, title, a_width, a_height) {
	var newwindow='';
	newwindow = window.open(url, title, "width=" + a_width + ",height=" + a_height + ",status=0, scrollbars=1,toolbar=0,location=0,status=0,resizable=1");
	newwindow.focus();
}

// "handler_func" is the name of the function.
function asyncGet(url, handler_func, arg) {
	var req;

	try {
		req = new XMLHttpRequest();
	} catch (e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { }
		}
	}

	if (req) {
		var currentTime = new Date();
		req.open("GET", url + "?time=" + currentTime.getTime(), true);
		req.onreadystatechange = function() {
			try {
				if (req.readyState == 4 && req.status == 200) {
					var response = req.responseText;
					eval(handler_func + '(response, arg)');
				}
			} catch (e) {}
		}

		req.send(null);
	}
}

// similiar to asyncGet, but allows extra url parameteres to be appended on calling URL
function asyncGet(url, handler_func, arg, url_params) {
	var req;

	try {
		req = new XMLHttpRequest();
	} catch (e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { }
		}
	}

	if (req) {
		var currentTime = new Date();
		req.open("GET", url + "?time=" + currentTime.getTime() + "&" + url_params, true);
		req.onreadystatechange = function() {
			try {
				if (req.readyState == 4) {
					if(req.status == 200){
						var response = req.responseText;
						eval(handler_func + '(response, arg)');
					}else{
						if(arg && arg.staticURL && arg.stopCall != 'true'){
							arg.stopCall = 'true';//prevent infinited recursive
							asyncGet(arg.staticURL, handler_func, arg, url_params);
						}
					}
				}
			} catch (e) {}
		}

		req.send(null);
	}
}

/*
 * a timeout version of asyncGet, specified with $timeout in milliseconds, when it couldn't
 * get the dynamic content from the first ajax call, it will try to load the arg.staticURL if possible
 */
var req_arr = new Array();//xmlhttprequest objects
var abort_arr = new Array();//when request object to abort
var arg_arr = new Array();//arg sent for every request
var handler_func_arr = new Array();//handler for every request
function asyncGetWithTimeout(url, handler_func, arg, url_params, timeout) {
        var req;

        try {
                req = new XMLHttpRequest();
        } catch (e) {
                try {
                        req = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try {
                                req = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) { }
                }
        }

        if (req) {

                var req_index = req_arr.length;
                req_arr[req_index] = req;
                arg_arr[req_index] = arg;
                handler_func_arr[req_index] = handler_func;
                var currentTime = new Date();
                req.open("GET", url + "?time=" + currentTime.getTime() + "&" + url_params, true);
                req.onreadystatechange = function() {
                        if (req.readyState == 4) {
                                if(!abort_arr[req_index]){
                                clearTimeout(xhrTimeout);
                                if(req.status == 200){
                                        var response = req.responseText;
                                        eval(handler_func + '(response, arg)');
                                }else{
                                        if(arg && arg.staticURL && !arg.stopCall){
                                        //abnormal response 500 ex... check if there's an static url to get
                                                arg.stopCall = 'true';//prevent infinited recursive
                                                asyncGet(arg.staticURL, handler_func, arg, url_params);
                                        }
                                }
                                }
                        }
                }

                req.send(null);
                var xhrTimeout=setTimeout("ajaxTimeout("+req_index+");",timeout);
        }
}

function ajaxTimeout(req_index){
   abort_arr[req_index] = true;
   req_arr[req_index].abort();
   //alert(arg_arr[req_index].staticURL);
        if(arg_arr[req_index] && arg_arr[req_index].staticURL){
           asyncGet(arg_arr[req_index].staticURL, handler_func_arr[req_index], arg_arr[req_index], '');
        }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/* depending on the current class of the button element, it will show/hide another element by changing its class */
function hideShowTbody(elementId, checkboxEl) {
	if (checkboxEl) {
		if (checkboxEl.checked) {
			document.getElementById(elementId).className = "tbody_show";
		} else {
			document.getElementById(elementId).className = "tbody_hide";
		}
	}
}

/* useful if you want to know the value of the checked radio button */
function getCheckedRadioValue(radioObj) {
	if (!radioObj) {
		return "";
	}

	var radioLength = radioObj.length;

	if (radioLength == undefined) {
		if (radioObj.checked) {
			return radioObj.value;
		} else {
			return "";
		}
	}

	for (var i = 0; i < radioLength; i++) {
		if (radioObj[i].checked) {
			return radioObj[i].value;
		}
	}

	return "";
}


	function asyncPost(url, f, handler_func, arg) {
		var req;

		try {
			req = new XMLHttpRequest();
		} catch (e) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) { }
			}
		}

		if (req) {
			var currentTime = new Date();
			var formValues = getFormValues(f) + "&time="+currentTime.getTime();
			req.open("POST", url, true);

			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					//var response = req.responseText.replace(/^\s+|\s+$/g, '');
					var response = req.responseText;
					eval(handler_func + '(response, arg)');
				}
			}

			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			req.setRequestHeader("Content-length", formValues.length);
			req.setRequestHeader("Connection", "close");
			req.send(formValues);
		}
	}


	function getFormValues(fobj)
	{
	   var str = "";
	   for(var i = 0; i < fobj.elements.length;i++)
	   {

		   switch(fobj.elements[i].type)
	       {


	           case "text":
	                str += fobj.elements[i].name +
	                 "=" + escape(fobj.elements[i].value) + "&";
	                 break;
	           case "hidden":
	                str += fobj.elements[i].name +
	                 "=" + escape(fobj.elements[i].value) + "&";
	                 break;
	           case "button":
	                str += fobj.elements[i].name +
	                 "=" + escape(fobj.elements[i].value) + "&";
	                 break;
	           case "select-one":
	                str += fobj.elements[i].name +
	                "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
	                break;
	           case "radio":
	           		if(fobj.elements[i].checked) {
		           		str += fobj.elements[i].name +
	    	             "=" + escape(fobj.elements[i].value) + "&";
	    	        }
	        	    break;
	           case "textarea":
	           		str += fobj.elements[i].name +
	                 "=" + escape(fobj.elements[i].value) + "&";
	                 break;
	           case "password":
		             str += fobj.elements[i].name +
	                 "=" + escape(fobj.elements[i].value) + "&";
	                 break;
	            case "checkbox":
	            	if(fobj.elements[i].checked) {
		            	str += fobj.elements[i].name +
	    	             "=" + escape(fobj.elements[i].value) + "&";
	            	}
	            	break;
	       }
	   }
	   str = str.substr(0,(str.length - 1));
	   return str;
	}

	function addHiddenField(elementID, fieldName, fieldValue) {

		var element = document.getElementById(elementID);
		element.innerHTML = "<input type=\"hidden\" name=\"" + fieldName + "\" value=\"" + fieldValue + "\" />";

	}

	/* Place a product, based on product_id,  into session as a recently viewed item */
	function recentlyViewedProduct(context, product_id)
	{
		var url = context + "/servlet/RecentlyViewedServlet";
		var queryString = "ref=PRODUCT&max_number_products=2&product_id=" + product_id;
		asyncGet(url, "", "", queryString);
	}

	/* Get products from session as a recently viewed item */
	function getRecentlyViewedProduct(context, element_id)
	{
		var queryString = context + "/templates/most_recently_viewed_handler.jsp?timeStamp=" + new Date().getTime();
		xmlreqGET(queryString, element_id, 'fill');
	}


	/*
		arg is a json element ({'elementId': 'co'})
		By default, it will look into the JSON value for variable "elementId" and set response as element innerHTML
	*/
	function copyToElementInnerHtml(response, arg) {

		document.getElementById(arg.elementId).innerHTML= response;

	}

	function showElement(d) {

		var b = document.getElementById(d);
		b.style.display = "block";

	}

	function hideElement(d) {

		if(d.length < 1) { return; }
		   document.getElementById(d).style.display = "none";
	}

	function swap_image(element_name, new_image_src) {
		if (document.images) {
			var imageElement = eval('document.images.' + element_name);
			if(imageElement)
				imageElement.src = new_image_src;
		}

	}

	function change_mouseover_image(mouseover_element_name, mouseover_element_name_that_change, mouseover_image, additionalAttributes) {

		if (document.images) {
			var mouseoverElement = eval('document.images.' + mouseover_element_name);
			if(mouseoverElement)
				mouseoverElement.onmouseover =function() {swap_image(mouseover_element_name_that_change, mouseover_image); eval(additionalAttributes)};
		}
	}

	/* Similiar to change_mouseover_image, but accounts of IE6 browsers */
	function change_mouseover_image_ie6(mouseover_element_name, mouseover_element_name_that_change, mouseover_image, additionalAttributes, mouseover_element_name_that_change_id) {

		if (document.images) {
			var mouseoverElement = eval('document.images.' + mouseover_element_name);
			if(mouseoverElement){
				var arVersion = navigator.appVersion.split("MSIE")
				var version = parseFloat(arVersion[1])

				if ((version >= 5.5) && (document.body.filters)){
					mouseoverElement.onmouseover =function() {document.getElementById(mouseover_element_name_that_change_id).src = mouseover_image; pngfixerproduct(document.getElementById('main_view'), '', '234', '282', ''); eval(additionalAttributes); };
				}else{
					mouseoverElement.onmouseover =function() {swap_image(mouseover_element_name_that_change, mouseover_image); eval(additionalAttributes)};
				}

			}
		}
	}

	function swap_image_with_mouseover(thumbname_element_name, thumbname_image, mouseover_element_name, mouseover_image) {
		if (document.images) {
			if(thumbname_element_name.length > 0)
				var imageElement = eval('document.images.' + thumbname_element_name);
			if(imageElement)
				imageElement.src = thumbname_image;

			imageElement.onmouseover =function() {swap_image(mouseover_element_name, mouseover_image);};
		}
	}

	function isCookieEnabled(){
		var tmpcookie = new Date();
	    chkcookie = (tmpcookie.getTime() + '');
	    document.cookie = "chkcookie=" + chkcookie + "; path=/";
	    if (document.cookie.indexOf(chkcookie,0) < 0) {
	      return false;
	      }
	    else {
	      return true;
	    }

	}

/* ---------------------------- */
/* End org scripts.js */
/* ---------------------------- */

/* PERSISTENT CART PAGING */
function paging(){
	var scrollId = document.getElementById('scroll');
	var cartItems = document.getElementById('cartitems');
	if (!cartItems) { return; }
	var sets = cartItems.getElementsByTagName('ul');
	for (i=3; i<sets.length; i++) {
		sets[i].style.display = "none"; // initially, hide all uls except the first three
	}

	var pageup = document.getElementById('pageup');
	pageup.style.display = "none";

	//alert (sets);
	if (sets.length > 3) { 					/* check to see if there are more then one set in cart */
		scrollId.style.display = "block"; 	/* display paging arrows */
		var pageup = document.getElementById('pageup');
		var pagedown = document.getElementById('pagedown');

		attachEventListener(pageup, "click", scrollUp, false);
		attachEventListener(pagedown, "click", scrollDown, false);
	}
}

function scrollDown() {
	var current = document.getElementById('current');
	var currentInt = parseInt(current.value);
	var firstBatch = document.getElementById('batch' + currentInt);
	firstBatch.style.display = "none";

	var counter = (currentInt) + 3;
	var nextVisible = document.getElementById('batch' + counter);
	nextVisible.style.display = "block";

	current.value = currentInt + 1;

	var pageup = document.getElementById('pageup');
	pageup.style.display = "block";

	var pagedown = document.getElementById('pagedown');
	var nextPossibleValue = (currentInt) + 4;
	var nextPossibleList = document.getElementById('batch' + nextPossibleValue);
	if (!nextPossibleList) {
		pagedown.style.display = "none";
	}


}

function scrollUp() {

	var current = document.getElementById('current');
	var currentInt = parseInt(current.value);
	var counterLastRow = (currentInt) +  2;
	var firstBatch = document.getElementById('batch' + counterLastRow);
	firstBatch.style.display = "none";

	var counter = (currentInt) - 1;
	var nextVisible = document.getElementById('batch' + counter);
	nextVisible.style.display = "block";

	current.value = currentInt - 1;

	var pagedown = document.getElementById('pagedown');
	pagedown.style.display = "block";

	var pageup = document.getElementById('pageup');
	var nextPossibleValue = (currentInt) + 4;
	var nextPossibleList = document.getElementById('batch' + nextPossibleValue);
	if (counter == 1) {
		pageup.style.display = "none";
	}
}

/* PAGING ARROWS HOVER */
function hoverArrow(){
		var pageup = document.getElementById('pageup');
		var pagedown = document.getElementById('pagedown');
		if (!pageup) { return };
		if (!pagedown) { return };

		attachEventListener(pageup, "mouseover", hoverUpArrow, false);
		attachEventListener(pageup, "mouseout", unHoverUpArrow, false);
		attachEventListener(pagedown, "mouseover", hoverDownArrow, false);
		attachEventListener(pagedown, "mouseout", unHoverDownArrow, false);
}

function hoverDownArrow(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/down_over.gif";
	element.src = picture;
}

function unHoverDownArrow(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/down.gif";
	element.src = picture;
}

function hoverUpArrow(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/up_over.gif";
	element.src = picture;
}

function unHoverUpArrow(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/up.gif";
	element.src = picture;
}


/* LOGIN */

function userLogin() {
	var login = document.getElementById('login');
	var closeLogin = document.getElementById('closelog');
	attachEventListener(closeLogin, "mouseover", hoverCloseLogin, false);
	attachEventListener(closeLogin, "mouseout", unHoverCloseLogin, false);
	attachEventListener(login, "click", showLogIn, false);
	attachEventListener(closeLogin, "click", hideLogIn, false);
}

function hoverCloseLogin(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/close_2_over.gif";
	element.src = picture;
}

function unHoverCloseLogin(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/close_2.gif";
	element.src = picture;
}

function showLogIn() {
	var logdiv = document.getElementById('logincontain');
	if (logdiv != "") {
 		logdiv.style.display = "block";
	};
}

function hideLogIn() {
	var logdiv = document.getElementById('logincontain');
	if (logdiv != "") {
 		logdiv.style.display = "none";
	};
}

/* HOVER DELETE BUTTONS IN SHOPPING CART */

function hoverDelete() {
	var buttons = getElementsByAttribute('class', 'delete');
	if (!buttons) { return; }

	for (i=0; i<buttons.length; i++) {
		attachEventListener(buttons[i], "mouseover", showDel, false);
		attachEventListener(buttons[i], "mouseout", hideDel, false);
	}

}

function showDel(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/delete_x_over.png";
	element.src = picture;
	//alert ('me');
}

function hideDel(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/delete_x.png";
	element.src = picture;
	//alert ('me');
}


/* DISPLAY SUBNAVIGATION */

function showSubnav() {
	var community = document.getElementById('community');
	var subNav = document.getElementById('subnav');
	if (!community) { return; }

	attachEventListener(community, "mouseover", displayNav, false);
	attachEventListener(community, "mouseout", hideNav, false);
	attachEventListener(subNav, "mouseover", displayNav, false);
	attachEventListener(subNav, "mouseout", hideNav, false);

}

function displayNav(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);

	var subNav = document.getElementById('subnav');
	if (!subNav) { return; }
	subNav.style.display = "block";
}

function hideNav(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);

	var subNav = document.getElementById('subnav');
	if (!subNav) { return; }
	subNav.style.display = "none";
}



/* HOVER CHECKOUT BUTTON */

function hoverCheckout() {
	var checkout = document.getElementById('checkout');
	if (!checkout) { return; }

	attachEventListener(checkout, "mouseover", checkHover, false);
	attachEventListener(checkout, "mouseout", checkNormal, false);


}

function checkHover(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/checkout_over.png";
	element.src = picture;
}

function checkNormal(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/checkout.png";
	element.src = picture;
}



/* OPEN SIZE CHART  */
function openSizeChart() {
	var openchart = document.getElementById('openchart');
	var closechart = document.getElementById('closechart');
	if (!openchart) { return; }
	if (!closechart) { return; }
	attachEventListener(closechart, "mouseover", hoverCloseChart, false);
	attachEventListener(closechart, "mouseout", unHoverCloseChart, false);
	attachEventListener(openchart, "click", openChart, false);
	attachEventListener(closechart, "click", closeChart, false);
}

function openChart() {
	var sizechart = document.getElementById('sizechart');
	sizechart.style.display = "block";

}

function closeChart() {
	var sizechart = document.getElementById('sizechart');
	sizechart.style.display = "none";
}


/* OPEN SIDE SIZE CHART  */
function openSideSizeChart() {
	var openchart = document.getElementById('gobutton');
	var closechart = document.getElementById('closeallsizes');
	if (!openchart) { return; }
	if (!closechart) { return; }
	attachEventListener(closechart, "mouseover", hoverCloseChart, false);
	attachEventListener(closechart, "mouseout", unHoverCloseChart, false);
	attachEventListener(openchart, "click", openSideChart, false);
	attachEventListener(closechart, "click", closeSideChart, false);
}

function hoverCloseChart(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/close_x_over.gif";
	element.src = picture;
}

function unHoverCloseChart(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/close_x.gif";
	element.src = picture;
}


function openSideChart() {
	var sizechart = document.getElementById('allsizes');
	sizechart.style.display = "block";

}

function closeSideChart() {
	var sizechart = document.getElementById('allsizes');
	sizechart.style.display = "none";
}


/* ADD TO CART HOVER */
function addCartHover() {
	var thisID = document.getElementById('addtocart');
	if (!thisID) { return; }
	attachEventListener(thisID, "mouseover", cartHover, false);
	attachEventListener(thisID, "mouseout", cartNormal, false);
}

function cartHover(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/add_to_cart_over.gif";
	element.src = picture;
}

function cartNormal(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/add_to_cart.gif";
	element.src = picture;
}



/* GO SIZE HOVER */
function goSizeHover() {
	var thisID = document.getElementById('gobutton');
	if (!thisID) { return; }
	attachEventListener(thisID, "mouseover", goHover, false);
	attachEventListener(thisID, "mouseout", goNormal, false);
}

function goHover(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/foot_go_over.gif";
	element.src = picture;
}

function goNormal(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/foot_go.gif";
	element.src = picture;
}


/* INTERNATIONAL DROPDOWN */

function countryDropdown() {
	var thisID = document.getElementById('international');
	var divID = document.getElementById('countrycontain');
	attachEventListener(thisID, "mouseover", showCountries, false);
	attachEventListener(thisID, "mouseout", hideCountries, false);
	attachEventListener(divID, "mouseover", showCountries, false);
	attachEventListener(divID, "mouseout", hideCountries, false);
}

function showCountries() {
	var thisID = document.getElementById('countrycontain');
	if (thisID != "") {
 		thisID.style.display = "block";
	};
}

function hideCountries() {
	var thisID = document.getElementById('countrycontain');
	if (thisID != "") {
 		thisID.style.display = "none";
	};
}


/* OPEN STATE LIST  */
function showStatesList() {
	var thisID = document.getElementById('choosestate');
	var divID = document.getElementById('statelist');
	if (!thisID) { return; }
	if (!divID) { return; }
	attachEventListener(thisID, "click", showStates, false);
	attachEventListener(divID, "mouseover", showStates, false);
	attachEventListener(divID, "mouseout", hideStates, false);
}

function showStates() {
	var divID = document.getElementById('statelist');
	divID.style.display = "block";

}

function hideStates() {
	var divID = document.getElementById('statelist');
	divID.style.display = "none";
}

/* OPEN CITY LIST  */
function showCityList() {
	var thisID = document.getElementById('choosecity');
	var divID = document.getElementById('citylist');
	if (!thisID) { return; }
	if (!divID) { return; }
	attachEventListener(thisID, "click", showCities, false);
	attachEventListener(divID, "mouseover", showCities, false);
	attachEventListener(divID, "mouseout", hideCities, false);
}

function showCities() {
	var divID = document.getElementById('citylist');
	divID.style.display = "block";

}

function hideCities() {
	var divID = document.getElementById('citylist');
	divID.style.display = "none";
}

/* CHECKOUT DIV AND CONTAINER HEIGHT  */
function setHeight(){
	var container = document.getElementById('container');
	if (!container) { return; };
	var pixelHeight = container.offsetWidth;
	var co = document.getElementById('co');
	if (!co) { return; };
	co.style.height = pixelHeight + "px";
}


/* VIEW DETAIL HOVERS */
function viewHover(){
		var view1 = document.getElementById('view1');
		var view2 = document.getElementById('view2');
		var view3 = document.getElementById('view3');
		if (!view1) { return };
		if (!view2) { return };
		if (!view3) { return };

		attachEventListener(view1, "mouseover", hoverView1, false);
		attachEventListener(view1, "mouseout", unHoverView1, false);
		attachEventListener(view2, "mouseover", hoverView2, false);
		attachEventListener(view2, "mouseout", unHoverView2, false);
		attachEventListener(view3, "mouseover", hoverView3, false);
		attachEventListener(view3, "mouseout", unHoverView3, false);
}

function hoverView1(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/view1_over.gif";
	element.src = picture;
}

function unHoverView1(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/view1.gif";
	element.src = picture;
}

function hoverView2(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/view2_over.gif";
	element.src = picture;
}

function unHoverView2(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/view2.gif";
	element.src = picture;
}

function hoverView3(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/view3_over.gif";
	element.src = picture;
}

function unHoverView3(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/view3.gif";
	element.src = picture;
}


/* SEE ALL HOVER */
function seeAllHover() {
	var menSeeall = document.getElementById('menSeeall');
	var seeall = document.getElementById('seeall');
	if (!menSeeall) { return; }
	if (!seeall) { return; }
	attachEventListener(menSeeall, "mouseover", menSeeAllShow, false);
	attachEventListener(menSeeall, "mouseout", menSeeAllHide, false);
	attachEventListener(seeall, "mouseover", seeAllShow, false);
	attachEventListener(seeall, "mouseout", seeAllHide, false);
}

function menSeeAllShow(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/men_title_seeall_over.gif";
	element.src = picture;
}

function menSeeAllHide(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/images/men_title_seeall.gif";
	element.src = picture;
}

function seeAllShow(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/see_all_over.gif";
	element.src = picture;
}

function seeAllHide(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var picture = "/colorwar/images/see_all.gif";
	element.src = picture;
}




/* PRESS HOVER NEED TO MAKE IT WORK */
function pressHover(){
	var list = getElementsByAttribute('class', 'pressitem');

	if (!list) { return; }

	for (i=0; i < list.length; i++) {
		var j = i + 1;
		var thisID = "presslg" + j;
		var presspops = new Array();
		presspops[i] = document.getElementById(thisID);

		attachEventListener(list[i], "mouseover", showBigPress, false);
		attachEventListener(presspops[i], "mouseover", showBigPress, false);
		attachEventListener(presspops[i], "mouseout", hideBigPress, false);
	}

}

function showBigPress(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	var presspop = element.getElementsByTagName('div');
	for (var i = 0; i < presspop.length; i++) {
		presspop[i].className = "presspop";

	}
	//presspop[0].style.display = "block";
}

function hideBigPress() {
	var presspop = document.getElementById('presslg1');
	presspop.style.display = "none";
}



function productHovers(){
	var myUl = document.getElementById('products');

	if (!myUl) { return; }
	var list=myUl.getElementsByTagName('li');
	for(i=0;i<list.length;i++) {
		list[i].style.position = "static";
	}

	for (i=0; i<list.length; i++) {
		attachEventListener(list[i], "mouseover", setRelative, false);
	}

}

function setRelative(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}
	var element = getEventTarget(event);
	element.style.position = "relative";
}

function setRelative2() {

	var spans=myLi.getElementsByTagName('span');
	for(i=0;i<spans.length;i++) {
		spans[i].style.display = "block";
		spans[i].style.position = "absolute";
	}

}

function hideSpan(id) {
	var hideMe=document.getElementById(id);
	hideMe.style.display = "none";
	hideMe.style.zIndex = "0";
}



/* FOR IE TO HOVER SIDEBAR SHOPPING ITEMS */
/*function hoverLi(){
	var cartItems = document.getElementById('cartitems');
	if (!cartItems) { return; }
	var lis = cartItems.getElementsByTagName('li');

	for (i=0; i<lis.length; i++) {
		attachEventListener(lis[i], "mouseover", hoverProduct, false);
		attachEventListener(lis[i], "mouseout", normalProduct, false);
	}


}

function hoverProduct() {
alert ('i work');

}
*/
/* utility functions -- no need to edit */

function nextSiblingElement(elem) {
	do {
	elem = elem.nextSibling;
	} while (elem && elem.nodeType != 3);
	return elem;
}

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}

function attachEventListener(target, eventType, functionRef, capture)
{
  if (typeof target.addEventListener != "undefined")
  {
    target.addEventListener(eventType, functionRef, capture);
  }
  else if (typeof target.attachEvent != "undefined")
  {
    target.attachEvent("on" + eventType, functionRef);
  }
  else
  {
    eventType = "on" + eventType;

    if (typeof target[eventType] == "function")
    {
      var oldListener = target[eventType];

      target[eventType] = function()
      {
        oldListener();

        return functionRef();
      }
    }
    else
    {
      target[eventType] = functionRef;
    }
  }

  return true;
}


function getElementsByAttribute(attribute, attributeValue)
{
  var elementArray = new Array();
  var matchedArray = new Array();

  if (document.all)
  {
    elementArray = document.all;
  }
  else
  {
    elementArray = document.getElementsByTagName("*");
  }

  for (var i = 0; i < elementArray.length; i++)
  {
    if (attribute == "class")
    {
      var pattern = new RegExp("(^| )" + attributeValue + "( |$)");

      if (elementArray[i].className.match(pattern))
      {
        matchedArray[matchedArray.length] = elementArray[i];
      }
    }
    else if (attribute == "for")
    {
      if (elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for"))
      {
        if (elementArray[i].htmlFor == attributeValue)
        {
          matchedArray[matchedArray.length] = elementArray[i];
        }
      }
    }
    else if (elementArray[i].getAttribute(attribute) == attributeValue)
    {
      matchedArray[matchedArray.length] = elementArray[i];
    }
  }

  return matchedArray;
}

function getEventTarget(event) {
	var targetElement = null;

	if (typeof event.target != "undefined") {
		targetElement = event.target;
	} else {
		targetElement = event.srcElement;
	}

	while (targetElement.nodeType == 3 && targetElement.parentNode != null) {
		targetElement = targetElement.parentNode;
	}

	return targetElement;
}


// "handler_func" is the name of the function.
function asyncGet(url, handler_func, arg) {
	var req;

	try {
		req = new XMLHttpRequest();
	} catch (e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { }
		}
	}

	if (req) {
		var currentTime = new Date();
		req.open("GET", url + "?time=" + currentTime.getTime(), true);
		req.onreadystatechange = function() {
			try {
				if (req.readyState == 4 && req.status == 200) {
					var response = req.responseText;
					eval(handler_func + '(response, arg)');
				}
			} catch (e) {}
		}

		req.send(null);
	}
}

		/**
		 * Updates the layer(popup) div contain the checkout page.
		*/
		function updateCOPage(response, arg) {
			document.getElementById(arg.elementId).innerHTML= response;
			//close the ajax loader
			closeAjaxLoader();
		}


//original file: popup.js-----------------------------------------------------------
/*
	This javascript class is responsible for showing a up.
	It will adjust the position when the user scroll (horizon and vertical)

	Usage::

	url: the url that it need to async call to get content
	elementID: id of the document element it will populate the data into
	popUp(url, elementID)


*/
	function popUp(url, elementID, url_params) {

		setHeight();
		popUpRelocate(elementID);
		asyncGet(url, 'updateCOPage', {'elementId': elementID}, url_params);
		document.getElementById(elementID).style.display = "block";
		document.getElementById('pop_up_bg').style.display = "block";
		document.body.onscroll = popUpRelocate;
		window.onscroll = popUpRelocate;

	}

	function popUp(url, elementID) {

		document.getElementById(elementID).innerHTML= "";

		//setHeight();
		//popUpRelocate(elementID);
		//document.getElementById('ajax_loader').style.display = "block";
		//showAjaxLoader();
		asyncGet(url, 'updateCOPage', {'elementId': elementID});

		document.getElementById(elementID).style.display = "block";
		document.getElementById('pop_up_bg').style.display = "block";

		//document.body.onscroll = popUpRelocate;
		//window.onscroll = popUpRelocate;

	}



	function closePopUp() {
		document.getElementById("cw_co").style.display="none";
		document.getElementById("co").style.display="none";
		document.getElementById("co_top").style.display="none";
		document.getElementById("pop_up_bg").style.display = "none";
	}

	function scrolledX() {
		var scrolledX;
		if( self.pageYOffset ) {
		  scrolledX = self.pageXOffset;
		} else if( document.documentElement && document.documentElement.scrollTop ) {
		  scrolledX = document.documentElement.scrollLeft;
		} else if( document.body ) {
		  scrolledX = document.body.scrollLeft;
		}

		return scrolledX;
	}

	function scrolledY() {
		var scrolledY;
		if( self.pageYOffset ) {
		  scrolledY = self.pageYOffset;
		} else if( document.documentElement && document.documentElement.scrollTop ) {
		  scrolledY = document.documentElement.scrollTop;
		} else if( document.body ) {
		  scrolledY = document.body.scrollTop;
		}

		return scrolledY;
	}


	function centerX() {

		var centerX;
		if( self.innerHeight ) {
		  centerX = self.innerWidth;
		} else if( document.documentElement && document.documentElement.clientHeight ) {
		  centerX = document.documentElement.clientWidth;
		} else if( document.body ) {
		  centerX = document.body.clientWidth;
		}

		return centerX;
	}

	function centerY() {

		var centerY;
		if( self.innerHeight ) {
		  centerY = self.innerHeight;
		} else if( document.documentElement && document.documentElement.clientHeight ) {
		  centerY = document.documentElement.clientHeight;
		} else if( document.body ) {
		  centerY = document.body.clientHeight;
		}

		return centerY;
	}

	function popUpRelocate() {

		//var leftOffset = scrolledX() + 50;
		//var topOffset = scrolledY() + 50;

		//document.getElementById('co').style.top = topOffset + "px";
		//document.getElementById('co').style.left = leftOffset + "px";

	}

	function showAjaxLoader() {

		setAjaxHelperHeight();
		document.getElementById('ajax_loader').style.display = "block";
	}

	function closeAjaxLoader() {
		document.getElementById('ajax_loader').style.display = "none";
	}

	function setAjaxHelperHeight(){

			var container = document.getElementById('container');
            if (!container) { return; };

            var pixelHeight = container.offsetWidth;
            var ajax_loader = document.getElementById('ajax_loader');

            if (!ajax_loader) { return; };

            ajax_loader.style.height = pixelHeight + "px";

	}


	function setHeight(){

            var container = document.getElementById('container');
            if (!container) { return; };

            var pixelHeight = document.body.offsetHeight;

            var co_top = document.getElementById('co_top');

            if (!co_top) { return; };

            co_top.style.height = pixelHeight + "px";

            var pop_up_bg = document.getElementById('pop_up_bg');

            if (!pop_up_bg) { return; };

            pop_up_bg.style.height = pixelHeight + "px";
	}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function toggleMemberDiv(div_num) {
	var show_div = document.getElementById('new_memberemail_block_'+div_num);
	var strike_div = document.getElementById('org_memberemail_block_'+div_num);

	if (show_div.style.display == 'block') {
		show_div.style.display = 'none';
		strike_div.style.textDecoration = 'none';
	}
	else {
		show_div.style.display = 'block';
		strike_div.style.textDecoration = 'line-through';
	}
}

function submit_tell_a_friend(divName) {

	var name_input = document.getElementById('tell_a_friend_name');
	var name = name_input.value;
	var email_input = document.getElementById('tell_a_friend_email');
	var email = email_input.value;
	var friendname_input = document.getElementById('tell_a_friend_friendname');
	var friendname = friendname_input.value;
	var friendemail_input = document.getElementById('tell_a_friend_friendemail');
	var friendemail = friendemail_input.value;
	var message_input = document.getElementById('tell_a_friend_message');
	var message = message_input.value;

	var post_body = 'name=' + name + '&email=' + email + '&friendname=' + friendname+ '&friendemail=' + friendemail+ '&message=' + message;

	var dd = document.getElementById(divName);

	new Ajax.Request(site_url+'/pages/process_tell_a_friend/',{

			method:'post',
			postBody:post_body,
			asynchronous:true,

			onSuccess: function(t) {
				dd.innerHTML = t.responseText;
			},

			onFailure: function(t) {
				dd.innerHTML = "An error occurred while submitting your request. Please try again.";
			}
		});
}

//moved to index page to get site_dir defined in call
/*
function getTeamLeaderSignUp(schoolID, colorID) {
	window.scrollTo(0,0);
	popUp('/teams/create/'+schoolID+'/'+colorID, 'co');
} */

function submitTeamLeaderSignUpSchedule(divName) {
	var school_id_input = document.getElementById('signup_school_id');
	var school_id = school_id_input.value;
	var color_id_input = document.getElementById('signup_color_id');
	var color_id = color_id_input.value;
	var schedule_id = getCheckedValue(document.forms['schedule_form'].elements['signup_schedule_id'])

	var post_body = 'school_id=' + school_id+ '&color_id=' + color_id+ '&schedule_id=' + schedule_id;

	var dd = document.getElementById(divName);

	if (schedule_id.length > 0) {
		new Ajax.Request(site_url+'/teams/create/',{

				method:'post',
				postBody:post_body,
				asynchronous:true,

				onSuccess: function(t) {
					dd.innerHTML = t.responseText;
				},

				onFailure: function(t) {
					dd.innerHTML = "An error occurred while submitting your request. Please try again.";
				}
			});
	} else {
		alert('Please select a competition time.');
	}

}

function submitTeamLeaderSignUp(divName) {

	var first_name_input = document.getElementById('signup_first_name');
	var first_name = first_name_input.value;
	var last_name_input = document.getElementById('signup_last_name');
	var last_name = last_name_input.value;
	var email_input = document.getElementById('signup_email');
	var email = email_input.value;
	var phone_input = document.getElementById('signup_phone');
	var phone = phone_input.value;
	var password_input = document.getElementById('signup_password');
	var password = password_input.value;
	var memberemail1_input = document.getElementById('signup_memberemail1');
	var memberemail1 = memberemail1_input.value;
	var memberemail2_input = document.getElementById('signup_memberemail2');
	var memberemail2 = memberemail2_input.value;
	var memberemail3_input = document.getElementById('signup_memberemail3');
	var memberemail3 = memberemail3_input.value;
	var memberemail4_input = document.getElementById('signup_memberemail4');
	var memberemail4 = memberemail4_input.value;
	var memberemail5_input = document.getElementById('signup_memberemail5');
	var memberemail5 = memberemail5_input.value;
	var school_id_input = document.getElementById('signup_school_id');
	var school_id = school_id_input.value;
	var color_id_input = document.getElementById('signup_color_id');
	var color_id = color_id_input.value;
	var schedule_id_input = document.getElementById('signup_schedule_id');
	var schedule_id = schedule_id_input.value;
	var confirm_input = document.getElementById('signup_confirm');
	var confirm = confirm_input.value;


	var post_body = 'first_name=' + first_name + '&last_name=' + last_name + '&email=' + email+ '&phone=' + phone+ '&password=' + password+
	'&memberemail1=' + memberemail1+ '&memberemail2=' + memberemail2+ '&memberemail3=' + memberemail3+ '&memberemail4=' + memberemail4+ '&memberemail5=' + memberemail5+
	'&school_id=' + school_id+ '&color_id=' + color_id+ '&schedule_id=' + schedule_id + '&confirm=' + confirm;

	var dd = document.getElementById(divName);

	new Ajax.Request(site_url+'/teams/process_create/',{

			method:'post',
			postBody:post_body,
			asynchronous:true,

			onSuccess: function(t) {
				if (t.responseText == "submit_success") {
					window.location = site_url + '/teams/index';
				}
				dd.innerHTML = t.responseText;
			},

			onFailure: function(t) {
				dd.innerHTML = "An error occurred while submitting your request. Please try again.";
			}
		});
}

function getInviteConfirmation(inviteID) {
	window.scrollTo(0,0);
	popUp(site_url+'/teams/confirm_invite/'+inviteID, 'cw_co');
}

function submitTeamMemberSignUp(divName) {

	var invite_id_input = document.getElementById('signup_invite_id');
	var invite_id = invite_id_input.value;
	var first_name_input = document.getElementById('signup_first_name');
	var first_name = first_name_input.value;
	var last_name_input = document.getElementById('signup_last_name');
	var last_name = last_name_input.value;
	var email_input = document.getElementById('signup_email');
	var email = email_input.value;
	var phone_input = document.getElementById('signup_phone');
	var phone = phone_input.value;
	var confirm_input = document.getElementById('signup_confirm');
	var confirm = confirm_input.value;


	var post_body = 'first_name=' + first_name + '&last_name=' + last_name + '&email=' + email+ '&phone=' + phone+ '&confirm=' + confirm+ '&invite_id=' + invite_id;

	var dd = document.getElementById(divName);

	new Ajax.Request(site_url+'/teams/process_invite/',{

			method:'post',
			postBody:post_body,
			asynchronous:true,

			onSuccess: function(t) {
				dd.innerHTML = t.responseText;
			},

			onFailure: function(t) {
				dd.innerHTML = "An error occurred while submitting your request. Please try again.";
			}
		});
}