
/*		CODED BY AM.E.ER		*/

$(document).ready(function(){
	$('.ameer').fadeTo('fast', 0.6); $('.ameer').mouseover(function(){ $('.ameer').fadeTo(200, 1.0);}); $('.ameer').mouseout(function(){ $('.ameer').fadeTo(1200, 0.6);});
});

function initMenus(){	
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){ $('#showme').show(); });
	$('ul.menu li a').click(
		function(){
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
			if($('#' + parent).hasClass('noaccordion')){
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')){ $('#' + parent + ' ul:visible').slideUp('normal'); }
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function(){initMenus();});

function validateFBForm(){
	var fname=document.getElementById("fname").value; var ph=document.getElementById("ph").value;
	var email=document.getElementById("email").value; var address=document.getElementById("address").value;
	var country=document.getElementById("country").value; var message=document.getElementById("message").value;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var tfoption = true;
	if(fname.length==0){$('#__feedback_error_fname').html('Please enter your full name').fadeIn('fast'); tfoption=false;}
	else{$('#__feedback_error_fname').fadeOut('slow');}
	if(ph.length==0){$('#__feedback_error_ph').html('Please enter your phone number').fadeIn('fast'); tfoption=false;}
	else{$('#__feedback_error_ph').fadeOut('slow');}
	if(email.length==0){$('#__feedback_error_email').html('Please enter your email address').fadeIn('fast'); tfoption=false;}
	else if(reg.test(email)==false){$('#__feedback_error_email').html('Please enter your valid email address');$('#__feedback_error_email').fadeIn('fast'); tfoption=false;}
	else{$('#__feedback_error_email').fadeOut('slow');}
	if(address.length==0){$('#__feedback_error_address').html('Please enter your mailing address').fadeIn('fast'); tfoption=false;}
	else if(address.length<5){$('#__feedback_error_address').html('Your mailing address is too short').fadeIn('fast'); tfoption=false;}
	else{$('#__feedback_error_address').fadeOut('slow');}
	if(country.length==''){$('#__feedback_error_country').html('Please select your country').fadeIn('fast'); tfoption=false;}
	else{$('#__feedback_error_country').fadeOut('slow');}
	if(message.length==0){$('#__feedback_error_message').html('Please enter your message').fadeIn('fast'); tfoption=false;}
	else if(message.length<5){$('#__feedback_error_message').html('Your message is too short');$('#__feedback_error_message').fadeIn('fast'); tfoption=false;}
	else{$('#__feedback_error_message').fadeOut('slow');}
	if (tfoption==false){ return false; } else { sendcontacts(); return false; }
}

function hideerrorFBForm(){
	$('#__feedback_error_fname').fadeOut('slow'); $('#__feedback_error_ph').fadeOut('slow');
	$('#__feedback_error_email').fadeOut('slow'); $('#__feedback_error_address').fadeOut('slow');
	$('#__feedback_error_country').fadeOut('slow'); $('#__feedback_error_message').fadeOut('slow'); return true;
}

function sendcontacts(){
	var formtype=document.getElementById("formtype").value; var fname=document.getElementById("fname").value;
	var company; if(document.getElementById("company").value){ company = document.getElementById("company").value; } else{ company = 'notfilled'} var ph=document.getElementById("ph").value;
	var fax; if(document.getElementById("fax").value){ fax = document.getElementById("fax").value; }else{ fax = 'notfilled'}	
	var email=document.getElementById("email").value; var address=document.getElementById("address").value;
	var country=document.getElementById("country").value; var message=document.getElementById("message").value;
	
	// DISABLING ALL THE FORMS
	document.contactsForm.fname.disabled=true;		document.contactsForm.company.disabled=true;
	document.contactsForm.ph.disabled=true;			document.contactsForm.fax.disabled=true;
	document.contactsForm.email.disabled=true;		document.contactsForm.address.disabled=true;
	document.contactsForm.country.disabled=true;	document.contactsForm.message.disabled=true;
	document.contactsForm.Submit.disabled=true;		document.contactsForm.Reset.disabled=true;
	
	if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }else{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }	
	$('#feedbackform_loading').fadeIn('fast');
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			if(xmlhttp.responseText=='DONE'){ $('#feedbackform_loading').fadeOut('fast'); setTimeout("display_feedback_result_pass()", 400); }
			else{ $('#feedbackform_loading').fadeOut('fast'); setTimeout("display_feedback_result_fail()", 400); }
		}
	}
	xmlhttp.open("GET", "send?formtype="+formtype+"&fname="+fname+"&company="+company+"&ph="+ph+"&fax="+fax+"&email="+email+"&address="+address+"&country="+country+"&message="+message, true); xmlhttp.send();
}

