// JavaScript Document

//control left menu, change ico
var m,n;
function changeroll(m){
	//loadURL();
	var strdisplay;
	//strdisplay=document.getElementById("rolling"+i).style.display;
	if (document.getElementById("rolling"+m).style.display=="none"){
		document.getElementById("rolling"+m).style.display="block";
		}
	else{
		document.getElementById("rolling"+m).style.display="none";
		}
		changepic(m);
		
		strdisplay=document.getElementById("rolling"+m).style.display;
		if(document.getElementById("keepstate").value.indexOf("?")>=0){
			if(document.getElementById("keepstate").value.indexOf("rolling"+m)<0){
			document.getElementById("keepstate").value+="&rolling"+m+"=="+strdisplay;
			}
			else{
				var i,j;
				var strK;
				var stra,strb;
				strK=document.getElementById("keepstate").value;
				i=strK.indexOf("rolling"+m);
				j=strK.substring(i,strK.length).indexOf("&");
				stra=document.getElementById("rolling"+m).style.display;
				stra="rolling"+m+"=="+stra;
				if(j>0){
					strb=strK.substring(i,j+1);
					//alert(strb);
					}
				else{
					strb=strK.substring(i,strK.length);
					}
					strK=strK.replace(strb,stra);
					document.getElementById("keepstate").value=strK;
				}
			}
		else{
			document.getElementById("keepstate").value="?rolling"+m+"=="+document.getElementById("rolling"+m).style.display;
			}
	}
	
function changepic(n){
	if(document.getElementById("rolling"+n).style.display=="none"){
		document.getElementById(n).src="images/pro_left_add.jpg";
		}
	else{
		document.getElementById(n).src="images/pro_left_minus.jpg";
		}
	}

function display_left(){
	document.getElementById("ftp_left_left_c").style.display="none";
	document.getElementById("ftp_left_right_c").style.display="block";
	}
	
function display_right(){
	document.getElementById("ftp_left_left_c").style.display="block";
	document.getElementById("ftp_left_right_c").style.display="none";
	}
	
//增加上传文件的控件
var i=1;
function add_att(){
//检查浏览器的类型，不同的浏览器设置不同的lineHeight
if (navigator.userAgent.indexOf("Firefox")>0){
document.getElementById("att_text").style.lineHeight="21px";
}

var att_div=document.getElementById("att");//获取file所在的层，也就是file的父层
var img=document.createElement("input");//新建一个file，以下为设置file的各种属性
img.type="file";
img.name="image";
img.id="img"+i;
att_div.appendChild(img);//添加这个file到所在的层里


add_att_text(i);
i++;
}

function add_att_text(num){
var att_text=document.getElementById("att_text").innerHTML;
att_text+="<br><a href='javascript:del_att("+num+");' id='text"+num+"'>Remove</a>";
document.getElementById("att_text").innerHTML=att_text;
}

function del_att(I){
var att_div=document.getElementById("att");
var a=document.getElementById("img"+I);
att_div.removeChild(a);
var strHtml=document.getElementById("att_text").innerHTML;
strHtml=strHtml.toLowerCase();
var i=strHtml.indexOf("text"+I);
var strHtmlB=strHtml.substring(0,i);
strHtmlB=strHtmlB.substring(0,strHtmlB.lastIndexOf("<br"));
//alert(strHtmlB);
//alert(strHtml);
var len=strHtml.length;
var strHtmlA=strHtml.substring(i+1,len);
//alert(strHtmlA);

if(strHtmlA.indexOf("<br")>0){
	strHtmlA=strHtmlA.substring(strHtmlA.indexOf("<br"),strHtmlA.length);
	}
else if(strHtmlA.indexOf("<br")<=0){
	strHtmlA="";
	}
	//alert(strHtmlA);
strHtml=strHtmlB+strHtmlA;
//alert(strHtml);
strHtml=strHtml.replace(/remove/g,"Remove");
strHtml=strHtml.replace(/add attachment/g,"Add Attachment");
//strHtml=strHtml.replace(/style24/g,"STYLE24");
//alert(strHtml);
document.getElementById("att_text").innerHTML=strHtml;
}


