
function doSubmit()
{
	var flag=true;
	if(!txt_TitleCheck())
	{
		flag=false;
	}
	
	/*if(!CheckBrief())
	{
		flag=false;
	}*/
	
	if(!CheckDescription())
	{
	flag=false;
	}
	
	if(!CheckMemberInfo())
	{
	flag=false;
	}
	return flag;
}


//check title
function txt_TitleCheck()
{
	CtoH( 'txtTitle');
	if( isEmpty( GE('txtTitle').value.trim()) == true)
	{
		SetError( "txtTitle","block","Please enter a buying leads title.");
		return false;
	}
	else if( includeChineseChar( GE('txtTitle').value) == false)
	{
		SetError( "txtTitle","block","Sorry, the information you filled in is not in English.");
		return false;
	}
	else if(!CheckLength(GE("txtTitle"),100))
	{
		SetError( "txtTitle","block","Buying Lead Title can not be more than 100 characters.");
		return false;
	}
	else
	{
		SetError( "txtTitle","none","");
		return true;
	}
}

// check brief
function CheckBrief()
{
	CtoH('txtBrief');
	if( isEmpty( GE('txtBrief').value) == true)
	{
		SetError( "txtBrief","block","Please enter a brief description. ");
		return false;
	}
	else if( GE('txtBrief').value.length > 128)
	{
		//GE('txtBrief').value = GE('txtBrief').value.substring(0,128);
		SetError( "txtBrief","block","Sorry, the brief description information you filled in exceeds the limit(from 4 to 128 characters).");
		return false;
	}
	else if( includeChineseChar( GE('txtBrief').value) == false)
	{
		SetError( "txtBrief","block","Please enter English.");
		return false;
	}
	else
	{
		SetError( "txtBrief","none","");
		return true;
	}
}

//check description
function CheckDescription()
{
//CtoH('txta_Description');
	if( isEmpty( GE('txtDescript').value) == true)
	{
		SetError( "txtDescript","block","Please do not enter HTML code directly. ");
		return false;
	}
	else if( GE('txtDescript').value.length < 20)
	{
		SetError( "txtDescript","block","Additional Description must be 20 characters at least.");
		return false;
	}
	else
	{
		SetError( "txtDescript","none","");
		return true;
	}
	/*if( includeChineseChar( GE('txta_Description').value) == false)
	{
		SetError( "txta_Description","block","Please enter English.");
		return false;
	}
	else if( GE('txta_Description').value.length > 8000)
	{
		SetError( "txta_Description","block","The information you filled exceeds the limit.");
		return false;
	}
	else
	{
		SetError( "txta_Description","none","");
	}*/
}

function txt_MinPriceCheck()
{
	CtoH('txt_MinPrice');
	if( isDigitDot( GE('txt_MinPrice').value.trim()) == false )
	{
		SetError( "txt_MinPrice","block","Please enter a number.");
		return false;
	}
	else
	{
		SetError( "txt_MinPrice","none","");
		return true;
	}
}
function txt_MaxPriceCheck()
{
	CtoH('txt_MaxPrice');
	var ii = GE('txt_MaxPrice').value.trim() - GE('txt_MinPrice').value.trim();
	if( isDigitDot( GE('txt_MaxPrice').value.trim()) == false )
	{
		SetError( "txt_MaxPrice","block","Please enter a number.");
		return false;
	}
	/*else if( parseInt( GE('txt_MinPrice').value) > parseInt( GE('txt_MaxPrice').value) )
	{
		SetError( "txt_MaxPrice","block","Sorry, the latter price must be larger than the former one.");
		return false;
	}*/
	else if( GE('sel_PriceRange').value != "" && ( isEmpty( GE('txt_MinPrice').value) == true || isEmpty( GE('txt_MaxPrice').value) == true ) )	
	{
		SetError( "txt_MaxPrice","block","Please enter a price.");
		return false;
	}
	else if( GE('sel_PriceRange').value == "" && ( isEmpty( GE('txt_MinPrice').value) == false || isEmpty( GE('txt_MaxPrice').value) == false ) )	
	{
		SetError( "txt_MaxPrice","block","Please choose a type.");
		return false;
	}
	else if( ii < 0)
	{
		SetError( "txt_MaxPrice","block","Sorry, the latter price must be larger than the former one.");
		return false;
	}
	else
	{
		SetError( "txt_MaxPrice","none","");
		return true;
	}
}

