// Flash and CSS init (c) Agents.se - v3.0

//var flashver = deconcept.SWFObjectUtil.getPlayerVersion()['major'];

// CSS Browser Selector   v0.2.3
// Documentation:         http://rafael.adm.br/css_browser_selector
var css_browser_selector = function() {
	var 
		ua = navigator.userAgent.toLowerCase();
		is = function(t){ return ua.indexOf(t) != -1; },
		h = document.getElementsByTagName('html')[0],
		b = (!(/opera|webtv/i.test(ua)) && /msie (\d)/.test(ua)) ? ((is('mac') ? 'ieMac ' : '') + 'ie ie' + RegExp.$1)
			: is('gecko/') ? 'gecko' : is('opera') ? 'opera' : is('konqueror') ? 'konqueror' : is('applewebkit/') ? 'webkit safari' : is('mozilla/') ? 'gecko' : '',
		os = (is('x11') || is('linux')) ? ' linux' : is('mac') ? ' mac' : is('win') ? ' win' : '';
	var c = b+os+' js';
	h.className += h.className?' '+c:c;
}();



// No spam e-mail address
function noSpam(a,b,c) {
	document.write('<a href="mai'+'lto:'+c+'@'+b+'.'+a+'">'+c+'@'+b+'.'+a+'</a>');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
		  window.open(theURL,winName,features);
}
		  
/*
Create the new window
*/
function openInNewWindow() {
	// Change "_blank" to something like "newWindow" to load all links in the same new window
    var newWindow = window.open(this.getAttribute('href'), '_blank');
    newWindow.focus();
    return false;
}


// form input prefill clear on focus, and reset on blur (if empty)
function prefillClear(field) {
	if (field.defaultValue==field.value) {field.value = '';}
	else if (field.value == '') {field.value = field.defaultValue;}
}

function my_prefillClear(field, initval) {
	if (field.value==initval) {field.value = '';}
	else if (field.value == '') {field.value = initval;}
}



function login_check()
{
	if ( (document.getElementById('login_username').value == "Username") || (document.getElementById('login_password').value == "Password") )
	{
		alert("You must fill in your username and password in order to login.");
		return false;
	}

	return true;
}
	
	
	
function check_search()
{
							  
	if ( ((document.getElementById('keyword').value=="")||(document.getElementById('keyword').value=="Keyword")) && ((document.getElementById('style').value=="")||(document.getElementById('style').value=="Style No")) && (document.getElementById('biztype').value=="") )
	{
		alert("You must type at least one search criteria");
		return false;
	}
	
	if (document.getElementById('keyword').value=="Keyword")
		document.getElementById('keyword').value = "";
		
	if (document.getElementById('style').value=="Style No")
		document.getElementById('style').value = "";
		
	document.getElementById('quickSearchForm').submit();
}

	
function checkEmail(elem)
{
   var field = document.getElementById(elem);
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
   if (field.value.length ==0)
		return false;

   if(field.value.match(emailExp))
		   return true;
   else 
		   return false;
   
}

function check_cancelform()
{
	clear_errors(1);
	
	if (document.getElementById('name').value=="")
	{
		show_error('name');
		alert("Please fill in your Name.");
		return false;
	}

	if (document.getElementById('order_code').value=="")
	{
		show_error('order_code');
		alert("Please type your Order Code.");
		return false;
	}
	
	if (document.getElementById('email').value=="")
	{
		show_error('email');
		alert("Please fill in your E-mail.");
		return false;
	}
	if (!checkEmail('email'))
	{
		show_error('email');
		alert ("Your email address is not valid.");
		return false;
	}
	
	if (document.getElementById('reason').value=="")
	{
		show_error('reason');
		alert("Please fill in The reason of your order cancellation.");
		return false;
	}
	
	document.getElementById('cancel_order').submit();
}

