// JavaScript Document
	
<!-- 

function createXMLHttpRequestObject() { // AJAX CALL

	// This function is used to create XMLHttpRequest object for different browser
	try {
		// firefox
		return new XMLHttpRequest();
	} catch (e) {
		try {
			// IE 6
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				// IE 5
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				return false;
			}
		}
	}
	
} // End Of function createXMLHttpRequestObject()

function send_data_to_server(url_string, parameters_string, call_back_function, on_error) {
	// Add any preload function here if needed
	var req = createXMLHttpRequestObject();
	if (req) {
		// Set call back function when XMLHttpRequest get the response
		req.onreadystatechange=function() {
			if(req.readyState == 4) { //Task Completed
				if(req.status == 200) { //Server Respone status
					var result = req.responseText;
					// Add anything to do here is needed
					if (result == "success"){
						call_back_function();
						return true;
					} else {
						on_error(result, 1);
						return false;
					}
				} else {
					// ERROR HANDLING HERE
					on_error(req.status, 2);
					return false;
				}
			}
		}
		// Prepare the request and send it to server
		var url = url_string; // e.g. "abc.php"
		var params = parameters_string; // e,g "id=1232&name=test"
		req.open("POST", url, true); //Open MUST be called before setting the request header
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
	} else {
		// Return false if XMLHttpRequest can not be created
		on_error('Your browser does not support AJAX.', 3);
		return false;	
	}
} // End of function send_data_to_server()

// Trim String
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

// Encoding
function encode_str(str){
	return escape(encodeURIComponent(str.trim()));
}

// Construct Parameter String For AJAX Call (JQuery is needed)
function getParaStr(eleID){
	return eleID + "=" + encode_str($('#' + eleID).val());
}

// Email Address Validation
function isEMailAddr(str) {
	if (str != ''){
		str = str.trim();
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
		if (!str.match(re)) {
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}

// Get Current Parameter From Current URL
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
  	var strQueryString = strHref.substr(strHref.indexOf("?"));
  	var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
} 

// JQuery Event
$(document).ready(function(){

	// Menu Index			   
		switch (current_page) {
			case 'news-detail':   //This case is not using
				current_page = 'news';
				break;
		}
	
		$("#home_nav_wrapper a img").each(function(){
			var current_path = $(this).attr('src');
			if(current_path.indexOf(current_page) != -1){
				$(this).attr('src',current_path.replace('_out.png','_over.png'));
			}
		});
	
		$("#home_nav_wrapper a").hover(function(){
			var current_path = $('img', this).attr('src');
			if(current_path.indexOf(current_page) == -1){
				$('img', this).attr('src',current_path.replace('_out.png','_over.png'));
			}
		}, function() {
			var current_path = $('img', this).attr('src');
			if(current_path.indexOf(current_page) == -1){
				$('img', this).attr('src',current_path.replace('_over.png','_out.png'));
			}
		});
	
	
		$("#nav_wrapper a img").each(function(){
			var current_path = $(this).attr('src');
			if(current_path.indexOf(current_page) != -1)
				$(this).attr('src',current_path.replace('_out.png','_over.png'));
		});
	
		$("#nav_wrapper a").hover(function(){
			var current_path = $('img', this).attr('src');
			if(current_path.indexOf(current_page) == -1){
				$('img', this).attr('src',current_path.replace('_out.png','_over.png'));
			}
		}, function() {
			var current_path = $('img', this).attr('src');
			if(current_path.indexOf(current_page) == -1){
				$('img', this).attr('src',current_path.replace('_over.png','_out.png'));
			}
		});
		
		$("#nav_sub_wrapper a img").each(function(){
			var current_path = $(this).attr('src');
			if(current_path.indexOf(current_sub_page) != -1)
				$(this).attr('src',current_path.replace('_out.png','_over.png'));
		});
	
		$("#nav_sub_wrapper a").hover(function(){
			var current_path = $('img', this).attr('src');
			if(current_path.indexOf(current_sub_page) == -1){
				$('img', this).attr('src',current_path.replace('_out.png','_over.png')); 
			}
		}, function() {
			var current_path = $('img', this).attr('src');
			if(current_path.indexOf(current_sub_page) == -1){
				$('img', this).attr('src',current_path.replace('_over.png','_out.png'));
			}
		});			
	// End of Menu Index
	
	// Min Height
		$(window).load(function(){
			if ($("#main_content_wrapper").height() < 535) {
					$("#main_content_wrapper").height('535px');
			}
			if ($("#news_content_wrapper").height() < 535) {
					$("#news_content_wrapper").height('535px');
			}
		});			
	// End of Min Height

});

// Contact Form Function
function send_mail(){
	
	var false_color
	false_color = '#b2e6e4';

	var true_color
	true_color = '#FFFFFF';

	$('#cf_name').css({'background-color':true_color});
	$('#cf_phone').css({'background-color':true_color});
	$('#cf_enquiry').css({'background-color':true_color});	

	// 1. Validation
	if ($('#cf_name').val() == ''){
		$('#cf_name').css({'background-color':false_color});
		$('#cf_name').focus();
		return false;
	} else if ($('#cf_phone').val() == ''){
		$('#cf_phone').css({'background-color':false_color});		
		$('#cf_phone').focus();
		return false;
	} else if ($('#cf_enquiry').val() == ''){
		$('#cf_enquiry').css({'background-color':false_color});				
		$('#cf_enquiry').focus();
		return false;		
	}
	// 2. Pass value to backend
	var url = 'process_form.php';
	var paraStr = getParaStr('cf_company') + '&' + getParaStr('cf_name') + '&' + getParaStr('cf_phone') + '&' + getParaStr('cf_email') + '&' + getParaStr('cf_enquiry');
	send_data_to_server(url, paraStr, send_success, send_error);
}

function send_success(){
	$('#contact_form').hide();
	$('#contact_form_success_msg').show();
}

function send_error(msg, type){

	$('#contact_form_fail_msg').html(msg);
	$('#contact_form_fail_msg').show();

}
		
//-->