function txt_QuantityCheck()
{
	CtoH('txt_Quantity');
	if( isDigit( GE('txt_Quantity').value) == false )
	{
		SetError( "txt_Quantity","block","Please enter a number.");
		return false;
	}
	if( isEmpty( GE('txt_Quantity').value) == true && GE('sel_Quantity').value != "0")
	{
		SetError( "txt_Quantity","block","Please enter a Quantity.");
		return false;
	}
	else
	{
		SetError( "txt_Quantity","none","");
	}
}
function sel_QuantityCheck()
{
	if( GE('txt_Quantity').value.trim() != "" && GE('sel_Quantity').value == "0")
	{
		SetError( "sel_Quantity","block","Please choose a unit.");
		return false;
	}
	else
	{
		SetError( "sel_Quantity","none","");
	}
}

function ShowLogin(flag)
{
	
	if(flag)
	{
		//GE("tbLogin").style.display='';
		GE("tbNologin").style.display='none';
		GE("IsMember").value=true;
		GE("radiobutton1").checked="checked";
	}
	else
	{
		//GE("tbLogin").style.display='';
		GE("tbNologin").style.display='';
		GE("IsMember").value=false;
		GE("radiobutton2").checked="checked";
	}
}

function txta_RequirementCheck()
{
	CtoH('txta_Requirement');
	if( includeChineseChar( GE('txta_Requirement').value) == false)
	{
		SetError( "txta_Requirement","block","Please enter English.");
		return false;
	}
	else if( GE('txta_Requirement').value.length > 512)
	{
		SetError( "txta_Requirement","block","The information you filled exceeds the limit.");
		return false;
	}
	else
	{
		SetError( "txta_Requirement","none","");
		return true;
	}
}

var DBCheckUserName=false;
function memberIDCheck()
{
	CtoH( 'txtMemberid');
	if( isEmpty( GE('txtMemberid').value) == true )
	{
		SetError( "txtMemberid","block","Member ID is empty.");
		return false;
	}
	else if( !checkNumberStr( GE('txtMemberid').value) )
	{
		SetError( "txtMemberid","block","Enter 6 to 20 characters (A-Z, a-z, 0-9, no spaces).");
		return false;
	}
	
	else
	{
		SetError( "txtMemberid","none","");
		if(GE("IsMember").value!='true')
		{
			CheckDBUserName( GE('txtMemberid').value);
			return DBCheckUserName;
		}
		return true;
	}
}

function CheckDBUserName( username )
{
	try
	{
		ECVV.MyECVV.Join.JoinStep2.ExistUserName( username, callbackCheckUserName );
	}
	catch(e)
	{
		SetError( "txtMemberid","block","There is something wrong for checking the member ID.");
		DBCheckUserName = false;
	}
}

function callbackCheckUserName(res)
{
	if (res.value == "0")
	{
		SetError( "txtMemberid","none","");
		DBCheckUserName = true;	
	}
	else if (res.value == "1")
	{
		SetError( "txtMemberid","block","This member ID is already registered, if you are already a member, please <a href='/MyECVV/login.html'>sign in</a> here.");
		DBCheckUserName = false;
	}					
	else
	{
		SetError( "txtMemberid","block", res.value);
		DBCheckUserName = false;
	}
}

var DBCheckEmail=false;
function emailCheck()
{
	CtoH( 'txtEmail');
	if( isEmpty( GE('txtEmail').value) == true )
	{
		SetError( "txtEmail","block","Email is empty.");
		return false;
	}
	else if( isEmail( GE('txtEmail').value) == false )
	{
		SetError( "txtEmail","block","Please enter a correct email address.");
		return false;
	}
	
	else
	{
		//SetError( "txtEmail","block","The email Checking ..");
		CheckDBEmail( GE('txtEmail').value);
		return DBCheckEmail;
	}
}


function CheckDBEmail( email )
{
	try
	{
		ECVV.MyECVV.Join.JoinStep2.ExistEmail( email, callbackCheckEmail );
		return true;
	}
	catch(e)
	{
		//SetError( "txtEmail","block","There is something wrong for checking the email.");
		DBCheckEmail = false;
	}
}