function display_feedback_result_pass(){ $('#__feedbackform_result_pass').fadeIn('fast'); }
function display_feedback_result_fail(){ $('#__feedbackform_result_fail').fadeIn('fast'); }

function sendinq(){
	$('#__inq_pro_txt_pass').fadeOut(1); $('#__inq_pro_txt_updt').fadeOut(1); $('#__inq_pro_txt_fail').fadeOut(1);
	var formtype=document.getElementById("formtype").value;
	var ItmID=document.getElementById("ItmID").value;
	var qty=document.getElementById('qty').value;
	var ArtNo=document.getElementById('ArtNo').value;
	if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }else{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	$('#__inq_pro_img').fadeIn('fast'); $('#__inq_pro_txt').fadeIn('fast');
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			if(xmlhttp.responseText=='DONE'){ $('#__inq_pro_img').fadeOut('fast'); $('#__inq_pro_txt').fadeOut('fast'); setTimeout("display_inq_result_pass()", 400); chksmlbasket();}
			else if(xmlhttp.responseText=='UPDATED'){ $('#__inq_pro_img').fadeOut('fast'); $('#__inq_pro_txt').fadeOut('fast'); setTimeout("display_inq_result_updt()", 400);}
			else{ $('#__inq_pro_img').fadeOut('fast'); $('#__inq_pro_txt').fadeOut('fast'); setTimeout("display_inq_result_fail()", 400); }
		}
	}
	xmlhttp.open("GET", "send?formtype="+formtype+"&ItmID="+ItmID+"&qty="+qty+"&ArtNo="+ArtNo, true); xmlhttp.send();
	return false;
}

function display_inq_result_pass(){ $('#__inq_pro_txt_pass').fadeIn('fast'); setTimeout("hide_inq_result_pass()", 1500); }
function display_inq_result_updt(){ $('#__inq_pro_txt_updt').fadeIn('fast'); setTimeout("hide_inq_result_updt()", 1500); }
function display_inq_result_fail(){ $('#__inq_pro_txt_fail').fadeIn('fast'); setTimeout("hide_inq_result_fail()", 1500); }

function hide_inq_result_pass(){ $('#__inq_pro_txt_pass').fadeOut('slow'); }
function hide_inq_result_updt(){ $('#__inq_pro_txt_updt').fadeOut('slow'); }
function hide_inq_result_fail(){ $('#__inq_pro_txt_fail').fadeOut('slow'); }

function chksmlbasket(){
	if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			if(xmlhttp.responseText=='EMPTY'){}else{ document.getElementById('m_inqbasket').innerHTML = xmlhttp.responseText;}			
		}
	}
	xmlhttp.open("GET", "send?formtype=chksmlbasket", true); xmlhttp.send();
}

