﻿$(function(){
	for(var i=0; i<document.links.length; i++)
    document.links[i].onfocus=function(){this.blur()} 
	/*if($.browser.opera) { 
		$( function() { $(".wrcProInfo b").css("margin", "22px 0 0 110px");}); 
    } else {
		$(function(){$(".wrcProInfo b").css("margin", "22px 0 0 -75px");});	
	}*/
	/*
	* Top animation
	*/
	var clickLeftNode = $(".playLeft");
	var clickRightNode = $(".playRight");
	var ADContentNode = $(".ADContent");
	var imgCount = $(".ADContent").find("img").length - 1;
	var imgWidth = imgCount * 982 ;
	//alert(imgCount)
	var pageIndex = 1;
	//click event
	/*clickLeftNode.click(function(){
		if(!ADContentNode.is(":animated")){
			if(pageIndex == 1){
				ADContentNode.animate({"left": -imgWidth + "px"},{duration:500});
				pageIndex = imgCount + 1;
			} else {
				ADContentNode.animate({"left":"+=" + 982 + "px"},{duration:500});
				pageIndex--;
			}
		}
	});
	clickRightNode.click(function(){
		if(!ADContentNode.is(":animated")){
			if(pageIndex == imgCount + 1) {
				ADContentNode.animate({"left":"0px"},{duration:500});	
				pageIndex = 1;
			} else {
				ADContentNode.animate({"left":"-=" + 982 + "px"},{duration:500});	
				pageIndex++;
			}
		}
	});*/
	//search form
	$("#searchValueId").blur(function(){
				if($(this).val() == '')
					$(this).val('Search');
			});
	$("#searchValueId").focus(function(){
				if($(this).val() == 'Search')
					$(this).val('');
			});
	/*function autoAnimate(){
		if(pageIndex == imgCount + 1) {
			ADContentNode.animate({"left":"0px"},{duration:500});	
			pageIndex = 1;
		} else {
			ADContentNode.animate({"left":"-=" + 982 + "px"},{duration:500});	
			pageIndex++;
		}
	}
	setInterval(autoAnimate, 10000);*/
	/***endAnimate***/
	/**/
	function checkCurrent(obj) {
		if($(obj).attr("class") == "current" ) {
			return true;	
		} else {
			return false;	
		}
	}
	//left animation
	var animateObj = $('#instaLeft').find("#instaContent");
	var n = 0;
	var t;
	$('.playRemark ul li').click(function(){
		clearInterval(t);
		var index = $(this).text()-1;
		n = index;
		if(!animateObj.is(":animated")) {
			animateObj.filter(":visible").fadeOut(200, function(){
				animateObj.eq(index).fadeIn(300);
			});
			$(this).css("background-image", "url(images/animateCurrent.gif)").siblings().css("background-image", "url(images/animateNormal.gif)");
			t = setInterval(display, 5000);
		}
	});
	function display(){
		n = n > 3 ? 0 : ++n;
		$('.playRemark ul li').eq(n).trigger('click');
	}
	t = setInterval(display, 5000);
	/*
	* menu transparent
	*/
	/*$(".opacityMenu").css("margin-left", ($(document).width() - $(".opacityMenu").width()) / 2);*/
	var opacityMenuNode = $(".navBar li");
	var hiddenMenuBar = $(".CompanyHiddenMenuBar");
	var productsMenuBar = $(".productsHiddenMenuBar");
	var opacityMenuNodeLength = opacityMenuNode.length;
	//hiddenMenuBar.corner();
	//opacityMenuNode.addClass("currentLi");
	/* remove split line */
	//$(".navBar li:last").css("background-image", "none");
	opacityMenuNode.each(function(index){
		$(this).hover(function(){
			if (checkCurrent($(this))) {
				return false;
			} else {
				$(this).css("background", "url(images/wisecleaner/menulihover.gif) no-repeat").children("a").css("color","#3568AC");
			}
		}, function(){
			if (checkCurrent($(this))) {
				return false;
			} else {
				$(this).css("background-image", "none").children("a").css("color","#525252");
			}		
		});				  
	});
	
	/* on company menu */
	/*opacityMenuNode.eq(5).hover(function(){
		$(this).css("background", "url(images/wisecleaner/menulihover.png) no-repeat")
		hiddenMenuBar.show();
	}, function(){
		
		hiddenMenuBar.hide();
	});*/
	
	/* on products menu */
	opacityMenuNode.eq(1).hover(function(){
		$(this).css("background", "url(images/wisecleaner/menulihover.png) no-repeat")
		productsMenuBar.show();
	}, function(){
			$(this).removeAttr("style");
			productsMenuBar.hide();
	});
	/* company children menu */
	hiddenMenuBar.hover(function(){
		opacityMenuNode.eq(5).css("background", "url(images/wisecleaner/menulihover.png) no-repeat").children("a").css("color","#3568AC");
		$(this).show();
	}, function(){
			$(this).hide();
			opacityMenuNode.eq(5).css("background-image", "none").children("a").css("color","#525252");
	});
	/* products children menu */
	productsMenuBar.hover(function(){
		opacityMenuNode.eq(1).css("background", "url(images/wisecleaner/menulihover.png) no-repeat").children("a").css("color","#3568AC");
		$(this).show();
	}, function(){
		if (checkCurrent(opacityMenuNode.eq(1))) {
			$(this).hide();//.fadeOut(500);
			$(opacityMenuNode).removeAttr("style");
		} else {
			$(this).hide();//.fadeOut(500);
			opacityMenuNode.eq(1).css("background-image", "none").children("a").css("color","#525252");
			$(opacityMenuNode).removeAttr("style");
		}
	});
	//get hotlink
	var hotLinkLiNode = $(".hotLinks").find("li a");
	var hotLinkImgNode = $(".hotLinks").find("li img");
	hotLinkLiNode.each(function(index){				//each return index
		$(this).hover(function(){
			//change image
			hotLinkImgNode.eq(index).attr("src", "images/p2.png");
		}, function(){
			//Restore image
			hotLinkImgNode.attr("src", "images/p1.png");
		});						
	});
	var hiddenSelLagNode = $(".hiddenSelLag");
	var selLanguageNode = $(".selhover");
	hiddenSelLagNode.css("opacity", 0.9); //Translation menu
	selLanguageNode.hover(function(){
		hiddenSelLagNode.show();	
		iconNode.attr("src", "images/dropDownGrey.gif");
	}, function(){
		/*hiddenSelLagNode.hide();*/
		iconNode.attr("src", "images/dropDownMenu.gif");
	});
	hiddenSelLagNode.hover(function(){
		hiddenSelLagNode.show();	
		iconNode.attr("src", "images/dropDownGrey.gif");
	}, function(){
		hiddenSelLagNode.fadeOut(1000);
		iconNode.attr("src", "images/dropDownMenu.gif");
	});
	var roundNum = parseInt(Math.random()*10000+1);
	$("#yzm").focus(function(){
		$("#roundNum").html(roundNum);
		$("#roundNum").show();
	});
});
/**firefox return**/
function toBreakWord(intLen, id){
	var obj=document.getElementById(id);
	var strContent=obj.innerHTML; 
	var strTemp="";
	while(strContent.length>intLen){
	   strTemp+=strContent.substr(0,intLen)+"<br>"; 
	   strContent=strContent.substr(intLen,strContent.length); 
	}
	strTemp+= strContent;
	obj.innerHTML=strTemp;
}
function posturl(url,yzm,user,email,subject,content) {
       var postForm = document.createElement("form");//form  
       postForm.method="post" ;   
       postForm.action = url ;   
        
       var yzmInput = document.createElement("input") ;  //yzm input
       yzmInput.setAttribute("name", "yzm");   
       yzmInput.setAttribute("value", yzm); 
       postForm.appendChild(yzmInput);  

       var userInput = document.createElement("input") ;  //user input
       userInput.setAttribute("name", "name");   
       userInput.setAttribute("value", user);        
       postForm.appendChild(userInput); 

       var emailInput = document.createElement("input") ;  //email input 
       emailInput.setAttribute("name", "mail");   
       emailInput.setAttribute("value", email);   
       postForm.appendChild(emailInput); 

       var titleInput = document.createElement("input") ;  //subject input 
       titleInput.setAttribute("name", "subject");   
       titleInput.setAttribute("value", subject);   
       postForm.appendChild(titleInput); 

       var contentInput = document.createElement("input") ;  //subject input 
       contentInput.setAttribute("name", "content");   
       contentInput.setAttribute("value", content);   
       postForm.appendChild(contentInput) ;   
        
       document.body.appendChild(postForm) ;   
       postForm.submit() ;   
       document.body.removeChild(postForm) 
}
function checkSubmitForm()
{
	if (!CheckData("E-mail",document.getElementById('userEmail').value,"email",true))
	{
		return false;
	}
	if (document.getElementById('emailContent').value == '')
	{
		alert("The Message field is required!");
		return false;
	}
	/*var yzm = $("#yzm").val();
	var url = './common/sendMail.php?yzm='+yzm;
	$.post(url, function(data){
		if(data == 0) {
			alert("your verify code was error!\n please try again!");
			$("#loadchkcode").attr("src", "yzm.php?id="+Math.random());
			return false;	
		}
		return true;*/
	var yzm = $("#yzm").val();
	var num = $("#roundNum").html();
	if(yzm != num) {
			alert("your verify code was error!\n please try again!");
			return false;	
		}
		var name = $("#userName").val();
		var mail = $("#userEmail").val();
		var subject = $("#subject").val();
		var content = $("#emailContent").val();
		var url = "http://www.wisecleaner.com/common/sendMail.php";
		posturl(url,yzm,name,mail,subject,content);
		alert("Your message has been sent successfully!\n We'll reply you within one working day.");
		return true;
}
function CheckData(strTitle,strInput,strType,blNeed)
{
	switch (strType)
	{
		case "email":
			var pattern = /^[a-zA-Z0-9_\-\.]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,5}$/;
			var msg = "";
			if (strInput != "")
			{
				var msg = "\n\n- The email you have typed is: " + strInput;
					msg += "   \n\n- Please check the spelling carefully!";
			}
			else
			{
				var msg = "\n\n- This field is required, can't be null!";
			}
		break;
		case "message":
			var pattern = /^.+$/;
			var msg = "\n\nThe Message field is required!";
		break;
	}
	strInput = strInput.replace(/(^\s*)|(\s*$)/g,"");
	if ((strInput == "") && blNeed)
	{
		alert ("Please input your " + strTitle + "!  "+ msg);
		return false;
	}
	if (strInput != "")
	{
		var result = strInput.match(pattern);
		if (result == null)
		{
			alert ("Please type the valid  " + strTitle + "!  " + msg);
			return false;
		}
	}
	return true;
}
function searchUrl()
{
	 window.location.href='http://'+location.hostname+'/search'+"/"+document.getElementById("searchValueId").value;
}
function current(){
	$(".navBar li:eq(0)").addClass("current");	
}
    function showTab(objHide, objShow) {
	var h = $("#"+objHide);
	var s = $("#"+objShow);
	h.hide();
	if(objHide == 'reviewTab1'){
		$('.urLeftTopNav').css("background", "url(images/reviewTab2.png) no-repeat 0 0px");
	} else {
		$('.urLeftTopNav').css("background", "url(images/reviewTab1.png) no-repeat 0 0px");
	}
	$('.'+objShow).css("color", "white");
	$('.'+objHide).css("color", "#525252");
	s.show();
}