function callbackCheckEmail(res)
{
	if (res.value == "0")
	{
		SetError( "txtEmail","none","");
		DBCheckEmail = true;	
	}					
	else if (res.value == "1")
	{
		SetError( "txtEmail","block","This email is already registered, if you are already a member, please <a href='/MyECVV/login.html'>sign in</a> here.");
		DBCheckEmail = false;
	}					
	else
	{
		SetError( "txtEmail","block", res.value);
		DBCheckEmail = false;
	}
}

function checkNumberStr(str)
{ 
	s=/^[a-zA-Z0-9-_]{6,20}$/;
	if(!s.test(str))
	{ 
		return false;
	} 
	
	return true;
}

function passwordCheck()
{
	CtoH( 'txtpwd');
	if( isEmpty( GE('txtpwd').value) == true || GE('txtpwd').value.trim().length < 6)
	{
		SetError( "txtpwd","block","The password should have 6-20 characters.");
		return false;
	}
	/*
	else if( !isPasswd( GE('txtPassword').value) )
	{
		SetError( "txtPassword","block","The password should have 6-20 characters.");
		return false;
	}
	*/
	else if(GE("IsMember").value=='true')
	{
		SetError( "txtpwd","none","");
		return true;
	}
	else if( isComposite( GE('txtpwd').value) )
	{
		SetError( "txtpwd","block","The password is too simple. Consecutive or repeated numbers and letters.- e.g. 123456, abcdef, aaaaaa, 888888.");
		//return false;
		
		if( GE('txtpwdC').value == GE('txtpwd').value)
		{
			SetError( "txtpwdC","none","");
			return true;
		}
		else if( GE('txtpwdC').value != "" && GE('txtpwdC').value != GE('txtpwd').value)
		{
			SetError( "txtpwdC","block","Incorrect password");
			return false;
		}
	}
	else
	{
		SetError( "txtpwd","none","");
		
		if( GE('txtpwdC').value == GE('txtpwd').value)
		{
			SetError( "txtpwdC","none","");
			return true;
		}
		else if( GE('txtpwdC').value != "" && GE('txtpwdC').value != GE('txtpwd').value)
		{
			SetError( "txtpwdC","block","Incorrect password");
			return false;
		}
	}
}

function isSamePassword(password)
{
	var	j = 1;
	for(var i=0;i<password.length-1;i++)
	{
		if(password.substring(i,i+1) == password.substring(i+1, i+2))
		{
			j++;
		}
	}
	return j;
}

function confirmPasswordCheck()
{
	CtoH( 'txtpwdC');
	if( isEmpty( GE('txtpwdC').value) == true )
	{
		SetError( "txtpwdC","block","Please input password again");
		return false;
	}
	else if( GE('txtpwdC').value != GE('txtpwd').value)
	{
		SetError( "txtpwdC","block","Incorrect password");
		return false;
	}
	else
	{
		SetError( "txtpwdC","none","");
		return true;
	}
}

function firstNameCheck()
{
	 CtoH( 'txtFirstName');
	if( isEmpty( GE('txtFirstName').value) == true )
	{
		SetError( "txtFirstName","block","Please enter first name");
		return false;
	}
	else if( isEngEmpty( GE('txtFirstName').value.trim() ) == false )
	{
		SetError( "txtFirstName","block","Please enter your name in English.");
		return false;
	}
	else
	{
		SetError( "txtFirstName","none","");
		return true;
	}
}

function lastNameCheck()
{
	 CtoH( 'txtLastName');
	if( isEmpty( GE('txtLastName').value) == true )
	{
		//SetError( "txtLastName","block","Please enter last name");
		return true;
	}
	else if( isEngEmpty( GE('txtLastName').value.trim()) == false )
	{
		SetError( "txtLastName","block","Please enter your name in English.");
		return false;
	}
	else
	{
		SetError( "txtLastName","none","");
		return true;
	}
}

function isComposite(password){
	var numberLine = '0123456789'					// numbers
	var charLine = 'abcdefghijklmnopqrstuvwxyz'	// alpha letters
	var haveNumber=false;
	var haveChar = false;
	var haveSame = false;
	
	if( numberLine.indexOf(password)>-1){haveNumber=true;}
	if(   charLine.indexOf(password)>-1){haveChar=true;}
	
	var samePassword = isSamePassword(password);

	if( samePassword == password.length)
	{
		haveSame = true;
	}
	
	return (haveNumber || haveChar || haveSame);
}