function validateIQForm(){
	var fname=document.getElementById("fname").value; var ph=document.getElementById("ph").value;
	var email=document.getElementById("email").value; var address=document.getElementById("address").value;
	var country=document.getElementById("country").value; var city=document.getElementById("city").value;
	var about=document.getElementById("about").value; var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	tfoption=true;
	if(fname.length==0){$('#__inquiryform_error_fname').html('Please enter your full name').fadeIn('fast');tfoption=false;}
	else{$('#__inquiryform_error_fname').fadeOut('slow');}
	if(ph.length==0){$('#__inquiryform_error_ph').html('Please enter your phone number').fadeIn('fast');tfoption=false;}
	else{$('#__inquiryform_error_ph').fadeOut('slow');}
	if(email.length==0){$('#__inquiryform_error_email').html('Please enter your email address').fadeIn('fast');tfoption=false;}
	else if(reg.test(email)==false){$('#__inquiryform_error_email').html('Please enter your valid email address');$('#__inquiryform_error_email').fadeIn('fast');tfoption=false;}
	else{$('#__inquiryform_error_email').fadeOut('slow');}
	if(address.length==0){$('#__inquiryform_error_address').html('Please enter your mailing address').fadeIn('fast');tfoption=false;}
	else if(address.length<5){$('#__inquiryform_error_address').html('Your mailing address is too short').fadeIn('fast');tfoption=false;}
	else{$('#__inquiryform_error_address').fadeOut('slow');}
	if(city.length==0){$('#__inquiryform_error_city').html('Please enter your city name').fadeIn('fast');tfoption=false;}
	else if(city.length<5){$('#__inquiryform_error_city').html('Your city name is too short').fadeIn('fast');tfoption=false;}
	else{$('#__inquiryform_error_city').fadeOut('slow');}
	if(country.length==''){$('#__inquiryform_error_country').html('Please select your country').fadeIn('fast');tfoption=false;}
	else{$('#__inquiryform_error_country').fadeOut('slow');}
	if(tfoption==false){ return false; }else{ sendinqdata(); return false; }
}

function hideerrorIQForm(){
	$('#__inquiryform_error_fname').fadeOut('slow'); $('#__inquiryform_error_ph').fadeOut('slow');
	$('#__inquiryform_error_email').fadeOut('slow'); $('#__inquiryform_error_address').fadeOut('slow');
	$('#__inquiryform_error_city').fadeOut('slow'); $('#__inquiryform_error_country').fadeOut('slow'); return true;
}

function sendinqdata(){
	var formtype=document.getElementById("formtype").value;
	var fname=document.getElementById("fname").value;
	var company;if(document.getElementById("company").value){company=document.getElementById("company").value;}else{company='notfilled';}
	var ph=document.getElementById("ph").value;
	var fax;if(document.getElementById("fax").value){fax=document.getElementById("fax").value;}else{fax='notfilled';}
	var email=document.getElementById("email").value;
	var url; if(document.getElementById("url").value){url=document.getElementById("url").value;}else{url='notfilled';}
	var address=document.getElementById("address").value;
	var city=document.getElementById("city").value;
	var country=document.getElementById("country").value;
	var about;if(document.getElementById("about").value){about=document.getElementById("about").value;}else{about='notfilled';}
	
	// DISABLING ALL THE FORMS
	document.inqDataForm.fname.disabled=true;		document.inqDataForm.company.disabled=true;
	document.inqDataForm.ph.disabled=true;			document.inqDataForm.fax.disabled=true;
	document.inqDataForm.email.disabled=true;		document.inqDataForm.url.disabled=true;
	document.inqDataForm.address.disabled=true;		document.inqDataForm.city.disabled=true;
	document.inqDataForm.country.disabled=true;		document.inqDataForm.about.disabled=true;	
	document.inqDataForm.Submit.disabled=true;		document.inqDataForm.Reset.disabled=true;
	
	if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	$('#inquiryform_loading').fadeIn('fast');
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4&&xmlhttp.status==200){
			if(xmlhttp.responseText=='DONE'){
				$('#inquiryform_loading').fadeOut('fast');setTimeout("display_inquiryform_result_pass()", 400);
			}else{
				$('#inquiryform_loading').fadeOut('fast');setTimeout("display_inquiryform_result_fail()", 400);
			}
		}
	}
	xmlhttp.open("GET", "send?formtype="+formtype+"&fname="+fname+"&company="+company+"&ph="+ph+"&fax="+fax+"&email="+email+"&url="+url+"&address="+address+"&country="+country+"&city="+city+"&about="+about, true); xmlhttp.send();
}
function display_inquiryform_result_pass(){ $('#__inquiryform_result_pass').fadeIn('fast'); }
function display_inquiryform_result_fail(){ $('#__inquiryform_result_fail').fadeIn('fast'); }
