function IsNumeric(input){
    var RE = /^\+{0,1}\d+\-{0,1}\d*\-{0,1}\d*\-{0,1}\d+$/;
    return (RE.test(input));
}
function isEmail(email) {
	filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
	  return true;
	}
	else {
		return false;
	}
}
function submit_request() {
	$("form.request_form p.error").text("");
	name = $("form.request_form .name").val();
	email = $("form.request_form .email").val();
	phone = $("form.request_form .phone").val();
	address = $("form.request_form .address").val();
	zip = $("form.request_form .zip").val();
	service = $("form.request_form .service").val();
	message = $("form.request_form .message").val();
	
	if(name != "" && name != "Name") {
		if(email != "") {
			if(isEmail(email)) {
				if(phone != "") {
					if(IsNumeric(phone)) {
						if(address != "" && address != "Address") {
							if(IsNumeric(zip)) {
								if(service != "") {
									if(message != "" && message != "Message") {
										return true;
									}
									else {
										$("form.request_form .message").next().text("Enter your message.");
									}
								}
								else {
									$("form.request_form .service").next().text("Please select service.");
								}
							}
							else {
								$("form.request_form .zip").next().text("Please enter valid zip code.");
							}
						}
						else {
							$("form.request_form .address").next().text("Please enter your address.");
						}
					}
					else {
						$("form.request_form .phone").next().text("Please enter valid phone number.");
					}
				}
				else {
					$("form.request_form .phone").next().text("Please enter your phone number.");
				}
			}
			else {
				$("form.request_form .email").next().text("Enter a valid email address.");
			}
		}
		else {
			$("form.request_form .email").next().text("Please enter your email.");
		}
	}
	else {
		$("form.request_form .name").next().text("Please enter your name.");
	}
	return false;
}

function contact_submit() {
	$("form.contact_form p.error").text("");
	name = $("form.contact_form .name_c").val();
	email = $("form.contact_form .email_c").val();
	phone = $("form.contact_form .phone_c").val();
	street = $("form.contact_form .street_c").val();
	city = $("form.contact_form .city_c").val();
	zip = $("form.contact_form .zip_c").val();
	worktype = $("form.contact_form .worktype_c").val();
	workwhen = $("form.contact_form .workwhen_c").val();;
	budget = $("form.contact_form .budget_c").val();
	message = $("form.contact_form .message_c").val();
	
	if(name != "") {
		if(email != "") {
			if(isEmail(email)) {
				if(phone != "") {
					if(IsNumeric(phone)) {
						if(street != "") {
							if(city != "") {
								if(zip != "") {
									if(worktype != "") {
										if(workwhen != "") {
											if(budget != "") {
												if(message != "") {
													return true;
												}
												else {
													$("form.contact_form .message_c").next().text("Comments cannot be blank.");
												}
											}
											else {
												$("form.contact_form .budget_c").next().text("Budget cannot be blank.");
											}
										}
										else {
											$("form.contact_form .workwhen_c").next().text("Work When cannot be empty.");
										}
									}
									else {
										$("form.contact_form .worktype_c").next().text("Work Type cannot be empty.");
									}
								}
								else {
									$("form.contact_form .zip_c").next().text("Zip cannot be empty.");
								}
							}
							else {
								$("form.contact_form .city_c").next().text("City cannot be empty.");
							}
						}
						else {
							$("form.contact_form .street_c").next().text("Street cannot be empty.");
						}
					}
					else {
						$("form.contact_form .phone_c").next().text("Please enter valid phone number.");
					}
				}
				else {
					$("form.contact_form .phone_c").next().text("Phone number cannot be blank.");
				}
			}
			else {
				$("form.contact_form .email_c").next().text("Enter a valid email address.");
			}
		}
		else {
			$("form.contact_form .email_c").next().text("Email cannot be blank.");
		}
	}
	else {
		$("form.contact_form .name_c").next().text("Name cannot be blank.");
	}
	return false;
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto();
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto();
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function myothercarousel_initCallback(othercarousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    othercarousel.buttonNext.bind('click', function() {
        othercarousel.startAuto();
    });

    othercarousel.buttonPrev.bind('click', function() {
        othercarousel.startAuto();
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    othercarousel.clip.hover(function() {
        othercarousel.stopAuto();
    }, function() {
        othercarousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#banner_slide').jcarousel({
        auto: 4,
        wrap: 'last',
		scroll: 1,
        initCallback: mycarousel_initCallback
    });
    jQuery('#latest_project_slide').jcarousel({
        auto: 4,
        wrap: 'last',
		scroll: 1,
        initCallback: myothercarousel_initCallback
    });
	
	jQuery("select.service").change(function(){
		jQuery("div.fake_select").text(jQuery(this).find("option[value='"+jQuery(this).val()+"']").text());
	});
	
	jQuery("input.name").focus(function(){
		if(jQuery(this).val() == "Name") {
			jQuery(this).val("");
		}
	});

	jQuery("input.name").blur(function(){
		if(jQuery(this).val() == "") {
			jQuery(this).val("Name");
		}
	});
	jQuery("input.email").focus(function(){
		if(jQuery(this).val() == "Email") {
			jQuery(this).val("");
		}
	});

	jQuery("input.email").blur(function(){
		if(jQuery(this).val() == "") {
			jQuery(this).val("Email");
		}
	});
	jQuery("input.phone").focus(function(){
		if(jQuery(this).val() == "Phone") {
			jQuery(this).val("");
		}
	});

	jQuery("input.phone").blur(function(){
		if(jQuery(this).val() == "") {
			jQuery(this).val("Phone");
		}
	});

	jQuery("input.address").focus(function(){
		if(jQuery(this).val() == "Address") {
			jQuery(this).val("");
		}
	});
	jQuery("input.address").blur(function(){
		if(jQuery(this).val() == "") {
			jQuery(this).val("Address");
		}
	});

	jQuery("input.zip").focus(function(){
		if(jQuery(this).val() == "Zip") {
			jQuery(this).val("");
		}
	});
	jQuery("input.zip").blur(function(){
		if(jQuery(this).val() == "") {
			jQuery(this).val("Zip");
		}
	});
	jQuery("textarea.message").focus(function(){
		if(jQuery(this).text() == "Message") {
			jQuery(this).text("");
		}
	});

	jQuery("textarea.message").blur(function(){
		if(jQuery(this).text() == " ") {
			jQuery(this).text("Message");
		}
	});
	
	if(parseInt(jQuery("#sidebar_wrapper").height()) > parseInt(jQuery("#content_area").height())) {
		eqHeight = parseInt(jQuery("#sidebar_wrapper").height()) - 62;
		jQuery("#page_content").css({'height':eqHeight+'px'});
	}
	
	if(jQuery("div.side_menu li.active").has("ul")) {
		jQuery("div.side_menu li.active ul li").each(function(){
			if(jQuery(this).hasClass('active')) {
				jQuery("div.side_menu li.active ul").prev().addClass('parent_active');
			}
		});
	}
});
