jQuery("head").append("<style type=\"text\/css\">.ibm-form-width-fix { behavior: expression(window.dropdown_menu_hack!=null?window.dropdown_menu_hack(this):0); }<\/style>");

/********************  BROWSER DETECTION ***************************************/

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},{
			string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},{
			prop: window.opera,
			identity: "Opera"
		},{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},{ // for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}]
};

BrowserDetect.init();

/*********************** Translations for Validation ************************/

pageLang = jQuery("head meta[name=DC.Language]").attr("content");
pageLang = pageLang.replace(/-/,"_");

jQuery("head script").prepend("<script type=\"text\/javascript\" src=\"/software/uk/forms/lang/"+pageLang+"/validation-trans.js\">\/\/<\/script>");

/************************ Other declarations **********************************************************/

var required = new Array();
var email = new Array();
var email_compare = new Array();
var req_error = new Array();
var eml_error = new Array();
var select_width_fix = new Array();
var elm_REQ_pos = 0;
var elm_EML_pos = 0;
var eml_compare = true;

if(typeof(correctY_ie) != undefined) var correctY_ie = 95;
if(typeof(correctY_def) != undefined) var correctY_def = 104;
if(typeof(correctX) != undefined) var correctX = 426;

var error_icon_start = "<a class=\"ibm-error-link\" href=\"javascript:void()\"><img style=\"padding-top:14px\" src=\"//www.ibm.com/i/c.gif\" width=\"1\" height=\"1\" alt=\"";
var error_icon_end = "\" /><\/a>";
var info_msg = "<div class=\"ibm-rule\"><hr \/><\/div><p class=\"ibm-ind-error\"><strong>" + def_error_msg + "<\/strong><\/p><div class=\"ibm-rule\"><hr \/><\/div><p>&nbsp;<\/p>";

var CoutriesCodes = new Array("","AF","AX","AL","DZ","AS","AD","AO","AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY","BE","BZ","BJ","BM","BT","BO","BA","BW","BV","BR","IO","BN","BG","BF","BI","KH","CM","CA","CV","KY","CF","TD","CL","CN","HK","MO","CX","CC","CO","KM","CG","CD","CK","CR","HR","CY","CZ","CI","DK","DJ","DM","DO","EC","EG","SV","GQ","ER","EE","ET","FK","FO","FJ","FI","FR","GF","PF","TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GG","GN","GW","GY","HT","HM","VA","HN","HU","IS","IN","ID","IQ","IE","IM","IL","IT","JM","JP","JE","JO","KZ","KE","KI","KR","KW","KG","LA","LV","LB","LS","LR","LY","LI","LT","LU","MK","MG","MW","MY","MV","ML","MT","MH","MQ","MR","MU","YT","MX","FM","MD","MC","MN","ME","MS","MA","MZ","MM","NA","NR","NP","NL","AN","NC","NZ","NI","NE","NG","NU","NF","MP","NO","OM","PK","PW","PS","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RO","RU","RW","RE","BL","SH","KN","LC","MF","PM","VC","WS","SM","ST","SA","SN","RS","SC","SL","SG","SK","SI","SB","SO","ZA","GS","ES","LK","SR","SJ","SZ","SE","CH","TW","TJ","TZ","TH","TL","TG","TK","TO","TT","TN","TR","TM","TC","TV","UG","UA","AE","GB","US","UM","UY","UZ","VU","VE","VN","VG","VI","WF","EH","YE","ZM","ZW");
	
/********************  on DOM READY ***************************************/

