function isblank(s)
{
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function CheckEmail(strEmail) {
	var i;
	var getChar;


	if ((Left(strEmail, 1) == "@") || (Right(strEmail, 1) == "@") )
		return false;
	

		getChar = 0;
	for (i = 0 ; i < strEmail.length ; i++ ) {
		if (strEmail.charAt(i)=='@'){
			getChar++;
		}
	}	    

	if ( getChar != 1 )
		return false;

	var email1;
	var email2;
	var temail;
	
	temail = strEmail.split('@')
	email1 = temail[0].replace(/\s/g, "");
	email2 = temail[1].replace(/\s/g, "");	
	
	var cemail;
	cemail = strEmail;
	cemail = cemail.replace(/\@/g, "");	
	cemail = cemail.replace(/\./g, "");	
	
	if (cemail.length == 0)
		return false;
	
	var allow;
	allow = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
	for(i = 0 ; i < cemail.length; i++ )
		if (allow.indexOf(cemail.charAt(i)) < 0 )
			return false;

	if (Left(email1, 1) == '.')
		return false;

	
	if (Left(email2, 1) == '.' || Right(email2, 1) == '.' || email2.replace(/\./g, "").length == email2.length)
		return false;

	if (email2.indexOf("..") >= 0 )
		return false;

	if (Left(email2, 1) == '-' || Right(email2, 1) == '-')
		return false;

	if (Left(email2, 1) == '_' || Right(email2, 1) == '_')
		return false;
	
	return true;
}	

function Left( sourceStr, charIdx ) {
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(0, charIdx);
}

function Right( sourceStr, charIdx ) {	
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(sourceStr.length-charIdx, sourceStr.length);
}

function ram_form(a,b)
{
	if(document.getElementById(b).value == ""){
		alert("E-mail Address is Required. ");
		return false;
	}
	if(!CheckEmail(document.getElementById(b).value)){
		alert("An Error occurred. Please enter a correct email address. ");
		return false;
	}
	if(document.getElementById(a).checked == false){
		alert("Please check agreement box before you move forward. ");
		return false;
	}
}

function ram_form2(a,b)
{
	var len = a.length;
	var checked = false;
	for (i = 0; i < len; i++){
		if(document.trainingForm.product[i].checked == true){
			checked = true;
			break;
		}
	}    
	if (!checked){ 
		alert("Product You Use or Sell is Required."); 
		return false; 
	} 
	if(document.getElementById(b).value == ""){
		alert("E-mail Address is Required. ");
		return false;
	}
	if(!CheckEmail(document.getElementById(b).value)){
		alert("An Error occurred. Please enter a correct email address. ");
		return false;
	}
}



// Check Register
function check_info(e)
{
	var msg;
	var textAll = "Please check your Personal Information.";
	var textfn="";
	var textln="";
	var textdb="";
	var textem="";
	var textad1="";
	var textad2="";
	var textct="";
	var textsp="";
	var textzp="";
	var textpw="";
	var textusername="";
	var fg=1;
	var vg=1;
	
	if ((e.username.value == null) || (e.username.value == "") || isblank(e.username.value)) { textusername = "Username is Required.\n";}
	if ((e.first_name.value == null) || (e.first_name.value == "") || isblank(e.first_name.value)) { textfn = "First Name is Required.\n";}	
	if ((e.last_name.value == null) || (e.last_name.value == "") || isblank(e.last_name.value)) { textln = "Last Name is Required.\n";}
	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 
		}
	if (fg) {
	 if (e.email.value != e.email_confirm.value) { textem = "Email address does not match.\n"; }
	}
	if ((e.address1.value == null) || (e.address1.value == "") || isblank(e.address1.value)) {textad1 = "Address1 is Required.\n";}
    if ((e.zip.value == null) || (e.zip.value == "") || isblank(e.zip.value)) { textzp = "Zip or Post Code is Required.\n"; }
	if ((e.city.value == null) || (e.city.value == "") || isblank(e.city.value)) { textct = "City is Required.\n";}
	if(e.input_select.value == 'select')
	{
		if ((e.entry_state.value == 'Choose One') || (e.entry_state.value == "") || isblank(e.entry_state.value)) { textsp = "State is Required.\n";}
			if (e.entry_state.style) e.entry_state.style.backgroundColor = textsp != "" ? '#ffffcc':'#FFFFFF';
	}
	else
	{
		if ((e.entry_state_input.value == "") || isblank(e.entry_state_input.value)) { textsp = "State is Required.\n";}
		if (e.entry_state_input.style) e.entry_state.style.backgroundColor = textsp != "" ? '#ffffcc':'#FFFFFF';
	}
	if ((e.password.value == null) || (e.password.value == "") || isblank(e.password.value)) { textpw = "Password is Required.\n"; vg=0;}
	if (vg) {
	 if (e.password.value != e.confirmation.value) { textpw = "Passowrd does not match.\n"; }
	}	


	if (e.username.style) e.username.style.backgroundColor = textusername != "" ? '#ffffcc':'#FFFFFF';
	if (e.first_name.style) e.first_name.style.backgroundColor = textfn != "" ? '#ffffcc':'#FFFFFF';
	if (e.last_name.style) e.last_name.style.backgroundColor = textln != "" ? '#ffffcc':'#FFFFFF';
	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#ffffcc':'#FFFFFF';
	if (e.address1.style) e.address1.style.backgroundColor = textad1 != "" ? '#ffffcc':'#FFFFFF';
	if (e.zip.style) e.zip.style.backgroundColor = textzp != "" ? '#ffffcc':'#FFFFFF'; 
	if (e.city.style) e.city.style.backgroundColor = textct != "" ? '#ffffcc':'#FFFFFF';
	if (e.password.style) e.password.style.backgroundColor = textpw != "" ? '#ffffcc':'#FFFFFF';
	if (e.confirmation.style) e.confirmation.style.backgroundColor = textpw != "" ? '#ffffcc':'#FFFFFF';
	
	if ((textfn == "") && (textln == "") && (textem == "") && (textad1 == "") && (textzp == "") && (textct == "") && (textsp == "")   && (textpw == "") && (textusername == "")) 
		{ 
			//e.submit();
			registerCheckUserName(e.username.value);
			return true;
		}
	
	if (textfn && textln && textem && textad1 && textzp && textct && textsp && textpw && textusername) {
		msg =  textusername + textpw + textfn + textln +  textad1 + textct  + textsp + textzp + textem ;
	} else {
		msg =  textusername + textpw + textfn + textln +  textad1 + textct  + textsp + textzp + textem ;
	}		
	alert(msg);
	return false;
}

