
function isnull(obj)
{
	if(obj==null)
		return true;
	else
		return false;
}

function checkAll(form) 
{
	var text = "You have to fill in all compulsary given field correctly!!"	
	//bemail = isEmail(form)
	//check = bemail
		
	check = isName(form.realname)
	
	if(check==false)
	{
		alert("The Name Field Must not be Empty")
		return false;
	}		
	
	if(!isnull(form.phonenumber))
		checkE = isNumeric(form.phonenumber)
	if(!isnull(form.faxnumber))
		checkE = checkE || isNumeric(form.faxnumber)
	if(!isnull(form.email)) 
		checkE = checkE || isEmail(form.email)
	if(checkE==false)
	{
		alert("Please Fill in at least on of these fields:\n1.Phone Number, \n2.Fax Number, \n3.Email")
		return false;
	}
	
	/*if(!isnull(form.details))
		check = check && isName(form.details)
		
	// For bulk Purchase and Special Order details	
	checkB = false
	if(!isnull(form.title))
		checkB = isName(form.title)	
	if(!isnull(form.author))
		checkB = checkB || isName(form.author)
	if(!isnull(form.publisher))
		checkB = checkB || isName(form.publisher)
	if(!isnull(form.yearPublished))
		checkB = checkB || isNumeric(form.yearPublished)
	if(!isnull(form.instrument))
		checkB = checkB || isName(form.instrument)
	if(!isnull(form.context))
		checkB = checkB || isName(form.context)
	if(!isnull(form.country))
		checkB = checkB || isName(form.country)
	if(!isnull(form.language))
		checkB = checkB || isName(form.language)
	
	
	if(!isnull(form.amount))
	{
		checkB = checkB && isNumeric(form.amount)
		
		checkB = checkB && isName(form.organization)
		checkB = checkB && isName(form.orgAddress)
		checkB = checkB && isName(form.contactPerson)
		checkB = checkB || isName(form.position)
		
		
	}
	
	check = check && checkB	*/
	if(!isnull(form.mail))
	{
		check =  check && (isName(form.mail[form.mail.selectedIndex]) || isName(form.branch[form.branch.selectedIndex]))
		if(check==false)
		{
			alert("Please Select One of the Colletion Methods.")
			return false;
		}
		if(form.mail.selectedIndex != 0) // Mailing Method is Selected
		{
			check = check && isName(form.address) 

			if(check==false)
			{
				alert("Collection Method > By Mail. --> Address Must not empty.")
				return false;
			}
			if(form.area.selectedIndex==0)
			{
				alert("Please Select the region of the country you stay.")
				return false;	
			}
			
			if(form.PaymentMethod[0].checked)
			{
				alert("Cash Payment is for SELF PICKUP  only.\n Please Choose Other Payment Method")
				return false;
			}
		}
		
	}
	if(!isnull(form.PaymentMethod))
		check = check && isRadio(form.PaymentMethod)

	if(check && checkE)
	{ 
		return true;
		//form.submit();
		//alert(window.location.pathname)
	}
	else
		alert(text)	
	
	return false;
}

function postCheck(val, val2)
{
	text = ""
	switch(val)
	{
		case 1 :  // Surface Mail
			switch(val2)
			{
				case 1: case 2: case 3: case 4:
					text=""
					break;
				default:
					text = "Surface Mail only Applied to Local, Macau, Asia, Japan and Others Country"	
					break;
				
			}
			break;
			
		case 2 :  // AirMail
			switch(val2)
			{
				case 3: case 4:
					text = ""
					break;
				default:
					text = "Air Mail only Applied to Asia, Japan and Others Country"
					break;
			}
			break;
			
		case 3 :  case 4: // SpeedPost and Courier Service
			switch(val2)
			{
				case 3: case 5: case 6: case 7: case 8: 
					text = ""
					break;
				default:
					text = "SpeedPost and Courier Service only Applied "
					break;
					text = text + " to Asia, USA, Canada, Europe and Others Country"
			}
			break;
		default:
			text = "Doesn't Apply"
			break;
	}
	return text
}

function isRadio(obj)
{
	i=0;
	while(!isnull(obj[i]))
	{	
		if(obj[i].checked)
			return true;
		i = i+1
	}
	return false;
}
function isEmail(obj) 
{
	if((obj.value == "" || obj.value.indexOf('@', 0) == -1) || obj.value.indexOf('.') == -1) 
		return false;
	else 
		return true;
}



function isName(obj) 
{
	if(obj.value == "") 
		return false;
	else 
		return true;
}

function isNumeric(obj) 
{
	
	ph = obj.value
	
	num = true
	if(ph == "") 
		return false;
	else 
	{
		for(i=0; i < ph.length ; i++)
		{
			switch(ph.charAt(i))
			{
				case '0': case '1': case '2': case '3': case '4':
				case '5': case '6': case '7': case '8': case '9':
					num =true;
					break;
				default:
					return false;
					
			}
		}
		return num
	}
}


function checkC22Form(form)
{
	var check
	check = checkAll(form)
	
	if(!check)
		return false;
	
	else if(!isName(form.Title) && !isName(form.Author))
	{
		alert("Please Provide some information about:\n 1.Title OR\n2. Author")
		return false;
	}
	return true;
}

function checkC24Form(form)
{
	var check
	check = checkAll(form)
	
	if(!check)
		return false;
	
	else if(!isName(form.Enquires))
	{
		alert("Please Let's Us know your enquires! \n Thank You")
		return false;
	}
	return true;
}

function checkC64Form(form)
{
	var check
	check = checkAll(form)
	
	if(!check)
		return false;
	
	else if(!isName(form.referenceNumber) || !isName(form.problemDetails))
	{
		alert("Please Provide The Following Information:\n1.Refence Number AND \n 2.Details of the Problems")
		return false;
	}
	return true;
}
