﻿/* attempt to fix IE6 background flickering because of bad cache operation */
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {/* not IE6 or no need to fix it */}

function SetClass(tag, className)
{
    if (tag.className != className)
        tag.className = className;
}

function showContent(obj) {
	if (obj.parentNode.hideTimer) clearTimeout(obj.parentNode.hideTimer);
	if (obj.parentNode.shown) obj.parentNode.shown.className = '';
	obj.className = 'show';
	obj.parentNode.shown = obj;
}

function sheduleHideContent(obj) {
	var hide = function() { obj.className = ''; }
	obj.parentNode.hideTimer = setTimeout(hide, 500);
}

function fnDoSave () 
{	
	var arFieldsNamesArray = new Array ("Details", "FirstName", "LastName", "Company", "Title", "Country", "Email", "Area", "ContactPhone", "reqInfoFile", "SecurityCode") ;
	var arFieldsRealNamesArray = new Array ("Please type in your inquiry or comments", "First Name", "Last Name", "Company", "Title", "Country", "Email Address", "Area Code", "Contact Phone", "Attach File", "Security Code") ;

	var arIsObligatory = new Array(1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1) ;

	for (i = 0 ; i < arFieldsNamesArray.length ; i++) 
	{
		var fName = arFieldsNamesArray[i];
		var fRealName = arFieldsRealNamesArray[i];
		
		if(arIsObligatory[i] == 1)
		{
			if (IsEmpty(fName, fRealName, true))
			{
				return false;
			}
		}
		
		if(fName == "Details")
		{
			if (fieldLengthIsMore(fName, fRealName, 2000))
			{
				return false;
			}
		}		
	}
}

function IsEmpty(_field, _fieldRealName, _IsObligatory)
{
	err = "Field '" + _fieldRealName + "' is mandatory!";
	field = document.getElementById("ctl00_MainContent_txt"+_field);
	
	if ( (field.value.length == 0) )
	{
		if (_IsObligatory)
		{
			field.focus();
			alert(err);
			return true;
		}		
	}
	else
	{
		return false;
	}
}

function fieldLengthIsMore(_field, _fieldRealName, symbolLimit)
{
	field = document.getElementById("ctl00_MainContent_txt" + _field);
	err = "The field '" + _fieldRealName + "' cannot contain more than " + symbolLimit + " symbols!";
	
	// server treats line break as 2 chars (\r\n), so scripts emulates the same logic by length measurement
	var test = field.value;
	if (test.match(/[^\r]\n/)) test = test.split("\n").join("\r\n"); // FF, Safari, any Unix/MaxOS X browser
	else if (test.match(/\r[^\n]/)) test = test.split("\r").join("\r\n"); // legacy MacOS 9 and lower

	if (test.length > symbolLimit)
	{
		alert(err);
		field.focus();
		return true;
	}
	else return false;
}

function writeML(part1, part2, text, cssClass) {
	if ( text == "") {
		text= part1 + "@" + part2;
	}
	if (cssClass != "") {
		cssClass = "class=\"" + cssClass + "\"";
	}
	document.write(" <a href=\"mailto:" + part1 + "@" + part2 + "\""+ cssClass +">" + text + "</a>");
}

function checkSearchForm(form) {
	form.keyword.value = form.keyword.value.replace(/^\s+|\s+$/, '');
	if (form.keyword.value == '') {
		form.keyword.focus();
		return false;
	}
}

(function s() {
		var mainStyle;
		var addStyle = 
		   document.styleSheets && (mainStyle = document.styleSheets[document.styleSheets.length - 1])
		   ? mainStyle.addRule
			  ? function(sel, styl) { mainStyle.addRule(sel, styl) }
			  : function(sel, styl) { mainStyle.insertRule (sel + ' {' + styl + '}', mainStyle.cssRules.length) }
		   : function(sel, styl) {
			   var s = document.createElement('style');
			   s.innerHTML = sel + ' {' + styl + '}';
			   document.getElementsByTagName('head')[0].appendChild(s);
			 }

		addStyle('#body .addcontent .browse', 'display: block');
		addStyle('#body .addcontent .noscript', 'display: none');
		addStyle('#footer ul li span', 'display: block');
		addStyle('#footer ul ul', 'display: none; padding: 0; position: absolute; left: 0; bottom: 20px; margin: 0; border: 1px solid #adadad; background-color: #fff; z-index: 250;');
		addStyle('#footer ul ul li', 'float: none');
	})();