﻿// JScript 文件



//var hostname = "192.168.18.3/JMWeb_v2.0";

//var hostname = "www.jmwoodenhandle.com";

var hostname = location.host;

var idGoDown="";

var idDiv="";



var objDIV1;

var objDIV2;



function CreateOverlay()

{

	Overlay.OverlayEntirelyOn(document.body,"ol1","#777",true,0.5);

    objDIV1 = Overlay.CreateOverlay();

    var top = 700;
    if(location.href.indexOf("index.htm")>=0 ||location.href.indexOf("products.htm")>=0||location.href.indexOf("about-us.htm")>=0||location.href.indexOf("service.htm")>=0)
		top = 430;

    Overlay.OverlayPartiallyOn(document.body,"ol2",400,220,top,500,"",false);

    objDIV2 = Overlay.CreateOverlay();
		
		var textareaLen = "0px";
		if(navigator.appName.indexOf("Microsoft Internet Explorer")>=0)
			textareaLen = "210px;";
		else
			textareaLen = "216px;";
		


	     var validatecodeImgUrl = "http://"+hostname+"/generatevcode.php?ID=" + Math.random();

	     var strHtmlHeader="<p class=\"ovl_line1\"></p><p class=\"ovl_line2\"></p><p class=\"ovl_line3\"></p><p class=\"ovl_line4\"></p>";

         var strHtmlFooter="<p class=\"ovl_line4\"></p><p class=\"ovl_line3\"></p><p class=\"ovl_line2\"></p><p class=\"ovl_line1\"></p>";

        var strHtml = "<form style=\"padding:0px;margin:0px;\">"+"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"tbcontent\">"+"<tr><td colspan=\"4\">"+strHtmlHeader+"</td></tr>"+"<tr bgcolor=\"#9ACD32\" ><td align=\"center\" colspan=\"4\">Please complete the form listed below to get in touch with a JM Rep. </td></tr>"+
"<tr bgcolor=\"#9ACD32\"><td colspan=\"4\" style=\"height:5px;\">&nbsp;</td>"+
"<tr bgcolor=\"#9ACD32\"><td>&nbsp;</td><td>Contacts</td><td><input id=\"namepost\" name=\"namepost\" type=\"text\" size=\"30\" value=\"\"  /></td><td>&nbsp;</td></tr>"+

"<tr bgcolor=\"#9ACD32\"><td>&nbsp;</td><td>Email</td><td><input id=\"emailpost\" name=\"emailpost\" type=\"text\" size=\"30\" value=\"\" /></td><td>&nbsp;</td></tr>"+

"<tr bgcolor=\"#9ACD32\"><td>&nbsp;</td><td>Comments/Inquiries</td><td><textarea id=\"interestedProducts\" name=\"interestedProducts\"  value=\"\" style=\"width:"+textareaLen+""+"height:80px;\"></textarea></td><td>&nbsp;</td></tr>"+

"<tr bgcolor=\"#9ACD32\"><td>&nbsp;</td><td></td><td><input style=\"float:right;color:#000; border:0px;\" type=\"button\" size=\"30\" value=\"Submit\" onclick=\"CheckValidationOfRequestPDF();\" onmouseover=\"this.className='bt_submit_mouseover'\" /></td><td>&nbsp;</td></tr>"+

"<tr bgcolor=\"#9ACD32\"><td>&nbsp;</td><td></td><td colspan=\"2\" id=\"status\"></td></tr>"+"<tr bgcolor=\"#9ACD32\"><td>&nbsp;</td><td align=\"center\" colspan=\"2\"><a href=\"http://www.jmwoodenhandle.com/get-in-touch-with-a-jm-rep.htm\">Can't submit the form?</a>&nbsp;&nbsp;&nbsp;<a style=\"text-decoration:none;color:white;\" href=\"javascript:;\" onclick=\"javascript:CloseOverlay();\">Close</a></td><td>&nbsp;</td></tr>"+
"<tr bgcolor=\"#9ACD32\" ><td colspan=\"4\" >&nbsp;</td></tr><tr><td  colspan=\"4\">"+strHtmlFooter+"</td></tr>"+

"</table>"+
"</form>";



    objDIV2.innerHTML=strHtml;


}