jQuery(document).ready(function() {

	/**************************  MASTER DECLARATION *********************************/
	
	jQuery("#InfoMssError").html(info_msg);
	jQuery("textarea").css("width","228px");
	
	RQ_label = jQuery(".ibm-required").parent("label");
	RQ_p = jQuery("p:has(strong.ibm-required) + fieldset");
	Email = jQuery(".ibm-form-email");
	Wfix = jQuery(".ibm-form-width-fix");
	if (jQuery(".ibm-form-country").length != 0) { cc_id = jQuery(".ibm-form-country").attr("id"); CC_list = jQuery("#"+cc_id) }
	if (jQuery(".ibm-form-state").length != 0) { st_id = jQuery(".ibm-form-state").attr("id"); ST_list_old = jQuery("#"+st_id) }
	
	for ( rq = 0; rq < RQ_label.length; rq ++ ) { required.splice(required.length + 1, 0, RQ_label.eq(rq).attr("for")) } // add element to array required
	for ( rq = 0; rq < RQ_p.length; rq ++ ) { required.splice(required.length + 1, 0, RQ_p.eq(rq).children().find("label:first").attr("for")) } // add element to array required
	for ( em = 0; em < Email.length; em ++ ) { email.splice(email.length + 1, 0, Email.eq(em).attr("id")) } // add element to array email
	for ( w = 0; w < Wfix.length; w ++ ) { select_width_fix.splice(select_width_fix.length + 1, 0, Wfix.eq(w).attr("id")) } // add element to array select_width_fix
	
	/*******************************  EVENTS ****************************************/
	
	eventElm = required.concat(email);
	eventElm.sort();
	var rt = 0;
	while ( rt < eventElm.length) { rs = rt++; if (eventElm[rt] == eventElm[rs]) eventElm.splice(rs,1) }
	
	for (n in eventElm) {
		eElm = jQuery("#" + eventElm[n]);
		if (eElm.attr("type") == "text" || eElm.is("textarea")) { eElm.bind("change", {obj: eElm, type: "A"}, function(e) { EventCheck(e.data.obj,e.data.type) }) }
		if (eElm.attr("type") == "radio") { jQuery("input[name="+eElm.attr("name")+"]").bind("click", {obj: eElm, type: "B"}, function(e) { EventCheck(e.data.obj,e.data.type) }) }
		if (eElm.attr("type") == "checkbox") { jQuery("fieldset:has(input#"+eElm.attr("id")+") input[type=checkbox]").bind("click", {obj: eElm, type: "C"}, function(e) { EventCheck(e.data.obj,e.data.type) }) }
		
		if (eElm.is("select") && BrowserDetect.browser != "Explorer") { eElm.bind("blur", {obj: eElm, type: "D"}, function(e) { EventCheck(e.data.obj,e.data.type) }) }
		if (eElm.is("select") && BrowserDetect.browser == "Explorer") {
			if (BrowserDetect.version <= 7 && !InArray(eElm,select_width_fix)) { eElm.bind("blur", {obj: eElm, type: "D"}, function(e) { EventCheck(e.data.obj,e.data.type) }) }
			if (BrowserDetect.version > 7) { eElm.bind("blur", {obj: eElm, type: "D"}, function(e) { EventCheck(e.data.obj,e.data.type) }) }
		}
	}

	/*******************************  TOOLTIP ***************************************/
	
	TooltipStart();
	
	/****************** EMAIL DEFAULT INFO MESSAGE ***************************/
	
	for (m in email) {
		emlField = jQuery("#"+email[m]);
		if (InArray(emlField,required)) text_msg = def_email_alt_required; else text_msg = def_email_alt;
		labelTEXT = jQuery("label[for="+emlField.attr("id")+"]").text();
		addition = "'" + labelTEXT.slice(0,labelTEXT.search(/\:?\*/)) + "'";
		msg = error_icon_start.replace(/ibm-error-link/,"ibm-information-link") + text_msg.replace(/%/,addition) + error_icon_end;
		emlField.after(msg);
		jQuery("input#"+emlField.attr("id")+"~a.ibm-information-link").bind("mouseenter",{tooltip: text_msg.replace(/%/,addition)}, function(e) { TooltipShow(e.data.tooltip, getX(this),getY(this)) });
		jQuery("input#"+emlField.attr("id")+"~a.ibm-information-link").bind("mouseleave", function(e) { jQuery("#tooltipContent").hide() });
	}
	
	/****************************** Select WIDTH FIX ************************************/
	
	wNum = (BrowserDetect.browser == "Explorer")? "233px" : "232px";
	Wfix.css("width",wNum);

	/************************ COUNTRIES XML PARSING ****************************/
	
	if (jQuery(".ibm-form-country").length != 0) {
		if (BrowserDetect.browser != "Explorer" || (BrowserDetect.browser == "Explorer" && BrowserDetect.version > 7)) CC_list.bind("change", function() { CountriesSelect() });
	}
	if (jQuery(".ibm-form-state").length != 0) {
		ST_list_old.parent().replaceWith("<span><select name=\""+ST_list_old.attr("name")+"\" id=\""+st_id+"\" disabled=\"disabled\"><option value=\"\" selected=\"selected\">" + def_sel_one + "<\/option><\/select><\/span>");
		ST_list = jQuery("#"+st_id);
	}

	/****************** otTitle ************************************************/
	
	jQuery("div#ibm-content").append("<div id=\"opTitle\"><\/div>");
	jQuery("div#opTitle").css({
		"display" : "none",
		"position" : "absolute",
		"background-color" : "#FFFF99",
		"padding" : "3px",
		"border" : "1px solid #CCCCCC",
		"font-family" : "arial, sans-serif",
		"font-size" : "12px"
	});
	
});