// Check expert
function check_expert(e)
{
	var msg;
	var textAll = "Please check your Information.";
	var textname="";
	var textemail="";
	var texttitle="";
	var textcompany="";
	var textphone="";
	var textbusiness="";
	var fg=1;
	
	if ((e.name.value == null) || (e.name.value == "") || isblank(e.name.value)) { textname = "Name is Required.\n";}
	if ((e.title.value == null) || (e.title.value == "") || isblank(e.title.value)) { texttitle = "Title is Required.\n";}	
	if ((e.company.value == null) || (e.company.value == "") || isblank(e.company.value)) { textcompany = "Company is Required.\n";}
	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textemail = "E-mail Address is Required.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.email.value)) { textemail = "An Error occurred. Please enter a correct email address. \n";} 
	}
	if ((e.phone.value == null) || (e.phone.value == "") || isblank(e.phone.value)) {textphone = "Phone# is Required.\n";}
	if ((e.business_type.value == 'Choose One') || (e.business_type.value == "") || isblank(e.business_type.value)) { textbusiness = "Business Type is Required.\n";}

	if (e.name.style) e.name.style.backgroundColor = textname != "" ? '#ffffcc':'#FFFFFF';
	if (e.title.style) e.title.style.backgroundColor = texttitle != "" ? '#ffffcc':'#FFFFFF';
	if (e.company.style) e.company.style.backgroundColor = textcompany != "" ? '#ffffcc':'#FFFFFF';
	if (e.email.style) e.email.style.backgroundColor = textemail != "" ? '#ffffcc':'#FFFFFF';
	if (e.phone.style) e.phone.style.backgroundColor = textphone != "" ? '#ffffcc':'#FFFFFF';
	if (e.business_type.style) e.business_type.style.backgroundColor = textbusiness != "" ? '#ffffcc':'#FFFFFF';
	
	if ((textname == "") && (texttitle == "") && (textcompany == "") && (textemail == "") && (textphone == "") && (textbusiness == "")) 
		{ 
			e.submit();
			return true;
		}
	
	if (textname && texttitle && textcompany && textemail && textphone && textbusiness) {
		msg =  textname + texttitle + textcompany + textemail + textphone + textbusiness ;
	} else {
		msg =  textname + texttitle + textcompany + textemail + textphone + textbusiness ;
	}		
	alert(msg);
	return false;
}

