$(document).ready(function(){
$("#email").required({onerror:"Email is required"})
.regexValidator({regexp:regexEnum.email,onshow:"Please  enter your email address",onfocus:"Email address is required!",oncorrect:"Email is ok.",onerror:"Email format is incorrect!"});
$("#username").required({onerror:"Name is requird"})
.regexValidator({regexp:regexEnum.name,onshow:"Please enter your Name",onfocus:"Name field is required!",oncorrect:"Name field is ok.",onerror:"Name format is incorrect!"});
$("#tel").regexValidator({regexp:regexEnum.telmobileblank,onshow:"",onfocus:"",oncorrect:"",onerror:""});
$("#msg").regexValidator({regexp:"^[\\s\\S]{0,1000}$",onerror:"Only 1,000 character is allowed!",alertit:true});
$("#email,#tel,#username,#msg").addClass('validate');
$("#contactForm").submitValidator({css:'validate'});
});
var ajax = null;
function InitAjax()
{
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
function deal(flag) {
$("#contactForm").submit();
if (!pageValidate) return;
$('#hide1').css('display','block');
$('#hide1').css('width',document.body.clientWidth);
$('#hide1').css('height',document.body.clientHeight);
if(!flag){
$('#bbs').css('display','none');
$('#bbs').css('width','0px');
$('#bbs').css('opacity',' 0');
}
$('#mailmsg').css('display', 'block');
$('#mailmsg').css('width', '309px');
$('#mailmsg').css('opacity', '1');
var msg=document.getElementById('mailmsg');
msg.style.left=(document.documentElement.clientWidth-msg.clientWidth)/2+document.documentElement.scrollLeft + 'px';
msg.style.top=(document.documentElement.clientHeight-msg.clientHeight)/2+document.documentElement.scrollTop + 'px';
$('#sendmsg').html(" Sending email, please wait!");
$('#mailmsg-close').css('display', 'none');
$('#mailmsg-loading').css('display', 'block');
var form = document.contactForm;
var url = "index2.php?option=com_content&task=sendmail";
var post = "username=" + form.username.value;
if(!flag){
post += "&sex=" + form.sex.value;
}
post += "&email=" + form.email.value;
post += "&tel=" + form.tel.value;
post += "&msg=" + form.msg.value;
var ajax = InitAjax();
ajax.open("POST", url, true);
ajax.setRequestHeader("content-length", post.length);
ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
ajax.onreadystatechange = callback;
ajax.send(post);
}
function clearit(){
$('#username,#tel,#email,#msg').attr('value','');
}
function callback() {
if (ajax.readyState == 4&&ajax.status == 200) {
var xmldoc = ajax.responseText;
$(xmldoc).each(function(){if($(this).attr('id')=='remotemsg'){result = $(this).text();}});
$('#hide1').css('display','block');
$('#hide1').css('width',document.body.clientWidth);
$('#hide1').css('height',document.body.clientHeight);
$('#mailmsg').css('display', 'block');
$('#mailmsg').css('width', '309px');
$('#mailmsg').css('opacity', '1');
$('#mailmsg-loading').css('display', 'none');
$('#mailmsg-close').css('display', 'block');
$('#mailmsg-close').css("background-position"," 0 -25px");
if (result == "suc") {
$('#sendmsg').text('Thanks for your message, please click to return！');
} else {
$('#sendmsg').text('Error in sending out message, please try again！');
}
$.ml.showTipState("usernameTip","onShow","Please enter your name");
$.ml.showTipState("emailTip","onShow","Please enter your email address");
$.ml.showTipState("telTip","onShow","Please enter your phone number");
document.contactForm.reset();
}
}