/*
function getVcode()

{

	document.getElementById("validatorImg").src="http://"+hostname+"/generatevcode.php?ID=" + Math.random();

}

function checkVcode()

{

	

	document.getElementById("status").innerHTML="<div><img alt=\"\" src=\"Imgs/ajax-loader.gif \" /></div>";

			  

	var objParams = new Object();

	objParams.parameters = new Object();

	objParams.parameters.vercode = document.getElementById("vercode").value;

	
	HTTP.get("http://"+hostname+"/checkVcode.php",checkVcode_callback,objParams);

}

function checkVcode_callback(value)

{

	if(value.isPassed=="true"){



            sendEmailSync();

		}

	else{

		 alert("the input was incorrect,please try again.");

		 document.getElementById("status").innerHTML="";

          document.getElementById("vercode").value="";

          document.getElementById("vercode").focus();

          return false;

	}

}
*/



function CloseOverlay()

{

    Overlay.RemoveOverlay(objDIV2);

    Overlay.RemoveOverlay(objDIV1);

}









function IsFillMsg(obj)

{

   //idDiv=obj.name.split("|||")[0];

  // idGoDown=obj.name.split("|||")[1];

   CreateOverlay();

}





/*****************************************js cookies operations apis [begin]**************************/

function getCookie(sName)

{

    var sRE = "(?:;)?"+sName+"=([^;]*);?";

    var oRE =  new RegExp(sRE);

    

    if(oRE.test(document.cookie))

    {

        return decodeURIComponent(RegExp["$1"]);

    }

    else

    {

        return null;

    }



}



function setCookies(sName,sValue,oExpires,sPath,sDomain,bSecure)

{

    var sCookies = sName + "=" + encodeURIComponent(sValue);

    

    if(oExpires){

        sCookies += "; expires=" + oExpires.toGMTString();

    }

    if(sPath){

        sCookies += "; path=" + sPath;

    }

    if(sDomain){

        sCookies +="; domain=" + sDomain;

    }

    if(bSecure){

        sCookies +="; secure";

    }

    

    document.cookie = sCookies;

}



/*****************************************js cookies operations apis [end]**************************/

function isEmail(strEmail) {
if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
return false;
}

function validateSubmit()

{

    if(trim(document.getElementById("namepost").value)=="")

    {

        alert("please enter your name.");

        document.getElementById("namepost").focus();

        return;

    }

    if(trim(document.getElementById("emailpost").value)=="")

    {

        alert("please enter e-mail.");

        document.getElementById("emailpost").focus();

        return false;

    }else 
	{
		if(!isEmail(trim(document.getElementById("emailpost").value)))
		{
			alert("please enter a valid e-mail address.");
			  document.getElementById("emailpost").focus();
			  return false;
		}
	}

    if(trim(document.getElementById("interestedProducts").value)=="")
    {

        alert("please enter Comments/Inquiries.");

        document.getElementById("interestedProducts").focus();

        return false;

    }
 	return true;

}



function CheckValidationOfRequestPDF()
{
	var isValid = true;
	isValid = validateSubmit();

		if(isValid){
		    document.getElementById("status").innerHTML="<div><img alt=\"\" src=\"Imgs/ajax-loader.gif \" /></div>";
		    sendEmailSync();
		}


}

  function sendEmailSync()

    {



        var strContacts = document.getElementById("namepost").value;

        var strEmail = document.getElementById("emailpost").value;

        var strInterPrds=document.getElementById("interestedProducts").value;



	var postBodyContents = {"namepost":strContacts,"emailpost":strEmail,"interestedProducts":strInterPrds};



	HTTP.post("http://"+hostname+"/sendemailrequestcatalog.php",postBodyContents,sendEmailSync_CallBack,null);

	



        

    }

    

function trim(str)

{

	return str.replace(/(^\s*)|(\s*$)/g, "");  

}

	

function sendEmailSync_CallBack(r)
{

		if(trim(r)=="1"){

            CloseOverlay();

			alert("Thank you, we'll contact you shortly.");

			  if(location.href.indexOf("index.htm")<0 ||location.href.indexOf("products.htm")<0||location.href.indexOf("about-us.htm")<0||location.href.indexOf("service.htm")<0)
				document.getElementById("pdf_wrap").innerHTML = "";

	}else

    {
       // document.getElementById("status").innerHTML="";

         alert("Sorry, Please Re-send it later.");
      
    }



}




