﻿//  Email Validation //
RE=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/


// VB Functions in JS//
function Trim(STRING){
	STRING = LTrim(STRING);
	return RTrim(STRING);
}


// VB Functions in JS//
function RTrim(STRING){
	while(STRING.charAt((STRING.length -1))==" "){
	STRING = STRING.substring(0,STRING.length-1);
	}
	return STRING;
}


// VB Functions in JS//
function LTrim(STRING){
	while(STRING.charAt(0)==" "){
	STRING = STRING.replace(STRING.charAt(0),"");
	}
	return STRING;
}


// VB Functions in JS//
function Left(STRING,CHARACTER_COUNT){
	return STRING.substring(0,CHARACTER_COUNT);
}


// VB Functions in JS//
function Right(STRING,CHARACTER_COUNT){
	return STRING.substring((STRING.length - CHARACTER_COUNT),STRING.length);
}


// ======================================
// ======================================
// show & hide options //
function ShowOption (num) {
	$(".option-content div").hide()
	$('#opt'+num).fadeIn(500);
}



// ======================================
// ======================================
// Contact Form Validation
function ContactValidation() {
	frm = document.frmcontact
	$("#msg").removeClass("msg-3")
	$("#msg").addClass("msg-1")
	
	if (Trim($('#iname').val()).length <= 2 ) {
		frm.name.focus();
		$('#msg').html("Please enter your full name");
		return false
	}
	if (Trim($('#iemail').val()).length <= 3 ) {
		frm.email.focus();
		$('#msg').html("Please enter your email address");
		return false
	}
	else {
		if (!RE.test(Trim($('#iemail').val()))){
			frm.email.focus();
			$('#msg').html("Invalid your email address");
			return false
		}
	}
	if (Trim($('#icomm').val()).length <= 5 ) {
		frm.comment.focus();
		$('#msg').html("Please enter your comment");
		return false
	}

	$('#msg').html("");
	ContactSend(Trim($('#iname').val()),Trim($('#iemail').val()),Trim($('#iphone').val()),Trim($('#icomm').val()))
	return false		
}


// ======================================
// ======================================
function ContactSend (myName,myEmail,myPhone,myMsg) {
	$.ajax({
		url: "contactsend.php?name=" + myName + "&email=" + myEmail + "&phone=" + myPhone + "&message=" + myMsg,
		cache: false,
		beforeSend: function(){
			$("#msg").removeClass("msg-1")
			$("#msg").addClass("msg-2")
			$('#msg').html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please wait ...");
		},
		success: function(html){
			$("#msg").removeClass("msg-2")
			$("#msg").addClass("msg-3")
			$('#msg').html("Your message has been sent");
		},
		complete: function(){
			$("input").val("");
			$("textarea").val("");
		}
	});
}


// ======================================
// ======================================
// menu show & hide //
var MenuSelect = false
var MenuTime
var MenuID
function myMenu(myid,mode){
	MenuID = $("#" + myid + '-content');
	// $ mean document get - $("#" + myid + '-content' means: document get elemnt by id + myid + -content //
	if (mode == 1){
		clearTimeout(MenuTime);
		MenuID.slideDown("normal");
	}
	if (mode == 0)
		MenuTime= setTimeout("if (MenuSelect == false) MenuID.slideUp('normal');",300)
	if (mode == 3){
		clearTimeout(MenuTime);
		MenuSelect = true
	}
	if (mode == 4) {
		MenuSelect = false
		MenuTime = setTimeout("if (MenuSelect == false) MenuID.slideUp('normal');",300)
	}
}



// ======================================
// ======================================