// Check Newsletter
function check_newsletter(e)
{
	var msg;
	var textAll = "Please check your Personal Information.";
	var textfn="";
	var textln="";
	var textem="";
	
	if ((e.first_name.value == null) || (e.first_name.value == "") || isblank(e.first_name.value)) { textfn = "First Name is Required.\n";}	
	if ((e.last_name.value == null) || (e.last_name.value == "") || isblank(e.last_name.value)) { textln = "Last Name is Required.\n";}
	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 
		}
	if (fg) {
	 if (e.email.value != e.email_confirm.value) { textem = "Email address does not match.\n"; }
	}

	if (e.first_name.style) e.first_name.style.backgroundColor = textfn != "" ? '#ffffcc':'#FFFFFF';
	if (e.last_name.style) e.last_name.style.backgroundColor = textln != "" ? '#ffffcc':'#FFFFFF';
	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#ffffcc':'#FFFFFF';
	
	if ((textfn == "") && (textln == "") && (textem == "") ) 
		{ 
			e.submit();
//			registerCheckUserName(e.username.value);
			return true;
		}
	
	if (textfn && textln && textem) {
		msg =  textfn + textln + textem ;
	} else {
		msg =  textfn + textln + textem ;
	}		
	alert(msg);
	return false;
}

// Check Update
function check_update_info(e)
{
	var msg;
	var textAll = "Please check your Personal Information.";
	var textfn="";
	var textln="";
	var textem="";
	var textad1="";
	var textct="";
	var textsp="";
	var textzp="";
	var textpw="";
	var textphone="";
	var fg=1;
	var vg=1;
	
	if ((e.password.value == null) || (e.password.value == "") || isblank(e.password.value)) { vg=0;}
	if (vg) {
	 if (e.password.value != e.password2.value) { textpw = "Passowrd does not match.\n"; }
	}
	if ((e.firstname.value == null) || (e.firstname.value == "") || isblank(e.firstname.value)) { textfn = "First Name is Required.\n";}	
	if ((e.lastname.value == null) || (e.lastname.value == "") || isblank(e.lastname.value)) { textln = "Last Name is Required.\n";}
	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 
	}
	if ((e.address1.value == null) || (e.address1.value == "") || isblank(e.address1.value)) {textad1 = "Address1 is Required.\n";}
      if ((e.zip.value == null) || (e.zip.value == "") || isblank(e.zip.value)) { textzp = "Zip or Post Code is Required.\n"; }
	if ((e.city.value == null) || (e.city.value == "") || isblank(e.city.value)) { textct = "City is Required.\n";}
	if(e.country.value == 211){
		if ((e.state_s.value == '0') || (e.state_s.value == "") || isblank(e.state_s.value)) { textsp = "State or Province is Required.\n";}
	}else{
		if ((e.state.value == '0') || (e.state.value == "") || isblank(e.state.value)) { textsp = "State or Province is Required.\n";}
	}
	if ((e.tel.value == null) || (e.tel.value == "") || isblank(e.tel.value)) { textphone = "Phone is Required.\n";}	