/************************ FUNCTIONS ********************************/

function chInput() {
	var ALLresult = false;
	req_error.length = 0; // cleaning array
	eml_error.length = 0; // cleaning array
	
	for (r in required) {
		Elm_rq = jQuery("#"+required[r]);
		if (!checkRequired(Elm_rq)) req_error.splice(req_error.length + 1,0,Elm_rq.attr("id"));
	}
	for ( m in email ) {
		Elm_eml = jQuery("#"+email[m]);
		found_eml_req = InArray(Elm_eml, req_error);
		if (!found_eml_req && Elm_eml.val().length > 0) if (checkEmail(Elm_eml)) eml_error.splice(eml_error.length + 1,0,Elm_eml.attr("id"));
	}
	
	if (req_error.length == 0 && eml_error.length == 0 && eml_compare) ALLresult = true;
	else {
		ShowErrors();
		window.scrollTo(0,getY(document.getElementById("InfoMssError")));
		document.location="#InfoMssError";
	}
	return (ALLresult);
}

function EventCheck(Elm,type) {
	is_req = InArray(Elm, required);
	isInREQArray = InArray(Elm, req_error);
	isInEMLArray = InArray(Elm, eml_error);
	if (type == "A" || type == "D") hideErrorsTypeA(Elm);
	if (type == "B" || type == "C") hideErrorsTypeB(Elm);
	
	if ((Elm.val().length == 0 || !Elm.is(":checked")|| !Elm.is(":selected")) && is_req) {
		if (isInEMLArray) { eml_error.splice(elm_EML_pos,1); hideErrorsTypeA(Elm) }
				
		if (!checkRequired(Elm)) {
			if (!isInREQArray) req_error.splice(req_error.length + 1,0,Elm.attr("id"));
			if (Elm.is("[class=ibm-form-email]")) jQuery("#"+Elm.attr("id")+"~a.ibm-information-link").hide();
			if (type == "A" || type == "D") showErrorsTypeA(Elm);
			if (type == "B" || type == "C") showErrorsTypeB(Elm);
		} else {
			if (isInREQArray) req_error.splice(elm_REQ_pos,1);
		}
	}
	
	if (Elm.is("[class=ibm-form-email]") && Elm.val().length > 0) {
		if (isInREQArray) { req_error.splice(elm_REQ_pos,1); hideErrorsTypeA(Elm) }
		
		if (checkEmail(Elm)) {
			if (!isInEMLArray) eml_error.splice(eml_error.length + 1,0,Elm.attr("id"));
			jQuery("#"+Elm.attr("id")+"~a.ibm-information-link").hide();
			showErrorsTypeC(Elm);
			
		} else {
			if (isInEMLArray) eml_error.splice(elm_EML_pos,1);
			jQuery("#"+Elm.attr("id")+"~a.ibm-information-link").hide();
		}
	}
	
	if (Elm.is("[class=ibm-form-email]") && Elm.val().length == 0 && !is_req) {
		if (isInEMLArray) eml_error.splice(elm_EML_pos,1);
		jQuery("#"+Elm.attr("id")+"~a.ibm-information-link").show();
	}

	ShowHideInfoMssError();
}

function InArray(Elm, pole) {
	isInArray = false;
	for (x in pole) {
		isInArray = (Elm.attr("id") == pole[x])? true : false;
		if (isInArray) {
			if (pole == "eml_error" || pole == "req_error") { elm_REQ_pos = x; elm_EML_pos = x }
			break
			}
	}
	return (isInArray);
}

function checkRequired(Elm) {
	var result = true;
	if (Elm.val().length == 0) result = false;
	if (Elm.is(":radio") && jQuery(":radio[name="+Elm.attr("name")+"]:checked").length == 0) result = false;
	if (Elm.is(":checkbox") && jQuery("fieldset:has(input#"+Elm.attr("id")+") input[type=checkbox]:checked").length == 0) result = false;
	return (result);
}

function checkEmail(Elm) {
	var result = true;
	var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
	if ( regex.test(Elm.val()) ) result = false;
	return (result);
}

