if(document.location.search != ''){
	tempStr = document.location.search.replace('?', '').split('&');
	p_SelectedMenu = '';
	category = '';
	for(i=0; i<tempStr.length; i++){
		if(tempStr[i].indexOf('category')!=-1) {
			category = tempStr[i].split('=')[1] ;
		}
		if(tempStr[i].indexOf('SelectedMenu')!=-1){
			p_SelectedMenu = tempStr[i].split('=')[1] ;
			p_SelectedMenu = decodeURI(p_SelectedMenu);
		}
	}
	if(category == '' || category == undefined){
		category = 'plastic';
	}
}else{
	p_SelectedMenu = 'home';
}
	//alert(document.location.search.replace('?', '').split('&'));

/*
remove to menu_array.jsp for dynamic generate the right side menu
HM_Array0 = [
//["Home", "../index/home.html", "pub", "" ],
["Company Profile",  "../index/com_profile.jsp", "pub", "" ],
["Product Collection",  "../index/products.jsp", "pri", ""],
["News and Events",  "../index/news_and_events.jsp", "pub", "" ],
["Contact Us",  "../index/contactus.jsp", "pub", "" ],
["Member Zone",  "../index/member_zone.jsp", "pub", "" ]
]
*/

/*
HM_Array0_1 = [
["New for This Fall", "javascript:void(0)", "pri", 1],
["Classic Collection", "javascript:void(0)", "pri", 1 ]
]

HM_Array0_1_0 = [
["Metal", "../index/products.html?category=metal", "pri", "" ],
["Plastic", "../index/products.html?category=plastic", "pri", "" ],
["Titanium", "javascript:void(0)", "pri", "" ],
["Sunglass", "javascript:void(0)", "pri", "" ]
]

HM_Array0_1_1 = [
["Metal", "javascript:void(0)", "pri", "" ],
["Plastic", "javascript:void(0)", "pri", "" ],
["Titanium", "javascript:void(0)", "pri", "" ],
["Sunglass", "javascript:void(0)", "pri", "" ]
]
*/


function ItemReturn(tmpAry, styleNum){

	andOrQuestion = (tmpAry[1].indexOf('?') != -1 ) ? '&' : '?';
	pmrSelItem = (tmpAry[1].indexOf('javascript:void(') != -1) ? '' : andOrQuestion + 'SelectedMenu=' + tmpAry[0] ;
	U_TmpStr = '';
/*
	if(tmpAry[tmpAry.length-2] == 'pri' ){
		if(getCookie('HASLOGIN') == 'true'){
			U_TmpStr = U_TmpStr  + "		<tr><td class='menuItem_" + styleNum + "' valign='top' ><img src='../images/left_menu_bullet.gif' ><a href='" + tmpAry[1] + pmrSelItem + "' style='color:black' >" + tmpAry[0] + "</a></td></tr>" ;
		}
	}else{
*/
		U_TmpStr = U_TmpStr  + "		<tr><td class='menuItem_" + styleNum + "' valign='top' ><img src='../images/left_menu_bullet.gif' ><a href='" + tmpAry[1] + pmrSelItem + "' style='color:black' >" + tmpAry[0] + "</a></td></tr>" ;
//	}
	return U_TmpStr ;
}

function sideMenu(selStr){
	//--------selStr------ 0_1_1
	//HasLogined = false;
	sideMu = "";
	sideMu = "	<table width=100% height=100% border=0 cellspacing=0 cellpadding=0  >" ;
	sideMu = sideMu + "		<tr><td height=1 ><img height=15 src='../images/spacer.gif' ></td></tr>" ;
	for(i=0;i<HM_Array0.length;i++){
		if(HM_Array0[i][HM_Array0[i].length-1] == 1 ){
			sideMu = sideMu + ItemReturn(HM_Array0[i], 0);
			selAry = eval('HM_Array0_'+i);
			for(k=0;k<selAry.length;k++){
				sideMu = sideMu + ItemReturn(selAry[k], 1);
				if(selAry[k][selAry[k].length-1] ==  1 ){
					selAry2 = eval('HM_Array0_'+ i + '_' + k);
					for(z=0;z<selAry2.length;z++){
						sideMu = sideMu + ItemReturn(selAry2[z], 2);
					}
				}
			}
		}else{
			//ItemReturn();
			sideMu = sideMu + ItemReturn(HM_Array0[i], 0);
			//sideMu = sideMu + "		<tr><td class='menuItem_0' ><img src='../images/left_menu_bullet.jpg' ><a href='" + HM_Array0[i][1] + "' style='color:white' >" + HM_Array0[i][0] + "</a></td></tr>" ;
		}
	}
	sideMu = sideMu + "		<tr><td class=menuItemRightBorder >&nbsp;</td></tr>"+
								  "	</table>" +
								"</td>" +
								"<td width=1 style='background-color:#CCCCCC' ><img src='../images/spacer.gif' height=1  >";
	return sideMu;
}