//keep the left menu state
var url;
function href(url){
	//alert(document.getElementById("keepstate").value);
	var strhttp=document.location.href;
	strhttp=strhttp.substring(0,strhttp.lastIndexOf("/")+1);
	document.location.href=strhttp+url+document.getElementById("keepstate").value;
	}
	
function loadurl(m){
	var strLocation;
	strLocation=document.location.href;
	if(m==0){
		if(strLocation.indexOf("?")>0){
			strLocation=strLocation.substring(strLocation.lastIndexOf("?"),strLocation.length);
			document.getElementById("keepstate").value=strLocation;
			}
		else{
			document.getElementById("keepstate").value="";
			}
	}
	else{
		if(strLocation.indexOf("rolling"+m+"==none")>0){
			document.getElementById("rolling"+m).style.display="none";
			}
		else if(strLocation.indexOf("rolling"+m+"==block")>0){
			document.getElementById("rolling"+m).style.display="block";
			}
		changepic(m);
		}
		
	}
	
//bookmark
function addBookMark(title,url){
if (window.sidebar){
	window.sidebar.addPanel(title,url,"");
	}else if(document.all){
		window.external.AddFavorite(url,title);
		}else if(window.opera && window.print){
			return true;
			}
}

//check form
function chk_testimonial(){
	var a=b=c=d=e=0;
	var msg="Please complete the following fields:\n";
	if(document.form.tName.value==""){
		a=1;
		msg+="- Name\n";
		}
	if(document.form.tCompany.value==""){
		b=1;
		msg+="- Company\n";
		}
	if(document.form.tEmail.value==""){
		c=1;
		msg+="- Email\n";
		}
	//if(document.form.tTel.value==""){
		//d=1;
		//msg+="- Tel\n";
		//}
	//if(document.form.tMsg.value==""){
		//e=1;
		//msg+="- Message\n";
		//}
	
	if(msg!="Please complete the following fields:\n"){
		alert(msg);
		
		if(a==1){
			document.form.tName.focus();
			}
			else if(b==1){
				document.form.tCompany.focus();
				}
				else if(c==1){
					document.form.tEmail.focus();
					}
					//else if(d==1){
						//document.form.tTel.focus();
						//}
						//else if(e==1){
							//document.form.tMsg.focus();
							//}
		return false;
		}
		
//验证邮箱
if (document.form.tEmail.value!=""){
//var rule=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
if (!rule.exec(document.form.tEmail.value)){
alert("Incorrect email address, please check it.");
document.form.tEmail.focus();
//m=1;
return false;
}
}

//验证电话
if(document.form.tTel.value!=""){
var strTel=document.form.tTel.value;
var strUnit;
var x=strTel.length;
var i;
for(i=0;i<x;i++){
strUnit=strTel.substring(i,i+1);
if(isNaN(strUnit) && strUnit!="-" && strUnit!="(" && strUnit!=")" && strUnit!="_"){
alert("Incorrect Tel number, please check it.");
document.form.tTel.focus();
return false;
break;
}
}
}
	}
	
	function chk_ftp(){
	var a=b=c=d=e=0;
	var msg="Please complete the following fields:\n";
	if(document.userftp.uCompany.value==""){
		a=1;
		msg+="- Company\n";
		}
	if(document.userftp.uEmail.value==""){
		b=1;
		msg+="- Email\n";
		}
	if(document.userftp.uPath.value==""){
		c=1;
		msg+="- Path\n";
		}
	if(document.userftp.uUser.value==""){
		d=1;
		msg+="- User\n";
		}
	if(document.userftp.uPsw.value==""){
		e=1;
		msg+="- Password\n";
		}
	
	if(msg!="Please complete the following fields:\n"){
		alert(msg);
		
		if(a==1){
			document.userftp.uCompany.focus();
			}
			else if(b==1){
				document.userftp.uEmail.focus();
				}
				else if(c==1){
					document.userftp.uPath.focus();
					}
					else if(d==1){
						document.userftp.uUser.focus();
						}
						else if(e==1){
							document.userftp.uPsw.focus();
							}
		return false;
		}
		
//验证邮箱
if (document.userftp.uEmail.value!=""){
//var rule=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
if (!rule.exec(document.userftp.uEmail.value)){
alert("Incorrect email address, please check it.");
document.userftp.uEmail.focus();
//m=1;
return false;
}
}
	}
	
	function chk_q(){
		var a=b=c=0;
		var msg="";
		if(document.form.qname.value=="")
		{
			a=1;
			msg+="Please complete the Name field.";
			}
		if(document.form.qemail.value=="")
		{
			b=1;
			msg+="\nPlease complete the Email field."
			}
		//验证邮箱
		if (document.form.qemail.value!=""){
		//var rule=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
		if (!rule.exec(document.form.qemail.value)){
		c=1;
		msg+="\nIncorrect Email format, please check."
		}
		}
		if(msg!=""){
			alert(msg);
			if(a==1){
				document.form.qname.focus();
				return false;
				}
			if(b==1 || c==1)
			{
				document.form.qemail.focus();
				return false;
				}
			}
	}
	

