//Clean the cache
$.ajaxSetup ({
    cache: false 
});

//index flash change url
function flashadchange(h_src,h_img){
 $('#'+h_src).attr("src","UpImags/"+h_img);	
}

//error alert
function errshow(){
	alert("database link error");
	history.back();
	}
//clear error
function errclear(){
	$("#resultshow").html("");  
	}


//email submit
function emailsubscribe(){
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;	
var emailsubmit_name = $("#emailsubmit_name").val();	
if(emailsubmit_name == "" || reEmail.test(emailsubmit_name)==false){
	$('#resultshow').html("<font color='#ff0000'>Please enter the correct e-mail address</font>");
	return false;
	}
$.ajax({
  type: "get",
  url: "action.asp",
  data: "emailsubmit_name=" + emailsubmit_name + "&action=emailsubmit",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		alert("Congratulations! E-mail subscription success!You would receive our latest information in your Email "+emailsubmit_name+"");
		$("#resultshow").html("<font color='#006633'>Congratulations! E-mail subscription success!</font>");
	}else{
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}



//inquiry submit
function inquirysubmit(){
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;	
var user_id = $('#user_id').val();
var user_name = $('#user_name').val();
var inquiry_memo = $('#inquiry_memo').val();
var inquiry_company = $('#user_company').val();
var inquiry_tel = $('#user_tel').val();
var inquiry_email = $('#user_email').val();
var inquiry_title = $('#inquiry_title').val();
var product_id = $('#product_id').val();
var product_itemno = $('#product_itemno').val();
var product_name = $('#product_name').val();
var product_img = $('#product_img').val();
var user_mobile = $('#user_mobile').val();
var selectedStr = "";   
var $sendMail = $("input[name='kproductinfo']");   
        $sendMail.each( function() {   
            if ($(this).attr("checked")) {   
                selectedStr += $(this).val() + ",";   
            }   
        });   
inquiry_memo += "<br>I want to know:"+selectedStr+"<br>";
if(user_name == ""){
	$('#resultshow').html("<font color='#ff0000'>Please enter your name</font>");
	return false;
	}
if(inquiry_email == "" || reEmail.test(inquiry_email)==false){
	$('#resultshow').html("<font color='#ff0000'>Please enter the correct e-mail address</font>");
	return false;
	}	
$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_id=" + user_id +"&user_name="+ user_name +"&inquiry_memo="+ inquiry_memo +"&inquiry_company=" + inquiry_company +"&inquiry_tel=" + inquiry_tel +"&inquiry_email=" + inquiry_email +"&inquiry_title="+ inquiry_title + "&product_id="+ product_id + "&product_itemno=" + product_itemno +"&product_name="+ product_name +"&product_img=" + product_img + "&user_mobile=" + user_mobile + "&action=inquirysubmit",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! Inquiry sent successfully! We will reply to you as soon as possible<br><a href='index.asp'>Click here to view more items</a> or <a href='contactus.asp'>Click here to contact us right now!</a></font>");
		$('#inbutton').attr("disabled",true);
	}else{
		alert(html);
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}



//feedback submit
function feedbacksubmit(){
var user_id = $('#user_id').val();	
var feedback_title = $('#feedback_title').val();	
var feedback_memo = $('#feedback_memo').val();	
var feedback_name = $('#feedback_name').val();	
var feedback_tel = $('#feedback_tel').val();	
var feedback_email = $('#feedback_email').val();	
var feedback_others = $('#feedback_others').val();	

if(feedback_title == "" || feedback_name == "" || feedback_email==""){
	$("#resultshow").html("<font color='#ff0000'>Required items can not be empty</font>");
	return false;
	}
$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_id=" + user_id +"&feedback_title="+ feedback_title +"&feedback_memo=" + feedback_memo +"&feedback_name=" + feedback_name +"&feedback_tel=" + feedback_tel +"&feedback_email=" + feedback_email +"&feedback_others=" + feedback_others + "&action=feedbacksubmit",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! Successfully submitted</font>");
        $('#fbtn').attr("disabled",true);
	}else{
		alert(html)
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}