/*
function submitLogin(){
	setCookie('HASLOGIN', 'true');
	//window.location.reload();
	window.location = '../index/home.html';
}
*/

function submitLogout(){
//	setCookie('HASLOGIN', 'false');
	window.location = '../login.do?method=doLogout';
}

/*
remove to menu_Array.jsp for dynamic generate the right side menu
tpMenu_Array = [
["Home", "../index/home.jsp" ],
["Logout", "javascript:submitLogout()"]
]
*/
function DateObject(){
	dateObj = new Date();
	s = dateObj.getDate() + " /";
	s += (dateObj.getMonth() + 1) + " /";
	s += dateObj.getYear();
	return(s);	
}

function tpMenu(){
	tpMuStr = "";
	tpMuStr = "	<table width=100% height=100% border=0 cellspacing=0 cellpadding=0  >" +
					"		<tr>" +
					"		<td style='background-color:#1D1C82' colspan=2 ><img src='../index/spacer.gif' width='1' height='3' ></td>" +
					"		</tr>" +
					"		<tr>" +
					"			<td bgcolor=white class='menuWidth logoTopBg' align=center  ><img src='../images/spacer.gif' ></td>" +
					"			<td bgcolor=#F3F2F7 style=text-align:right >" +
					"				<table height=100% border=0 cellspacing=0 cellpadding=0  bgcolor=#F0F0F0 >" +
					"					<tr>" +
					"						<td width=1 ><img src='../images/tr_menu_corner.jpg' ></td>" +
					"						<td style=font-size:7pt ><img src='../images/spacer.gif' >" ;
					for(i=0;i<tpMenu_Array.length;i++){
						tpMuStr = tpMuStr + "<img src='../images/spacer.gif' width=8 height=5   ><a href='" + tpMenu_Array[i][1] + "' >" + tpMenu_Array[i][0] + "</a>";
						tpMuStr = tpMuStr + "<img src='../images/spacer.gif' width=8 height=5   >|";
					}	
					tpMuStr = tpMuStr + "<img src='../images/spacer.gif' width=8 height=5 >" + DateObject() + 
					"						</td>" +
					"						<td>" +
					"							<img src='../images/spacer.gif' width=10 height=5 >" +
					"						</td>" +
					"					</tr>" +
					"				</table>" +
					"			</td>" +
					"		</tr>" +
					"	</table>" ;

		return tpMuStr;
}

function header(){
		headerStr = "";
		headerStr = "	<table width=100% height=100% border=0 cellspacing=0 cellpadding=0  >														" +
							"		<tr>																																									" +
							"			<td bgcolor=white class=menuWidth align=center  ><img src='../images/hoitat_logo.jpg' ></td>			" +
							//"			<td width=1 bgcolor=#F7F7F7 ><img src='../images/spacer.gif' height=1  ></td>									" +
							"			<td bgcolor=white style='padding-top:0;background-image:url(../images/header_bg.jpg);background-position-x:right;background-repeat:repeat-y' ><img style='margin-left:7' src='../images/header_text.gif' ></td> 	" +
							"		</tr>																																								" +
							"	</table>																																								" ;
		return headerStr;
}