function chkfriend(){
	var a=b=c=d=0
	var msg="Please fill the follow fields completely."
	
	if(document.form.s_name.value==""){
		a=1;
		msg+="\nPlease complete the Your Name field."
		}
	if(document.form.s_email.value==""){
		b=1;
		msg+="\nPlease complete the Your Email field."
		}
	if(document.form.t_name.value==""){
		c=1;
		msg+="\nPlease complete the Friend Name field."
		}
	if(document.form.t_email.value==""){
		d=1;
		msg+="\nPlease complete the Friend Email field."
		}
		
	if(msg!="Please fill the follow fields completely."){
		alert(msg);
		if(a==1){
			document.form.s_name.focus();
			return false;
			}
		if(b==1){
			document.form.s_email.focus();
			return false;
			}
		if(c==1){
			document.form.t_name.focus();
			return false;
			}
		if(d==1){
			document.form.t_email.focus();
			return false;
			}
		
		}
	var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
	if(document.form.s_email.value!=""){
		if(!rule.exec(document.form.s_email.value)){
			alert("Incorrect Your Email fomat, please check.");
			document.form.s_email.focus();
			return false;
			}
		}
		
	if(document.form.t_email.value!=""){
		if(!rule.exec(document.form.t_email.value)){
			alert("Incorrect Your Email fomat, please check.");
			document.form.t_email.focus();
			return false;
			}
		}
	}
	
	
function cl(){
	window.close();
	}
	
	

function ajaxpage(url, containerid){
var Conversion = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
Conversion = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IEs
try {
Conversion = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
Conversion = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
Conversion.onreadystatechange=function(){
loadpage(Conversion, containerid)
}
Conversion.open('GET', url, true)
Conversion.send(null)
}

function loadpage(Conversion, containerid){
if (Conversion.readyState == 4 && (Conversion.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=Conversion.responseText
}

function changePIC(ID,Num){
var path="images/successfulcase/";
if (ID=="pic_b"){
document.getElementById(ID).src=path+Num+"_b.gif";
}
else {
document.getElementById(ID).src=path+Num+"_t.gif";
}
}

function changeICO(ID,Num){
	var path="images/successfulcase/";
	document.getElementById(ID).src=path+Num+"_t_2.gif";
}

function changeBg(ID){
	var path="images/successfulcase/";
	var i;
	for(i=1;i<8;i++){
	document.getElementById("bg_"+i).style.background="";
	}
	document.getElementById("bg_"+ID).style.background="url("+path+"0"+ID+"_t.gif) center no-repeat";
}