 



// ************** AjaxSupport control begin ************************
var xmlhttp;
function loadXMLDoc(url, params, resultDest, resultHandler, errorHandler) {
xmlhttp=null;
this.params = params;
this.resultDest = resultDest;
this.resultHandler = resultHandler;
this.errorHandler = errorHandler;
this.errorText = '';
var me = this;
this.sendRequest = function() {
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
if (xmlhttp!=null) {
xmlhttp.onreadystatechange=function () {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
if (xmlhttp.responseText.substring(0, 9) == 'GoToError') {
document.location = '/Error.aspx?ErrorMessage=' + xmlhttp.responseText.substring(9);
} else {
me.resultHandler(resultDest, xmlhttp.responseText, params, me);
turnOffWorkingDiv();
}
} else {
me.errorText = xmlhttp.responseText;
me.errorHandler(resultDest, params, me);
turnOffWorkingDiv();
}
}
}
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(me.params);
turnOnWorkingDiv();
} else {
alert('Your browser does not support XMLHTTP.'); }
}
}

function turnOnWorkingDiv()
{
if (document.getElementById('ajax_WorkingOuter') != null)
{
document.getElementById('ajax_WorkingOuter').style.display = "";
setTimeout("turnOnInnerDiv()", 500 );
}
}

function turnOnInnerDiv()
{
if (document.getElementById('ajax_WorkingOuter').style.display == "" && document.getElementById('ajax_WorkingInner') != null)
{
document.getElementById('ajax_WorkingInner').style.display = "";
}
}

function turnOffWorkingDiv()
{
if (document.getElementById('ajax_WorkingOuter') != null)
{
document.getElementById('ajax_WorkingOuter').style.display = "none";
}
if (document.getElementById('ajax_WorkingInner') != null)
{
document.getElementById('ajax_WorkingInner').style.display = "none";
}
}
// ************** AjaxSupport control end ************************


// ************** Accordian control begin ************************
var F_FilterOptions = '';

function ApplyTradeFilter()
{
  F_FilterOptions='';
  var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].type == "checkbox" && inputs[a].className == "styled" && inputs[a].value == "TradeFilter") {
			if (inputs[a].checked)
			F_FilterOptions += inputs[a].id+',';
	              }
     }
     //TODO 
	try
    {
        ApplyFilter(AutoApplyFilters, F_FilterOptions);
    }
    catch(err)
    {
    }
     
}

// -----------------------------------------------------------------
//
// TCD Checkboxes 
// Default Behavior
//
//
// -----------------------------------------------------------------


// ------------------------------------------------------------
//	CSS Form fields - Floating Inital Values
// ------------------------------------------------------------
function initOverLabels () {
  if (!document.getElementById) return;  	

  var labels, id, field;

  // Set focus and blur handlers to hide and show 
  // LABELs with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
	
    if (labels[i].className == 'overlabel') {

      // Skip labels that do not have a named association
      // with another field.
      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      }

      // Change the applied class to hover the label 
      // over the form field.
      labels[i].className = 'overlabel-apply';

      // Hide any fields having an initial value.
      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      // Set handlers to show and hide labels.
      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      // Handle clicks to LABEL elements (for Safari).
      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };
    }
  }
};

function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-10000px' : '0px';
      return true;
    }
  }
}


// ------------------------------------------------------------
//	Auto focus textfield - < Enter The Code >
// ------------------------------------------------------------
function autofocus(field, limit, next, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
    if (charCode > 31 && field.value.length == limit) {
        field.form.elements[next].focus();
    }
}


// ------------------------------------------------------------
//	Custome graphical form elements
// ------------------------------------------------------------
var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "105";
var selectWidth2 = "60";
var selectWidth3 = "255";

/* No need to change anything after this */

document.write('<style type="text/css">input.styled { display: none; } input.upload-styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } select.styled2 { position: relative; width: ' + selectWidth2 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } select.styled3 { position: relative; width: ' + selectWidth3 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');


// Funtion to change the Text Color

function colorChange(el) {
    if (el.name != '')
    {
	    var radgroup = document.getElementsByName(el.name);
	    for (var r=0; radgroup[r]; ++r)
    	    radgroup[r].parentNode.style.color = radgroup[r].checked ? 'red' : 'white';
	}
}

function getCheck(el) {
	if (el.checked == true){
		el.checked = false;
	}else{
		el.checked = true; }
		el.onchange();
		ApplyTradeFilter();
}

var CustomCheckRadio = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;
				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
					colorChange(inputs[a]);
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = CustomCheckRadio.clear;
				span[a].onmousedown = CustomCheckRadio.pushed;
				span[a].onmouseup = CustomCheckRadio.check;
				document.onmouseup = CustomCheckRadio.clear;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
			colorChange(element);
		}
		ApplyTradeFilter();
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
			try 
		    {
		    if (inputs[b].className == "styled") {
			    colorChange(inputs[b]);
			}
			}
			catch(ex)
			{}
		}
	}
}

var UploadCheckRadio = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, active;
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].type == "checkbox" && inputs[a].className == "upload-styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;
				if(inputs[a].checked == true) {
					position = "0 -" + (checkboxHeight*2) + "px";
					span[a].style.backgroundPosition = position;
					colorChange(inputs[a]);
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = UploadCheckRadio.clear;
				span[a].onmousedown = UploadCheckRadio.pushed;
				span[a].onmouseup = UploadCheckRadio.check;
				document.onmouseup = UploadCheckRadio.clear;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true) {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked != true) {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true) {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			element.checked = true;
			colorChange(element);
		}
		if (element.name.indexOf('group') >= 0) {
		    UploadCheckRadio.checkAll(element.checked, element.alt);
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].checked == true && inputs[b].className == "upload-styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].className == "upload-styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
			colorChange(inputs[b]);
		}
	},
	checkAll: function(turnOn, versionCodes) {
		inputs = document.getElementsByTagName("input");
		var codes = Array();
		if (versionCodes != null)
		{
		    codes = versionCodes.split(',');
		}
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].className == "upload-styled") {
			    var checkIt = true;
			    if (codes.length > 0) {
			        checkIt = false;
			        for (var i=0; i < codes.length; i++) {
			            if (inputs[b].alt == codes[i]) {
			                checkIt = true;
			                break;
			            }
			        }
			    }
			    if (checkIt) {
  		    		inputs[b].checked = turnOn;
			        if (turnOn) {
    		    		inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
	        		} else {
	    	    		inputs[b].previousSibling.style.backgroundPosition = "0 0";
    			    }
			    }
    			colorChange(inputs[b]);
			}
		}
	},
	getChecked: function() {
	    var checkList = '';
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].checked == true && inputs[b].className == "upload-styled" && inputs[b].name.indexOf('group') < 0) {
                if (checkList.length != 0) {
                    checkList += ',';
                }
                checkList += inputs[b].alt;
			}
		}
		return checkList;
	}
}

var CustomSelect = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option;
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = CustomSelect.choose;
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
				//TODO
				
			     if (typeof IsRegistrationPage != 'undefined')
			    	{
			    	  RegistrationCheckParentEmailDisplay(); 
			    	}
			    
				try
                {
			    	
			    	SetRowsPerPage(option[d].value);
			    	
			    	
                }
                catch(err)
                {
                }
			}
		}
	}
}

var CustomSelect2 = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option;
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled2") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select2";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = CustomSelect.choose;
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}

var CustomSelect3 = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option;
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled3") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select3";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = CustomSelect3.choose;
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
				if (this.name == "Country" && SetLanguageList != undefined) {
				    SetLanguageList();
				}
			}
		}
	}
}