function navBar(){
	navBar = "";
	navBar = "	<table width=100% height=100% border=0 cellspacing=0 cellpadding=0  >"+
					"	<tr>"+
					//"		<td bgcolor=white class='menuWidth logoBottomBg' align=center  ><img src='../images/spacer.gif' ></td>"+
					//"		<td width=1 bgcolor=#CCCCCC ><img src='../images/spacer.gif' height=1  ></td>"+
					"		<td bgcolor=#000073 style=\"background-image:url(../images/nav_menu_corner.jpg);background-repeat: no-repeat;background-position-x:right\" >"+
					"			<table width=100% height=100% border=0 cellspacing=0 cellpadding=0  >"+
					"				<tr>"+
					"					<td class='navBarUrlTextColor' >"+

					"					<img src='../images/spacer.gif' height=1  width=10 ><a class='navBarUrlTextColor' href='../index/home.jsp?SelectedMenu=home' >Home</a>" ;

					for(i=0; i<HM_Array0.length; i++){
						if(HM_Array0[i][0] == p_SelectedMenu){
							navBar = navBar + "					<img src='../images/spacer.gif' height=1  width=5 >>";
							navBar = navBar + "					<img src='../images/spacer.gif' height=1  width=5 class='navBarUrlTextColor' >" + HM_Array0[i][0] ;
						}
					}

					navBar = navBar + "					</td>"+
					"					<td style='padding:3 0 3 0;text-align:center;width:80px;color:black' ><a href='http://webmail.hoitat.com' target='_blank' ><img src=\"../images/btn/btn_webmail.gif\" border=0 ></a></td>"+
					"				</tr>"+
					"			</table>"+
					"		</td>"+
					"	</tr>"+
					" </table>";
	return navBar;
}


function bmMu(){
	bmMuStr = "";
	bmMuStr = "	<table width=100% height=100% border=0 cellspacing=0 cellpadding=0  >"+
							"<tr><td height=1 bgcolor=#000073 colspan=2 ><img src='../images/spacer.gif' height=1' ></td></tr>"+
							"<tr><td height=1 bgcolor=#F0F0F0 colspan=2 ><img src='../images/spacer.gif' height=1  ></td></tr>"+
							"<tr><td height=1 bgcolor=#3B80B9 colspan=2 ><img src='../images/spacer.gif' height=1  ></td></tr>"+
						"		<tr>"+
						"			<td width=50% align=left valign=top class='footerUrl'>"+
						//"					<img src='../images/spacer.gif' height=20 width=10  >Privacy"+
						//"					<img src='../images/spacer.gif' height=1 width=5  >|"+
						"					<img src='../images/spacer.gif' height=20 width=10 ><a class='footerUrl' href='../index/terms_of_use.jsp' >Terms of Use</a>"+
						"					<img src='../images/spacer.gif' height=1 width=5  >|"+
						"					<img src='../images/spacer.gif' height=1 width=5  ><a class='footerUrl' href='../index/sitemap.jsp' >Sitemap</a>"+
						"					<img src='../images/spacer.gif' height=1 width=5  >|"+
						"					<img src='../images/spacer.gif' height=1 width=5  ><a class='footerUrl' href='../index/feedback.jsp' >Site Feedback</a>"+
						"			</td>"+
						"			<td width=50% align=right valign=top class='footerUrl' ><img src='../images/spacer.gif' >"+
						"				&copy; 2005 Hoitat Optical Manufactory Ltd."+
						"			<img src='../images/spacer.gif' height=20 width=10  >"+
						"			</td>"+
						"		</tr>"+
						"	</table>";
	return bmMuStr;
}

/*
rightMuArray = [
['Metal', 'M', true],
['Plastic', '999', true],
['Titanium', '', false],
['Sunglass', '', false]
]
*/

function rightMuHtmlStr(index){
	if (rightMuArray[index][2]){
		return "<tr><td style=vertical-align:middle;padding:3 0 3 15 ><img src=\'../images/bulet_1.gif\' >&nbsp;<a href=\'../product.do?method=displayProductByCategory&SelectedMenu=" + p_SelectedMenu + "&category=" +  rightMuArray[index][1] + "\' >" +  rightMuArray[index][0] + "</td></tr>";
	}
	else {
		return "<tr><td style=vertical-align:middle;padding:3 0 3 15 ><img src=\'../images/bulet_1.gif\' >&nbsp;" +  rightMuArray[index][0] + "</td></tr>";
	}
}

