function e(id) {
	return document.getElementById(id);
}

function toggle(show, hide) {
	  document.getElementById(show).style.display = 'block';
	  document.getElementById(hide).style.display = 'none';
}

function contact_us () {
	
	MM_validateForm('name','','R','email','','RisEmail','subject','','R','user_message','','R');
	
	if (document.MM_returnValue == true) {
		// show loading bar and procced with mail.
		e('loadBar').style.display = 'block';
		e('submit').disabled = true;
		
		var values = get_form('contact_form');
		var cp = new cpaint();
		
		cp.set_transfer_mode('post');
		cp.set_response_type('text');
		
		cp.call('module/contact_us.php', null, contact_response, values);
	}
	return false;
}

function contact_response (response) {
	var result = response;

	// success. submit the form 
	if (result > 0) {
		// thank you page show and hide the form
		e('thankyou').style.display = 'block';
		e('contact_form_area').style.display = 'none';
	} else {
		// mail not send! show error.
		e('loadBar').style.display = 'none';
		e('submit').disabled = false;
		alert('oops!!! something went wrong, mail could not be sended, please try again!');
	}
}

function request_quote () {
	
	MM_validateForm('name','','R','email','','RisEmail');
	
	if (document.MM_returnValue == true) {
		// show loading bar and procced with mail.
		e('loadBar').style.display = 'block';
		e('submit').disabled = true;
		
		var values = get_form('quote_form');
		var cp = new cpaint();
		
		cp.set_transfer_mode('post');
		cp.set_response_type('text');
		
		cp.call('module/request_quote.php', null, quote_response, values);
	}
	return false;
}

function quote_response (response) {
	var result = response;

	// success. submit the form 
	if (result > 0) {
		// thank you page show and hide the form
		e('thankyou').style.display = 'block';
		e('quote_form_area').style.display = 'none';
	} else {
		// mail not send! show error.
		e('loadBar').style.display = 'none';
		e('submit').disabled = false;
		alert('oops!!! something went wrong, mail could not be sended, please try again!');
	}
}

/* gets all the valid values and var of the form and put in array
 *
 * @param string FormName
 *
 * @return array 
 * @static
 */ 
function get_form (FormName) {
	var SubmitValues = new Array();
	SubmitValues["form_name"] = FormName;

	for (var i=0; i <= document.forms[FormName].elements.length-1; i++) {
		var field_name = document.forms[FormName].elements[i].name;
		var field_value = document.forms[FormName].elements[i].value;
		var field_type = document.forms[FormName].elements[i].type;

		// text 
		if (field_type == 'text' 
			|| field_type == 'hidden' 
			|| field_type == 'textarea' 
			|| field_type == 'select-one' 
			|| field_type == 'file') {
			
			SubmitValues[field_name] = field_value;
		}

		// radio button
		if (field_type == 'radio') {
			if (document.forms[FormName].elements[i].checked == true)
				SubmitValues[field_name] = field_value;
		}
		// checkbox
		if (field_type == 'checkbox') {
			if (document.forms[FormName].elements[i].checked == true)
				SubmitValues[field_name] = field_value;
		}
		// multi selection box
		if (field_type == 'select-multiple') {
			var ob = document.forms[FormName].elements[i];
			selected = new Array(); 
			for (var j = 0; j < ob.options.length; j++) 
				if (ob.options[ j ].selected) 
					selected.push(ob.options[ j ].value);
				SubmitValues[field_name] = selected;
		}
	}

	return SubmitValues;
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