function ShowErrors() {
	jQuery("*.ibm-error").removeClass("ibm-error");
	jQuery("a.ibm-error-link").remove();
	
	for (r in req_error) {
		Elm_rq = jQuery("#"+req_error[r]);
		if (Elm_rq.attr("type") == "text" || Elm_rq.is("select") || Elm_rq.is("textarea")) {
			if (Elm_rq.is("[class=ibm-form-email]")) jQuery("#"+Elm_rq.attr("id")+"~a.ibm-information-link").hide();
			showErrorsTypeA(Elm_rq) }
		if (Elm_rq.attr("type") == "radio" || Elm_rq.attr("type") == "checkbox") { showErrorsTypeB(Elm_rq) }
	}
	for (m in eml_error) {
		Elm_eml = jQuery("#"+eml_error[m]);
		showErrorsTypeC(Elm_eml);
	}
	ShowHideInfoMssError();
}

function showErrorsTypeA(Elm) {
	labelTEXT = jQuery("label[for="+Elm.attr("id")+"]").text();
	addition = "'" + labelTEXT.slice(0,labelTEXT.search(/\:\*/)) + "'";
	if (Elm.is("select")) error_text = def_error_select.replace(/%/,addition);
	if (Elm.is("textarea")) error_text = def_error_textarea.replace(/%/,addition);
	if (Elm.attr("type") == "text") error_text = (InArray(Elm, email))? def_email_info_tooltip.replace(/%/,addition) : def_error_empty.replace(/%/,addition);
	
	jQuery("p label[for="+Elm.attr("id")+"]").addClass("ibm-error");
	Elm.after(error_icon_start + error_text + error_icon_end);
	if (Elm.is("textarea")) Elm.next("a.ibm-error-link").css("vertical-align","top");
	Elm.next("a.ibm-error-link").bind("mouseenter",{tooltip: error_text}, function(e) { TooltipShow(e.data.tooltip, getX(this), getY(this)) });
	Elm.next("a.ibm-error-link").bind("mouseleave", function(e) { jQuery("#tooltipContent").hide() });
}

function showErrorsTypeB(Elm) {
	labelTEXT = jQuery("fieldset:has(input#"+Elm.attr("id")+")").prev("p").text();
	addition = "'" + labelTEXT.slice(0,labelTEXT.search(/\:\*/)) + "'";
	if (Elm.attr("type") == "radio") error_text = def_error_radio.replace(/%/,addition);
	if (Elm.attr("type") == "checkbox") error_text = def_error_checkbox.replace(/%/,addition);
	
	jQuery("fieldset:has(input#"+Elm.attr("id")+")").prev("p").addClass("ibm-error");
	jQuery("fieldset:has(input#"+Elm.attr("id")+")").addClass("ibm-error");		
	jQuery("fieldset:has(input#"+Elm.attr("id")+")").prev("p").append(error_icon_start + error_text + error_icon_end);
	jQuery("fieldset:has(input#"+Elm.attr("id")+")").prev("p").children("a.ibm-error-link").bind("mouseenter",{tooltip: error_text}, function(e) { TooltipShow(e.data.tooltip, getX(this) , getY(this)) });
	jQuery("fieldset:has(input#"+Elm.attr("id")+")").prev("p").children("a.ibm-error-link").bind("mouseleave", function(e) { jQuery("#tooltipContent").hide() });
}

function showErrorsTypeC(Elm) {
	labelTEXT = jQuery("label[for="+Elm.attr("id")+"]").text();
	addition = "'" + labelTEXT.slice(0,labelTEXT.search(/\:\*/)) + "'";
	error_text = def_email_error_tooltip.replace(/%/,addition);
	error_alt = def_email_error_alt.replace(/%/,addition);
	
	jQuery("p label[for="+Elm.attr("id")+"]").addClass("ibm-error");
	Elm.after(error_icon_start + error_alt + error_icon_end);
	Elm.next("a.ibm-error-link").bind("mouseenter",{tooltip: error_text}, function(e) { TooltipShow(e.data.tooltip, getX(this), getY(this)) });
	Elm.next("a.ibm-error-link").bind("mouseleave", function(e) { jQuery("#tooltipContent").hide() });
}

function hideErrorsTypeA(Elm) {
	jQuery("p label[for="+Elm.attr("id")+"]").removeClass("ibm-error");
	jQuery("input#"+Elm.attr("id")+"~a.ibm-error-link").remove();
	jQuery("textarea#"+Elm.attr("id")+"~a.ibm-error-link").remove();
	jQuery("select#"+Elm.attr("id")+"~a.ibm-error-link").remove();
}

function hideErrorsTypeB(Elm) {
	jQuery("fieldset:has(input#"+Elm.attr("id")+")").prev("p").removeClass("ibm-error");
	jQuery("fieldset:has(input#"+Elm.attr("id")+")").removeClass("ibm-error");		
	jQuery("fieldset:has(input#"+Elm.attr("id")+")").prev("p").children("a.ibm-error-link").remove();
}