function rightMu(prodCatMenu){
	rightMuStr ='';

	if(prodCatMenu){
		rightMuStr = "<table class=rightMuInnerWidth border=0 cellspacing=2 cellpadding=3  >"+
							"<tr><td align=center style=background-color:#DDDDDD ><b>Product Collection</b></td></tr>"+
							"<tr><td style=padding:10 0 10 10 >"+
							"<table height=100% width=100% border=0 cellspacing=2 cellpadding=3  >"+
							"<!-- tr><td style=background-color:#EEEEEE >New for This Fall</td></tr -->";
							
		for(i=0; i<rightMuArray.length; i++ ){
			rightMuStr += rightMuHtmlStr(i);
		}
/*		
							"<tr><td style=vertical-align:middle;padding:3 0 3 15 ><img src=\'../images/bulet_1.gif\' >&nbsp;<a href=\'products.jsp?SelectedMenu=" + p_SelectedMenu + "&category=metal\' >Metal</td></tr>"+
							"<tr><td style=vertical-align:middle;padding:3 0 3 15 ><img src=\'../images/bulet_1.gif\' >&nbsp;<a href=\'products.jsp?SelectedMenu=" + p_SelectedMenu + "&category=plastic\' >Plastic</a></td></tr>"+
							"<tr><td style=vertical-align:middle;padding:3 0 3 15 ><img src=\'../images/bulet_1.gif\' >&nbsp;Titanium</td></tr>"+
							"<tr><td style=vertical-align:middle;padding:3 0 3 15 ><img src=\'../images/bulet_1.gif\' >&nbsp;Sunglass</td></tr>"+
*/

			rightMuStr += "</table>"+
							"</td></tr>"+
							"<tr><td align=center style=background-color:#DDDDDD ><img src='../images/spacer.gif' width=135 height=10 ></td></tr>" +
							"</table>";
	}
	return rightMuStr;
}


/*
ModelAry = [

['m', 'Matal', 'M2310', 'Mat Brown', 'MBN14B-T(MBN7B)-174', '50-19-135', 'p_'],
['m', 'Matal', 'M2533', 'Pink', 'PK810A-SM17297', '52-18-135', 'p_'],
['m', 'Matal', 'M2539S', 'Mat Gun Metal', 'MGM9B-3016-L.GN', '56-18-125', 'p_'],
['m', 'Matal', 'M2540', 'Mat Gun Metal', 'MGM162B-BC(OY86)', '56-18-125', 'np_'],
['m', 'Matal', 'M2542', 'Pink', 'PK960A', '53-18-135', 'p_'],
['m', 'Matal', 'M2574S', 'Mat Blue', 'MBL12B-DGY/LEM', '54-18-135', 'p_'],
['m', 'Matal', 'M2696', 'Blue', 'GABL(M12)B-3016', '48-19-135', 'np_'],
['m', 'Matal', 'M2704', 'Rose Gold', 'RG2A-FT(PR(A7)A)', '50-19-135', 'np_'],
['m', 'Matal', 'M2714', 'Antique Sliver', 'GASV1A', '48-18-135', 'np_'],
['m', 'Matal', 'M2717S', 'Brown', 'BN851A-ME914', '56-17-130', 'p_'],
['m', 'Matal', 'M2745', 'Gun Metal', 'GM162A', '48-19-135', 'np_'],
['m', 'Matal', 'M2788', 'Rose Gold', 'RG1A/F(128)', '51-18-135', 'np_'],

['999', 'Plastic', '4860S', 'Purple', 'CT4-17319-(S823/35P)', '56-20-135', 'p_'],
['999', 'Plastic', '4896', 'Black', 'ELH5903-GY', '57-18-125', 'p_'],
['999', 'Plastic', '4910', 'Light Green', 'E1453/P1202-8641', '54-18-140', 'p_'],
['999', 'Plastic', '4912', 'Red', 'E2378/3017-S571', '53-18-140', 'p_'],
['999', 'Plastic', '4914S', 'Purple', 'E2647/P1208(0292/TF)', '52-18-140', 'p_'],
['999', 'Plastic', '4962', 'Brown & Blue', 'CT3-17331', '48-16-135', 'p_'],
['999', 'Plastic', '4965', 'Red', 'RG1A-3192', '52-16-135', 'p_'],
['999', 'Plastic', '5062S', 'Pink', 'CT4-17322(GN)', '53-16-135', 'p_'],
['999', 'Plastic', '5176', 'Black', 'ELH5601', '50-17-135', 'np_']
]

*/