function validate_register_form(form_id)
{
	clear_errors(0);
	
	if (document.getElementById('your_surname').value=="")
	{
		show_error('your_surname');
		alert("Please fill in your Last Name.");
		return false;
	}	
	if (document.getElementById('your_name').value=="")
	{
		show_error('your_name');
		alert("Please fill in your First Name.");
		return false;
	}
	
	if (document.getElementById('your_position').value=="")
	{
		show_error('your_position');
		alert("Please fill in your Position.");
		return false;
	}
	if (document.getElementById('store_name').value=="")
	{
		show_error('store_name');
		alert("Please fill in your Store/Company name.");
		return false;
	}
	if (document.getElementById('address').value=="")
	{
		show_error('address');
		alert("Please fill in your Address.");
		return false;
	}
	if (document.getElementById('city').value=="")
	{
		show_error('city');
		alert("Please fill in the City field.");
		return false;
	}
	if (document.getElementById('state').value=="")
	{
		show_error('state');
		alert("Please fill in the State field.");
		return false;
	}
	if (document.getElementById('zipcode').value=="")
	{
		show_error('zipcode');
		alert("Please fill in the Zipcode field.");
		return false;
	}
	if (document.getElementById('country').value=="")
	{
		show_error('country');
		alert("Please fill in the country field.");
		return false;
	}
	
	
	if (document.getElementById('email').value=="")
	{
		show_error('email');
		alert("Please fill in your E-mail.");
		return false;
	}
	if (!checkEmail('email'))
	{
		show_error('email');
		alert ("Your email address is not valid.");
		return false;
	}
	
	//type_of_business (select)
	var selbox = document.getElementById('type_of_business');
	if (selbox.options[selbox.selectedIndex].value=="")
	{
		alert("Please select your 'Type of store/business'.");
		show_error('type_of_business');
		return false;
	}
	
	if ( (document.getElementById('amount_of_stores').value=="") || (isNaN(document.getElementById('amount_of_stores').value)) )
	{
		show_error('amount_of_stores');
		alert("Please fill a number in the 'How many stores do you have?' field.");
		return false;
	}
	if (document.getElementById('company_how_old').value=="")
	{
		show_error('company_how_old');
		alert("Please fill in the 'How long is your company in business?' field.");
		return false;
	}
	
	if (document.getElementById('username').value=="")
	{
		show_error('username');
		alert("Please fill in your Username.");
		return false;
	}
	if (document.getElementById('password').value=="")
	{
		show_error('password');
		alert("Please fill in your Password.");
		return false;
	}
	/*if ( document.getElementById("password").value != document.getElementById("temp_password").value )
	{
		show_error('password');
		show_error('temp_password');
		alert("Passwords do not match. Please type them again.");
		return false;
	}*/
	if (document.getElementById('securitycode').value=="")
	{
		show_error('securitycode');
		alert("Please type the security code.");
		return false;
	}
	
	document.getElementById(form_id).submit();
}
	


function show_error(id)
{
	document.getElementById(id).style.border="solid 1px #8e006e";
}

function clear_errors(which)
{
	for (i=0;i<document.forms[which].elements.length;i++)
	{
		//if (document.forms[which].elements[i].type == "text")
			document.forms[which].elements[i].style.border="none";
	}
}


function check_order_status(form_id)
{
	if ( (document.getElementById('order_code').value=="") || (isNaN(document.getElementById('order_code').value)) )
	{
		show_error('order_code');
		alert("You have to insert a valid product code.");
		return false;
	}
	document.getElementById(form_id).submit();
}