function ShowHideInfoMssError() {(req_error.length > 0 || eml_error.length > 0)? jQuery("#InfoMssError").show() : jQuery("#InfoMssError").hide() }

function FormReset(form) {
	jQuery("*.ibm-error").removeClass("ibm-error");
	jQuery("a.ibm-error-link").remove();
	jQuery("a.ibm-information-link").show();
	req_error.length = 0; // cleaning array
	eml_error.length = 0; // cleaning array
	ShowHideInfoMssError()
	if (BrowserDetect.browser == "Explorer") {
		for (s in select_width_fix) {
			optReset = jQuery("#"+select_width_fix[s]+" option:eq(0)");
			optReset.val("");
			optReset.html("<NOBR>"+def_sel_one+"<\/NOBR>");
			}
	}
	if (jQuery(".ibm-form-state").length != 0) {
		ST_list.empty();
		ST_list.append("<option value=\"\" selected=\"selected\">" + def_sel_one + "<\/option>");
		document.getElementById(st_id).disabled = true;
	}
	document.location.hash = "";
}

function TooltipStart () {
	jQuery("#ibm-content-body").append("<div id=\"tooltipContent\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td colspan=\"3\" class=\"ibm-tt-head\"><\/td><\/tr><tr valign=\"top\"><td class=\"left\"><\/td><td class=\"mainArea\"><div id=\"mainText\">&nbsp;<\/div><\/td><td class=\"right\"><\/td><\/tr><tr><td colspan=\"3\" class=\"ibm-tt-footer\"><\/td><\/tr><\/table><\/div>");
	
	jQuery("#tooltipContent").css({
		"position" : "absolute",
		"display" : "none",
		"top" : "100px",
		"left" : "300px",
		"z-index" : "2000",
		"width" : "290px",
		"margin" : "0 0 0 1em",
		"padding" : "0 10px 0 10px",
		"border" : "none"
		});
	
	jQuery("#tooltipContent table").css({
		"padding" : "0px",
		"margin" : "0px",
		"border" : "0px"
		});
	jQuery("#tooltipContent .ibm-tt-head").css({
		"background" : "transparent url(//www.ibm.com/i/v16/tooltip/tooltip_sprite_tb.png) no-repeat 15px 0px",
		"height" : "17px"
		});
	jQuery("#tooltipContent .left").css({
		"width" : "35px",
		"min-height" : "30px",
		"background" : "transparent url(//www.ibm.com/i/v16/tooltip/tooltip_sprite_sides.png) no-repeat 0px 0px"
		});
	jQuery("#tooltipContent .right").css({
		"width" : "35px",
		"min-height" : "30px",
		"background" : "transparent url(//www.ibm.com/i/v16/tooltip/tooltip_sprite_sides.png) no-repeat -36px -35px"
		});
	jQuery("#tooltipContent .mainArea").css({
		"width" : "200px",
		"background-color" : "#F4F7F9",
		"min-height" : "35px",
		"margin-top" : "-5px"
		});
	jQuery("#tooltipContent #mainText").css({
		"font-size" : "0.6em",
		"font-family" : "Arial,Sans Serif",
		"text-align" : "left"
		});
	jQuery("#tooltipContent .ibm-tt-footer").css({
		"background" : "transparent url(//www.ibm.com/i/v16/tooltip/tooltip_sprite_tb.png) no-repeat 15px -18px",
		"height" : "30px"
		});

	if (BrowserDetect.browser == "Explorer") {
		jQuery("#tooltipContent .ibm-tt-head").css({ "background" : "transparent url(//www.ibm.com/i/v16/tooltip/tooltip_sprite_tb.gif) no-repeat 15px 0px" });
		jQuery("#tooltipContent .left").css({
			"background-image" : "url(//www.ibm.com/i/v16/tooltip/tooltip_sprite_sides.gif)",
			"background-position" : "0px 0px",
			"height" : "35px"
			});
		jQuery("#tooltipContent .right").css({
			"background-image" : "url(//www.ibm.com/i/v16/tooltip/tooltip_sprite_sides.gif)",
			"background-position" : "-36px -35px"
			});
		jQuery("#tooltipContent .mainArea").css({ "margin-top" : "-2px" });
		jQuery("#tooltipContent .ibm-tt-footer").css({ "background-image" : "url(//www.ibm.com/i/v16/tooltip/tooltip_sprite_tb.gif)" });
	}
}