function companyCheck()
{
	CtoH( 'txtCompanyName');
	if( isEmpty( GE('txtCompanyName').value) == true )
	{
		SetError( "txtCompanyName","block","Please enter company name");
		return false;
	}
	else if( includeChineseChar( GE('txtCompanyName').value) == false )
	{
		SetError( "txtCompanyName","block","Please enter English.");
		return false;
	}
	else
	{
		SetError( "txtCompanyName","none","");
		return true;
	}
}

function phoneCountryCodeCheck()
{
	CtoH( 'txtRegionCode');
	if( isEmpty( GE('txtRegionCode').value) == true )
	{
		
		SetError( "txtRegionCode","block","Please enter a phone countrycode");
		return false;
		
	}
	else if( isCountryCode( GE('txtRegionCode').value) == false )
	{
		SetError( "txtRegionCode","block","Incorrect phone countrycode");
		return false;
	}
	else
	{
		SetError( "txtRegionCode","none","");
		return true;
	}
}

function phoneAreaCodeCheck()
{
	CtoH( 'txtAreaCode');
	if( isEmpty( GE('txtAreaCode').value) == true )
	{
		SetError( "txtAreaCode","block","Please enter a phone areacode");
		return false;
	}
	else if( isDigit( GE('txtAreaCode').value) == false )
	{
		SetError( "txtAreaCode","block","Incorrect phone areacode");
		return false;
	}
	else
	{
		SetError( "txtAreaCode","none","");
		return true;
	}
}

function phoneNumberCheck()
{
	CtoH( 'txtNumber');
	if( isEmpty( GE('txtNumber').value) == true )
	{
		
		SetError( "txtNumber","block","Please enter a phone number");
		return false;
		
	}
	else if( isTel( GE('txtNumber').value) == false )
	{
		SetError( "txtNumber","block","Please enter numbers, dash and space only.");
		return false;
	}
	else
	{
		SetError( "txtNumber","none","");
		return true;
	}
}

function CheckSelect()
{
	if(GE("selectCountry").selectedIndex>0)
	{
		SetError( "selectCountry","none","");
		return true;
	}
	else
	{
		SetError( "selectCountry","block","Please select your country.");
		return false;
	}
	
}

function CheckMemberInfo()
{
	var flag=true;
	if(!memberIDCheck())
	{
	flag=false;
	}
	if(!passwordCheck())
	{
	flag=false;
	}
	if(GE("IsMember").value=='true')
	{
		return flag;
	}
	
	if(!confirmPasswordCheck())
	{
		flag=false;
	}
	
	if(!emailCheck())
	{
		flag=false;
	}
	
	if(!firstNameCheck())
	{
		flag=false;
	}
	
	if(!lastNameCheck())
	{
		flag=false;
	}
	
	if(!phoneCountryCodeCheck())
	{
		flag=false;
	}
	
	if(!phoneAreaCodeCheck())
	{
		flag=false;
	}
	
	if(!phoneNumberCheck())
	{
		flag=false;
	}
	
	if(!companyCheck())
	{
		flag=false;
	}
	
	if(!CheckSelect())
	{
		flag=false;
	}
	
	return flag;
	
}

function CheckLength(objValue,length)
{
	if(objValue.Length>length)
	{
		return false;
	}
	else
	{
		return true;
	}
}


//set expiry date
function SetExpiryDate()
{
	GE("hiddenExpiry").value=GE("selectExpiry").options[GE("selectExpiry").selectedIndex].value;
}

function showAndHidden()
{
	GE("trPrice").style.display=GE("trPrice").style.display=="none" ? "":"none";
	GE("trOrder").style.display=GE("trOrder").style.display=="none" ? "":"none";
	GE("trCertification").style.display=GE("trCertification").style.display=="none" ? "":"none";
	if(GE("imgShow").src.indexOf("ico02.gif")>0)
	{
		GE("imgShow").src="/newimages/sin/icon_add.gif";
	}
	else
	{
		GE("imgShow").src="/newimages/sin/ico02.gif";
	}
}
function GetBriefLength()
{
var n = GE("txtBrief").value.length;
GE("spanNum").innerHTML=n;
}