function validate_profile_form(form_id)
{
	clear_errors(1);
	
	if (document.getElementById('your_name').value=="")
	{
		show_error('your_name');
		alert("Please fill in your Name.");
		return false;
	}
	if (document.getElementById('your_surname').value=="")
	{
		show_error('your_surname');
		alert("Please fill in your Last name.");
		return false;
	}
	if (document.getElementById('your_position').value=="")
	{
		show_error('your_position');
		alert("Please fill in your Position.");
		return false;
	}
	if (document.getElementById('store_name').value=="")
	{
		show_error('store_name');
		alert("Please fill in your Store/Company name.");
		return false;
	}
	if (document.getElementById('address').value=="")
	{
		show_error('address');
		alert("Please fill in your Address.");
		return false;
	}
	if (document.getElementById('city').value=="")
	{
		show_error('city');
		alert("Please fill in the City field.");
		return false;
	}
	if (document.getElementById('state').value=="")
	{
		show_error('state');
		alert("Please fill in the State field.");
		return false;
	}
	if (document.getElementById('zipcode').value=="")
	{
		show_error('zipcode');
		alert("Please fill in the Zipcode field.");
		return false;
	}
	if (document.getElementById('country').value=="")
	{
		show_error('country');
		alert("Please fill in the country field.");
		return false;
	}
	
	
	if (document.getElementById('email').value=="")
	{
		show_error('email');
		alert("Please fill in your E-mail.");
		return false;
	}
	if (!checkEmail('email'))
	{
		show_error('email');
		alert ("Your email address is not valid.");
		return false;
	}
	
	//type_of_business (select)
	
	if ( (document.getElementById('amount_of_stores').value=="") || (isNaN(document.getElementById('amount_of_stores').value)) )
	{
		show_error('amount_of_stores');
		alert("Please fill a number in the 'How many stores do you have?' field.");
		return false;
	}
	if (document.getElementById('company_how_old').value=="")
	{
		show_error('company_how_old');
		alert("Please fill in the 'How long is your company in business?' field.");
		return false;
	}
	
	/*if (document.getElementById('username').value=="")
	{
		show_error('username');
		alert("Please fill in your Username.");
		return false;
	}*/
	
	if (document.getElementById('securitycode').value=="")
	{
		show_error('securitycode');
		alert("Please fill the security code.");
		return false;
	}
	
	document.getElementById(form_id).submit();
}
	
	
function find_key_pressed(e)
{
	var numCharCode;
   
   // get event if not passed
   if (!e) var e = window.event;

   // get character code of key pressed
   if (e.keyCode) 
   		numCharCode = e.keyCode;
   else if (e.which) 
   		numCharCode = e.which;
   
   if ( numCharCode == 13 )
   	check_search();
}


function check_form(formid, whichform, mandatory_fields, numericfields, emailfield)
{
	clear_errors(whichform);
	
	//check mandatory fields
	var man = mandatory_fields.split(",");
	for (i=0;i<man.length;i++)
	{
		if (document.getElementById(man[i]).value == "")
		{
			show_error(man[i]);
			alert ("You must fill all the mandatory fields (*)");
			return false;
		}
	}
	
	if (emailfield!="")
	{
		var emailid = 'email';
		if (formid == 'newsletform')
			emailid = 'newsemail';
	
		if (!checkEmail(emailid))
		{
			show_error(emailid);
			alert ("Your email address is not valid.");
			return false;
		}
	}
	
	//check numeric fields
	if (numericfields != "")
	{
		var numeric = numericfields.split(",");
		for (i=0;i<numeric.length;i++)
		{
			document.getElementById(numeric[i]).value = document.getElementById(numeric[i]).value.replace(/,/,".");
			
			if (isNaN (document.getElementById(numeric[i]).value))
			{
				show_error(numeric[i]);
				alert (numeric[i]+": should be a number. Plase check and try again!");
				return false;
			}
		}
	}
	
	document.getElementById(formid).submit();
}



/* ---------------- available fixtures & tradeshows --------------- */

function show_paragraph(id, total)
{
	$(".slider").css("display", "none");
	$("#preview").css("display", "block");
	
	if (document.getElementById('par'+id).style.display == "block")
	{
		document.getElementById('par'+id).style.display = "none";
		document.getElementById('ptitle'+id).className = "";
	}
	else
	{
		for (i=0;i<total;i++)
		{
			document.getElementById('par'+i).style.display = "none";
			document.getElementById('ptitle'+i).className = "";
		}
		
		document.getElementById('par'+id).style.display = "block";
		document.getElementById('ptitle'+id).className = "activeList";
		document.getElementById('preview').src = arr_images[id];
	}
}