function getY(A) {
	icon = (jQuery(A).is("a"))? true : false;
	var B = 0;
	if( A.offsetParent ){
		while (A.offsetParent){ B += A.offsetTop; A = A.offsetParent }
	} else{ if( A.y ){ B += A.y }}
	 if (icon) {if (BrowserDetect.browser == "Explorer") { B -= correctY_ie } else { B -= correctY_def }}
	return B;
}

function getX(B) {
	icon = (jQuery(B).is("a"))? true : false;
	var A = 0;
	if( B.offsetParent ){
		while (B.offsetParent){ A += B.offsetLeft; B = B.offsetParent}
	}
	else{ if( B.x ){ A += B.x }}
	if (icon) A -= correctX;
	return A;
}

function TooltipShow(tooltipText,Xposition,Yposition) {
	jQuery("#tooltipContent").css({
		"top" : Yposition,
		"left" : Xposition
	});
	jQuery("#tooltipContent #mainText").empty();
	jQuery("#tooltipContent #mainText").css("min-height","35px");
	jQuery("#tooltipContent #mainText").append(tooltipText);
	jQuery("#tooltipContent #mainText ul").css({ "padding-left" : "0px","margin-left" : "0px" });
	jQuery("#tooltipContent #mainText ul li").css({
		"list-style-type" : "none",
		"background" : "url(//www.ibm.com/i/v16/bullets/sprites.gif) no-repeat 0px 0px",
		"padding-left" : "10px"
	});
	if (BrowserDetect.browser == "Explorer") jQuery("#tooltipContent #mainText ul li").css("background-position","0px 5px")
	jQuery("#tooltipContent").fadeIn("slow");
}

function CountriesSelect() {
	var selObj = document.getElementById(st_id);
	var CNobj = document.getElementById(cc_id)
	
	var selectedCC = CNobj.options[CNobj.selectedIndex].value;
	
	var xmlDoc=null;
	var ides = false;
	
	selObj.disabled = true;
	
	if (window.ActiveXObject) {// code for IE
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	}
	else if (document.implementation.createDocument) {// code for Mozilla, Firefox, Opera, etc.
		xmlDoc = document.implementation.createDocument("","",null);
	}
	else { alert('Your browser cannot handle this script');
	}

	if (xmlDoc != null) {
		xmlDoc.async = false;
		xmlFile = "/software/uk/forms/countries/" + selectedCC + "-county.xml";
		xmlDoc.load(xmlFile);
		var regions = xmlDoc.getElementsByTagName("region");
		var language = xmlDoc.getElementsByTagName("language");
	}

	ST_list.empty();
	ST_list.append("<option value=\"\" selected=\"selected\">" + def_sel_one + "<\/option>");
	
	for (var n = 0; n < regions.length; n++) {
		
		fulltext = regions[n].childNodes[0].nodeValue;
		separ = fulltext.search("|");		
		if (separ != -1) {
			reg_name = fulltext.split("|");
			ST_list.append("<option title=\""+reg_name[1]+"\" value=\""+reg_name[0]+"\">"+reg_name[0]+"<\/option>");
			ides = true;
		}
		else {
			ST_list.append("<option value=\""+fulltext+"\">"+fulltext+"<\/option>");
		}
	}
	
	if (ides) { // for all options, which are apper title, add event
		
		jQuery("#"+st_id+" option[title]").each(function(){
			if (jQuery(this).attr("title") != "undefined") {
				jQuery(this).bind("mouseover",{obj: jQuery(this), titleName: jQuery(this).attr("title")},function(e){
					jQuery(e.data.obj).removeAttr("title");
					
					jQuery("div#opTitle").css("display","block");
					jQuery("div#opTitle").empty();
					if (language != "") {
						lang = language[0].childNodes[0].nodeValue;
						multilang = false;
						spl = lang.search("|");
						if (spl != -1) {
							multilang = true;
							langroup = lang.split("|");
						}
						
						if (lang == "ar" || lang == "fa" || lang == "bn") jQuery("div#opTitle").css("font-size","16px");
						else if (lang == "hy") jQuery("div#opTitle").css("font-size","14px");
						else jQuery("div#opTitle").css("font-size","12px");
						
						if (multilang) {
							tlang = e.data.titleName.split("^");
							for (a = 0; a < tlang.length; a++) {
								if (tlang[a] != "") {
									jQuery("div#opTitle").append("<span xml:lang=\""+langroup[a]+"\" lang=\""+langroup[a]+"\">"+tlang[a]+"<\/span>");
									if (a < tlang.length) jQuery("div#opTitle").append("<br \/>");
								}
							}
						}
						else {
							jQuery("div#opTitle").append("<span xml:lang=\""+lang+"\" lang=\""+lang+"\">"+e.data.titleName+"<\/span>");
						}
					}
					else {
						jQuery("div#opTitle").append(e.data.titleName);
					}
					
					optPos = jQuery(e.data.obj).offset();
						
					headHeight = jQuery("div#ibm-masthead").height() + 10;
					content = jQuery("div#ibm-content-main").offset();
					wTitle = document.getElementById("opTitle").offsetWidth;
					
					topPos = optPos.top - headHeight;
					leftPos = optPos.left - content.left - wTitle - 2;
					
					jQuery("div#opTitle").css("top",topPos+"px");
					jQuery("div#opTitle").css("left",leftPos+"px");
					
				});
				jQuery(this).bind("mouseout",function(){
					jQuery("div#opTitle").css("display","none");
				});
			}
			else { jQuery(this).attr("title",""); }
			if (BrowserDetect.browser != "Explorer") jQuery(this).removeAttr("title"); // removed title
			
			// for IE7
			
			if (jQuery(this).attr("title")) {
				titletext = jQuery(this).attr("title");
				if (titletext.search("^") != -1) {
					part = titletext.split("^");
					titletext = "";
					for (m = 0; m < part.length; m ++) {
						if (part[m] != "") {
							if (m != 0 && m < part.length) titletext += " - ";
							titletext += part[m];
						}
					jQuery(this).attr("title",titletext);	
					}
				}
			}
			
		});
	}
	selObj.disabled = (selObj.length > 1)? false : true;
}