//
//	
	if (e.password.style) e.password.style.backgroundColor = textpw != "" ? '#ffffcc':'#FFFFFF';
	if (e.password2.style) e.password2.style.backgroundColor = textpw != "" ? '#ffffcc':'#FFFFFF';
	if (e.firstname.style) e.firstname.style.backgroundColor = textfn != "" ? '#ffffcc':'#FFFFFF';
	if (e.lastname.style) e.lastname.style.backgroundColor = textln != "" ? '#ffffcc':'#FFFFFF';
	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#ffffcc':'#FFFFFF';
	if (e.address1.style) e.address1.style.backgroundColor = textad1 != "" ? '#ffffcc':'#FFFFFF';
	if (e.zip.style) e.zip.style.backgroundColor = textzp != "" ? '#ffffcc':'#FFFFFF'; 
	if (e.city.style) e.city.style.backgroundColor = textct != "" ? '#ffffcc':'#FFFFFF';
	if(e.country.value == 211){
		if (e.state.style) e.state.style.backgroundColor = textsp != "" ? '#ffffcc':'#FFFFFF';
	}else{
		if (e.state_s.style) e.state_s.style.backgroundColor = textsp != "" ? '#ffffcc':'#FFFFFF';
	}
	if (e.tel.style) e.tel.style.backgroundColor = textphone != "" ? '#ffffcc':'#FFFFFF';
	
	if (textfn == "" && textln == "" && textem == "" && textad1 == "" && textzp == "" && textct == "" && textsp == ""   && textpw == "" && textphone == "") 
	{ 
			e.submit();
			return true;
	}else {
		msg = textfn + textln + textem + textad1 + textzp + textct  + textsp + textpw + textphone ;
	}		
	alert(msg);
	return false;
}


// Check Login
function check_login(e)
{
	var msg;
	var textun="";
	var textpw="";
	var fg=1;

	if ((e.username.value == null) || (e.username.value == "") || isblank(e.username.value)) { textun = "User Name is Required.\n"; fg=0;}
	
	
	
	if ((e.password.value == null) || (e.password.value == "") || isblank(e.password.value)) { textpw = "Password is Required.\n"; }
		
	if (e.username.style) e.username.style.backgroundColor = textun != "" ? '#ffffcc':'#FFFFFF';
	if (e.password.style) e.password.style.backgroundColor = textpw != "" ? '#ffffcc':'#FFFFFF';
	
	if (textun == "" && textpw == "") 
	{ 
		e.submit(); 
		//loginCheckEmail();
		return true; 
	}
	else { msg = textun+textpw;	} 
	
	alert(msg);
	return false;
}

// Fogot pw
function fogotPw(e)
{
	var msg;
	var textun="";
	var textem="";
	var fg=1;
	if ((e.username.value == null) || (e.username.value == "") || isblank(e.username.value)) { textun = "User Name is Required.\n"; fg=0;}
	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 
		}
		
	if (e.username.style) e.username.style.backgroundColor = textun != "" ? '#ffffcc':'#FFFFFF';
	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#ffffcc':'#FFFFFF';
	
	if (textun == "" && textem == "") 
	{ 
		e.submit(); 
		//loginCheckEmail();
		return true; 
	}
	else { msg = textun+textem;	} 
	
	alert(msg);
	return false;
}