function prodItemHtmlStr(icount){
	o_tmpStr = '';
/*
		if(ModelAry[icount][ModelAry[icount].length-1].indexOf('np_') != -1){
			photoPath = 'notAvailable';
		}else{
			photoPath = ModelAry[icount][2].toLowerCase();
		}
*/
	o_tmpStr = o_tmpStr + '<tr><td width=150 ><a href=\'../index/product_details.jsp?modelNo=' + ModelAry[icount][2] + '\' ><img border=0 lowsrc=\'../images/bulet_1.gif\' src=\'../images/products/' + ModelAry[icount][6] + '_thumb.jpg\' ></a></td>';
	o_tmpStr = o_tmpStr + '<td valign=top ><table border=0 cellspacing=2 cellpadding=3  >';
	o_tmpStr = o_tmpStr + '<tr><td width=70 ><b>Model No.</b></td><td>' + ModelAry[icount][2] + '</td></tr>';
	o_tmpStr = o_tmpStr + '<tr><td><b>Color</b></td><td>' + ModelAry[icount][3] + '</td></tr>';
	o_tmpStr = o_tmpStr + '<tr><td colspan=2 ><a href=\'../index/product_details.jsp?modelNo=' + ModelAry[icount][2] + '\' ><b>Details Information</b></a></td></tr>';
	o_tmpStr = o_tmpStr + '</table>';
	o_tmpStr = o_tmpStr + '</td></tr>';
	return o_tmpStr;
}

function prodItem(material, modelNo){
	returnStr = '';
	returnStr = returnStr + '<table width=100% border=0 cellspacing=2 cellpadding=3  >';

	for(i=0; i<ModelAry.length; i++ ){
		if(material == 'all' || material.toUpperCase() == ModelAry[i][0].toUpperCase()){
			if(modelNo != '' && modelNo != undefined && modelNo != 'all' ){
				if( modelNo == ModelAry[i][2]){
					returnStr = returnStr +prodItemHtmlStr(i);
				}
			}else{
					returnStr = returnStr +prodItemHtmlStr(i);
			}
		}
	}

	returnStr = returnStr + '</table>';

	return returnStr ;
}

function prodItemDetail(modelNo){

	for(i=0; i<ModelAry.length; i++ ){
		if(ModelAry[i][2] == modelNo){
			t_material = ModelAry[i][1];
			t_modelNo = ModelAry[i][2];
			t_color = ModelAry[i][3];
			t_colorCode = ModelAry[i][4];
			t_size = ModelAry[i][5];

			photoPath =ModelAry[i][6];
		}
	}



	p_tmpStr = '';
	p_tmpStr = p_tmpStr + '<table width=100% border=0 cellspacing=2 cellpadding=3  >';
	p_tmpStr = p_tmpStr + '<tr><td >';
	p_tmpStr = p_tmpStr + '<p align=right ><img src=\'../images/products/' + photoPath + '.jpg\' ><img src=\'../images/btn/btn_zoom.gif\' border=0 onclick=\'PopUpWindow(\"products_pop_img.jsp?modelNo=" + photoPath + "\", \"pic_image\" )\' style=\'cursor:hand;margin:0 8 0 10 \'></p>';
	p_tmpStr = p_tmpStr + '</td></tr>';
	p_tmpStr = p_tmpStr + '<tr><td valign=top ><table class=prodDetBorder width=100% border=0 cellspacing=2 cellpadding=3  >';
	p_tmpStr = p_tmpStr + '<tr><td width=150 class=prodDetCol1 ><b>Model No.</b></td><td class=prodDetCol2  >' + t_modelNo + '</td></tr>';
	p_tmpStr = p_tmpStr + '<tr><td class=prodDetCol1 ><b>Material</b></td><td class=prodDetCol2  >' + t_material + '</td></tr>';
	p_tmpStr = p_tmpStr + '<tr><td class=prodDetCol1 ><b>Color</b></td><td class=prodDetCol2  >' + t_color + '</td></tr>';
	p_tmpStr = p_tmpStr + '<tr><td class=prodDetCol1 ><b>Color Code</b></td><td class=prodDetCol2  >' + t_colorCode + '</td></tr>';
	p_tmpStr = p_tmpStr + '<tr><td class=prodDetCol1 ><b>Size</b></td><td class=prodDetCol2  >' + t_size + '<br></td></tr>';
	p_tmpStr = p_tmpStr + '</tr></table>';
	p_tmpStr = p_tmpStr + '</td></tr>';
	p_tmpStr = p_tmpStr + '</table>';

	return p_tmpStr ;
}