/******************************** IE fixed behavior *************************************************/

function dropdown_menu_hack(el) {
	if(el.runtimeStyle.behavior.toLowerCase()=="none"){return;}
	el.runtimeStyle.behavior="none";

	var ie5 = (document.namespaces==null);
	el.ondblclick = function(e) {
		window.event.returnValue=false;
		return false;
	}
	
	if(window.createPopup==null) {
		
		var fid = "dropdown_menu_hack_" + Date.parse(new Date());
	
		window.createPopup = function() {
			if(window.createPopup.frameWindow==null) {
				el.insertAdjacentHTML("AfterEnd","<iframe   id='"+fid+"' name='"+fid+"' src='about:blank'  frameborder='1' scrolling='no'></></iframe>");
				var f = document.frames[fid];
				f.document.open();
				f.document.write("<html><body></body></html>");
				f.document.close();
				f.fid = fid; 
				

				var fwin = document.getElementById(fid);
				fwin.style.cssText="position:absolute;top:0;left:0;display:none;z-index:99999;";
			
				
				f.show = function(px,py,pw,ph,baseElement) {
					py = py + baseElement.getBoundingClientRect().top + Math.max( document.body.scrollTop, document.documentElement.scrollTop) ;
					px = px + baseElement.getBoundingClientRect().left + Math.max( document.body.scrollLeft, document.documentElement.scrollLeft) ;
					fwin.style.width = pw + "px";
					fwin.style.height = ph + "px";						
					fwin.style.posLeft =px ;
					fwin.style.posTop = py ;		
					fwin.style.display="block";						
				}

				
				f_hide = function(e) {
					if(window.event && window.event.srcElement	&& window.event.srcElement.tagName && window.event.srcElement.tagName.toLowerCase()=="select"){return true;}
					fwin.style.display="none";
				} 
				f.hide = f_hide;
				document.attachEvent("onclick",f_hide);		
				document.attachEvent("onkeydown",f_hide);		
					
			}
			return f;
		}
	}

	function showMenu() {
		
		function selectMenu(obj) {
			var o = document.createElement("option");
			o.value = CoutriesCodes[obj.selectedIndex];
			o.innerHTML = obj.innerHTML;
			while(el.options.length > 0){ el.options[0].removeNode(true); }
			el.appendChild(o);
			el.title = o.innerHTML.replace(/<\/*nobr>/gi,'');
			el.contentIndex = obj.selectedIndex;
			if (InArray(CC_list,select_width_fix)) CountriesSelect();
			EventCheck(jQuery("#"+el.id),"D");
			el.menu.hide(o.value);
		}				
		
		el.menu.show(0 , el.offsetHeight , 10,  10, el); 
		var mb = el.menu.document.body;
		
		mb.style.cssText ="border:solid 1px black;margin:0;padding:0;overflow-y:auto;overflow-x:auto;background:white;text-aligbn:center;font-family:Arial,sans-serif;font-size:12px;";
		var t = el.contentHTML;
		t = t.replace(/<select/gi,'<ul');
		t = t.replace(/<option/gi,'<li');
		t = t.replace(/<\/option/gi,'</li');
		t = t.replace(/<\/select/gi,'</ul');
		mb.innerHTML = t;	
		
		el.select = mb.all.tags("ul")[0];
		el.select.style.cssText="list-style:none;margin:0;padding:0;";
		mb.options = el.select.getElementsByTagName("li");
		
		for(var i=0;i<mb.options.length;i++) {
			mb.options[i].selectedIndex = i;
			mb.options[i].style.cssText = "list-style:none;margin:0;padding:1px 2px;width/**/:100%;cursor:hand;cursor:pointer;white-space:nowrap;"
			mb.options[i].title =mb.options[i].innerHTML;
			mb.options[i].innerHTML ="<nobr>" + mb.options[i].innerHTML + "</nobr>";
			mb.options[i].onmouseover = function() {
				if( mb.options.selected ){mb.options.selected.style.background="white";mb.options.selected.style.color="black";}
				mb.options.selected = this;
				this.style.background="#333366";this.style.color="white";
			}
			mb.options[i].onmouseout = function(){this.style.background="white";this.style.color="black";}
			mb.options[i].onmousedown = function(){ selectMenu(this); }
			mb.options[i].onkeydown = function(){ selectMenu(this);	}

			if(i == el.contentIndex) {
				mb.options[i].style.background="#333366";
				mb.options[i].style.color="white";	
				mb.options.selected = mb.options[i];
			}
		}
		
		var mw = Math.max(   ( el.select.offsetWidth + 22 ), el.offsetWidth + 22  );
		mw = Math.max(  mw, ( mb.scrollWidth+22) );
		var mh =  mb.options.length * 15  + 8 ; 
			 
		var mx = (ie5)?-3:0;
		var my = el.offsetHeight -2;
		var docH =   document.documentElement.offsetHeight ;
		var bottomH = docH  - el.getBoundingClientRect().bottom ; 

		mh = Math.min(mh, Math.max(( docH - el.getBoundingClientRect().top - 50),100)		);
		
		if(( bottomH < mh) ) {
			mh = Math.max( (bottomH - 12),10);
			if( mh <100 ) my = -100 ;
			mh = Math.max(mh,100);			
		}
		
		self.focus();
		
		el.menu.show( mx , my ,  mw, mh , el); 
		sync=null;
		if(mb.options.selected) mb.scrollTop = mb.options.selected.offsetTop;
		
		window.onresize = function(){el.menu.hide()};		
	}

	function switchMenu() {
		if(event.keyCode) {
			if(event.keyCode==40){ el.contentIndex++ ;}
			else if(event.keyCode==38){ el.contentIndex--; }
		}
		else if(event.wheelDelta ) {
			if (event.wheelDelta >= 120)
			el.contentIndex++ ;
			else if (event.wheelDelta <= -120)
			el.contentIndex-- ;
		}
		else {return true;}

		if( el.contentIndex > (el.contentOptions.length - 1) ) { el.contentIndex = 0 }
		else if (el.contentIndex < 0){el.contentIndex = el.contentOptions.length - 1 ;}

		var o = document.createElement("option");
		o.value = el.contentOptions[el.contentIndex].value;
		o.innerHTML = el.contentOptions[el.contentIndex].text;
		while(el.options.length > 0){ el.options[0].removeNode(true) }
		el.appendChild(o);
		el.title =  o.innerHTML;
		if (InArray(CC_list,select_width_fix)) CountriesSelect();
		EventCheck(jQuery("#"+el.id),"D");
	}
	
	if(dropdown_menu_hack.menu == null) {
		dropdown_menu_hack.menu =  window.createPopup();
		document.attachEvent("onkeydown",dropdown_menu_hack.menu.hide);
	}
	
	el.menu = dropdown_menu_hack.menu ;
	el.contentOptions = new Array();
	el.contentIndex = el.selectedIndex;
	el.contentHTML = el.outerHTML;

	for(var i=0; i<el.options.length; i++) {	
		el.contentOptions [el.contentOptions.length] = 
		{
			"value": el.options[i].value,
			"text": el.options[i].innerHTML
		}

		if(!el.options[i].selected){ el.options[i].removeNode(true); i-- }
	}
	
	el.onkeydown = switchMenu;
	el.onclick = showMenu;
	el.onmousewheel= switchMenu;
	}