// contact Us
function contactUs(e)
{
	var msg;
	var textun="";
	var textem="";
	var textinquiry="";
	var fg=1;
	if ((e.you_name.value == null) || (e.you_name.value == "") || isblank(e.you_name.value)) { textun = "Your name is Required.\n"; fg=0;}
	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "Your E-mail is Required.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 
		}
	if ((e.inquiry.value == null) || (e.inquiry.value == "") || isblank(e.inquiry.value)) { textinquiry = "Your Inquiry is Required.\n"; fg=0;}
		
	if (e.you_name.style) e.you_name.style.backgroundColor = textun != "" ? '#ffffcc':'#FFFFFF';
	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#ffffcc':'#FFFFFF';
	if (e.inquiry.style) e.inquiry.style.backgroundColor = textinquiry != "" ? '#ffffcc':'#FFFFFF';
	
	if (textun == "" && textem == "" && textinquiry == "") 
	{ 
		e.submit(); 
		//loginCheckEmail();
		return true; 
	}
	else { msg = textun+textem+textinquiry;	} 
	
	alert(msg);
	return false;
}


function js_jump2(a,link,search)
{
//	alert(a.value);
	if(a.value){
		window.location = "./" + link + ".php?"+search+"="+a.value;
	}else{
		window.location = "./" + link + ".php";
	}
}

function js_jump3(a,link,act,search)
{
//	alert(a.value);
	if(a.value){
		window.location = "./" + link + ".php?act="+act+"&"+search+"="+a.value;
	}else{
		window.location = "./" + link + ".php?act="+act;
	}
}

function showPic(id){
	var pic = document.getElementById(id);

	var img = new Image();
	img.src = pic.src;
//	alert($(obj).src);



//	alert(pic.src);
//	alert(getstr2(pic.src))//or document.write(getstr(url); 
	if(getstr(pic.src) == "noimg1"){
		pic_src = getstr2(pic.src) + "/noimg3.jpg";
	}else{
		pic_src = pic.src;
	}

	var topHat = document.getElementById("topHat");

	if(img.width >= img.height){
		topHat.setAttribute('width',344);
		topHat.setAttribute('height',344*img.height/img.width);
	}else{
		topHat.setAttribute('height',221);
		topHat.setAttribute('width',221*img.width/img.height);
	}
//	alert(img.height);
	topHat.setAttribute("src", pic_src);

}

function getstr(str) 
{ 
stag=str.lastIndexOf('/'); 
etag=str.lastIndexOf('.'); 
rstr=str.substring(stag+1,etag); 
return rstr 
} 

function getstr2(str) 
{ 
stag=str.lastIndexOf('/'); 
etag=str.lastIndexOf('.'); 
rstr=str.substring(0,stag); 
return rstr 
} 



// Check change pw
function check_change_pw(e)
{
	var msg;
	var textun="";
	var textpw="";
	var fg=1;

	if ((e.username.value == null) || (e.username.value == "") || isblank(e.username.value)) { textun = "User Name is Required.\n"; }
	if ((e.pw.value == null) || (e.pw.value == "") || isblank(e.pw.value)) { textpw = "Password is Required.\n"; fg=0;}
	if (fg) {
	 if (e.pw2.value != e.pw.value) { textpw = "Password does not match.\n"; }
	}
		
	if (e.username.style) e.username.style.backgroundColor = textun != "" ? '#ffffcc':'#FFFFFF';
	if (e.pw.style) e.pw.style.backgroundColor = textpw != "" ? '#ffffcc':'#FFFFFF';
	
	if (textun == "" && textpw == "") 
	{ 
		e.submit(); 
		//loginCheckEmail();
		return true; 
	}
	else { msg = textun+textpw;	} 
	
	alert(msg);
	return false;
}



function check_update_term(e)
{
	/*
	if(!e.i_agree.checked)
	{
		alert('Please agree to charge this amount.');
		e.i_agree.style.backgroundColor = '#ffffcc';
		return false;
	}
	*/
	e.submit();
}

//jerome check case reply

function check_case_reply(e)
{
	var msg;
	var textcm="";

	if((e.case_comments.value == null) || (e.case_comments.value == "") || isblank(e.case_comments.value)){ textcm = "Comments is Required.\n"; }

	if (textcm) e.case_comments.style.backgroundColor = '#FFCC66';
	
	if (textcm == "" ) 
	{ 
		e.submit(); 
		//loginCheckEmail();
		return true; 
	}
	else { msg = textcm;	} 
	
	alert(msg);
	return false;
}