/*
|--------------------------------------------------------------------------------------------------	|
| Pop up a browser window 																			|
|--------------------------------------------------------------------------------------------------	|
*/

function PopUpWindow(theURL,winName,width,height,CloseParent) { //v2.0

	windowBorder = 6;
	windowTitleHeight = 24;
	myWidth  = parseInt(width);
	myHeight = parseInt(height);

	if (isNaN(myWidth)) {
		myWidth = screen.AvailWidth - (windowBorder*2) ;
		//myWidth = 788;
	}

	if (isNaN(myHeight)) {
		myHeight = screen.AvailHeight  -  windowTitleHeight  -  windowBorder;
		//myHeight = 542;
	}

	var winLeft = ((screen.AvailWidth - windowBorder*2) -  myWidth ) / 2 ;
  	var winTop = (screen.AvailHeight -  windowTitleHeight - windowBorder - myHeight ) / 2 ;
  	//var winLeft = (screen.width - myWidth) / 2 -2;
  	//var winTop = (screen.height - myHeight) / 2 - 26;
  	features = 'fullscreen=0;location=no,toolbar=no,' + 'width=' + myWidth + ',height=' + myHeight + ',top=' + winTop + ',left=' + winLeft + ',directories=no,status=no,scrollbars=no,resizable=yes,menubar=no';
	var Temp_Window_Obj;
	var tmp_w_flag = '';

	Temp_Window_Obj = window.open(theURL, winName, features);
	Temp_Window_Obj.focus();
	if(CloseParent != undefined){
		window.top.close();
	}

//	window.self.location.href = theURL;

}


/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

//getCookie("usefulLink")
//setCookie("usefulLink", "true", );


//+ Check enter key ----------------------------------------------------------
function EnterSubmit(func){
	if(event.keyCode == 13){
		func();
	}	
}



 function emailCheck (emailStr) {

 var checkTLD=1;

 var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

 var emailPat=/^(.+)@(.+)$/;

 var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

 var validChars="\[^\\s" + specialChars + "\]";

 var quotedUser="(\"[^\"]*\")";

 var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

 var atom=validChars + '+';

 var word="(" + atom + "|" + quotedUser + ")";

 var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

 var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

 var matchArray=emailStr.match(emailPat);

 if (matchArray==null) {

 //alert("Email address seems incorrect (check @ and .'s)");
 return false;
 }
 var user=matchArray[1];
 var domain=matchArray[2];

 for (i=0; i<user.length; i++) {
 if (user.charCodeAt(i)>127) {
 //alert("Ths username contains invalid characters.");
 return false;
    }
 }
 for (i=0; i<domain.length; i++) {
 if (domain.charCodeAt(i)>127) {
 //alert("Ths domain name contains invalid characters.");
 return false;
    }
 }

 if (user.match(userPat)==null) {

 //alert("The username doesn't seem to be valid.");
 return false;
 }

 var IPArray=domain.match(ipDomainPat);
 if (IPArray!=null) {

 for (var i=1;i<=4;i++) {
 if (IPArray[i]>255) {
 //alert("Destination IP address is invalid!");
 return false;
    }
 }
 return true;
 }

 var atomPat=new RegExp("^" + atom + "$");
 var domArr=domain.split(".");
 var len=domArr.length;
 for (i=0;i<len;i++) {
 if (domArr[i].search(atomPat)==-1) {
 //alert("The domain name does not seem to be valid.");
 return false;
    }
 }

 if (checkTLD && domArr[domArr.length-1].length!=2 &&
 domArr[domArr.length-1].search(knownDomsPat)==-1) {
 //alert("The address must end in a well-known domain or two letter " + "country.");
 return false;
 }

 if (len<2) {
 //alert("This address is missing a hostname!");
 return false;
 }

 return true;
 }


 //--------------------------------------------------------------------------------------------------------------------

