/*fasson.js
* by Julianne Reid for Fasson Roll Aust & NZ
* Copyright (c) 2001 Collaborative Developments Pty Ltd. All Rights Reserved.
*/

function searchDB(path,query) {
	path+="?SearchView&Query="+query+"&Start=1&Count=10";
	window.location.href = "/"+path;     
}

function searchDBReturn(path,query) {
	path+="?SearchView&Query="+query+"&Start=1&Count=10";
	window.location.href = "/"+path;
        return false;
}

function searchInventory(path,product,quantity) {
       if (product == "") {
            alert("Product Code cannot be blank.");
            return false;
       } else {
             if (quantity == "") {
                  alert("Quantity cannot be blank.");
                  return false;
             } else {
                  // location search
	          path+="?SearchView&Query=Field+ProductCode+Contains+"+product+"+AND+Field+AvailableStock>="+quantity+"&Start=1&Count=10";
	          window.location.href = "/"+path;       
                  return false;          
             }
       }
}

function searchJobs(path,location,category) {
       if (location == "" && category == "") {
            alert("A location or category must be selected.");
            return false;
       } else {
              if (location != "" && category != "") {
                     path+="?SearchView&Query=Field+JobCategory+Contains+"+category+"+AND+Field+SearchLocation+Contains+"+location+"&Start=1&Count=10";
	             window.location.href = "/"+path;
                     return false;
              } else {
                   if (location == "") {
                       // category search
	               path+="?SearchView&Query=Field+JobCategory+Contains+"+category+"&Start=1&Count=10";
	               window.location.href = "/"+path;    
                       return false;         
                  } else {
                       // location search
	               path+="?SearchView&Query=Field+SearchLocation+Contains+"+location+"&Start=1&Count=10";
	               window.location.href = "/"+path;
                       return false;
                  }
             }
       }
}

function validateContactForm() {
	var strError="";
	if (document.forms['ContactForm'].reqname.value == "") {
		strError="Name \n";
	       } 
	 if (document.forms['ContactForm'].company.value == "") {
            strError += "Company \n"
       }       
	       
		if ((document.forms['ContactForm'].country[document.forms['ContactForm'].country.selectedIndex].value =="others"

	&& document.forms['ContactForm'].othersbox.checked==false) || (document.forms['ContactForm'].othersbox.checked 
	&& document.forms['ContactForm'].otherscountry.value=="")) {
	 			   strError += "Country \n"
	}
		if(document.forms['ContactForm'].officecountry.value=="" || document.forms['ContactForm'].officearea.value=="" || document.forms['ContactForm'].office.value=="")
		              
		       	{
		  		strError += "Office No. with Country Code & Area Code\n"
						   
	}
	  
	       if (document.forms['ContactForm'].reqemail.value == "") {
	       	        	strError += "Email \n"
	       	       }
	       
	if(strError=='')		
	{
              	  return true;  
	}
	else
	{
		alert('The following field(s) cannot be empty \n\n' + 	strError)	
		return false;
	}

}

function validateOrderForm() {
	if (document.forms[1].reqname.value == "") {
            alert("Name cannot be blank.");
            return false;
       } else {
             if (document.forms[1].reqemail.value == "") {
                  alert("Email cannot be blank.");
                  return false;
             } else {
                  if (document.forms[1].productcode.value == "" && document.forms[1].description.value == "")  {
                       alert("Product Code and Description cannot be blank.");
                       return false;
                   } else {
                         if (document.forms[1].quantity.value == "") {
                              alert("Order Quantity cannot be blank.");
                              return false;
                         } else {
                              return true;
                         }
                   }
             }
       }
}

function validateRegistrationForm() {
	if (document.forms[1].txtCustomerNo.value == "") {
            alert("Customer No. cannot be blank.");
            return false;
       } else {
             if (document.forms[1].txtCompanyName.value == "") {
                  alert("Company Name cannot be blank.");
                  return false;
             } else {
                  if (document.forms[1].txtContactFirstName.value == "" && document.forms[1].txtContactLastName.value == "")  {
                       alert("Contact Name cannot be blank.");
                       return false;
                   } else {
                         if (document.forms[1].txtEmail.value == "") {
                              alert("Email cannot be blank.");
                              return false;
                         } else {
                              return true;
                         }
                   }
             }
       }
}

function openPopUpHelp(pageurl,name) {
	 window.open(pageurl,name, 'width=607,height=508,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=no');
        return false;
}

function validateCustomerRegistrationForm() {
	var strError="";
	if (document.forms['RegistrationForm'].name.value == "") {
	strError="Name \n";
       } 
     if (document.forms['RegistrationForm'].company.value == "") {
            strError += "Company \n"
       }
       
       
       if(document.forms['RegistrationForm'].officecountry.value=="" || document.forms['RegistrationForm'].officearea.value=="" || document.forms['RegistrationForm'].office.value=="")
              
       	{
  		strError += "Office No. with Country Code & Area Code\n"
				   
	}
	/*if(document.forms['RegistrationForm'].officearea.value=="")
	              
	{
		strError += "Office No. Area Code \n"
					   
	}
	
	if(document.forms['RegistrationForm'].office.value=="")
		              
	{
		strError += "Office No. \n"
						   
	}*/
	
	if(document.forms['RegistrationForm'].useremail.value=="")
	              	{
	         		strError += "Email \n"
	       				   
	}
	
	if(strError=='')		
	{
              	 //document.forms[0].submit();
              	 return true;
	}
	else
	{
		alert('The following field(s) cannot be empty \n\n' + 	strError)
		return false;
	}

}

function validateForgetPasswordForm()
{
	if(document.forms['ForgetPasswordForm'].UserEmailID.value=="")
	{
		alert("Email ID cannot be blank");
		return false;
	}
	else
	{
	return true;
	}
}
function OpenGlossaryView(id)
{
	document.getElementById(id).className = "here"; 
}
function ProductCodeSearch()
{
	if(document.forms['sproductcode'].Query.value=='')
		alert('Enter a product code or keyword(s)');
	else
		document.sproductcode.submit();
}
function QuickSearch(intStartNumber, strQuery, strType)
{
	document.forms['SearchForm'].Query.value=strQuery;
	switch(strType)
	{
		case 'previous' : document.forms['SearchForm'].Start.value=intStartNumber-20;
break;
		case 'next' : document.forms['SearchForm'].Start.value=intStartNumber+20;
break;
		case 'page' : document.forms['SearchForm'].Start.value=(((intStartNumber-1)*20)+1);
break;		

	}
	document.forms['SearchForm'].submit();
}
function callSubmit(strForm) 
{	
	var form = document.forms[strForm];

	if (  trimString(form.username.value)  == '' &&  form.password.value == '')
	{
		alert ('Enter Username and Password');
		form.username.focus(); 
		form.username.select();
		return false;
	}
	if (  trimString(form.username.value)  == ''  )
	{
		alert ('Enter the User Name');
		form.username.focus(); 
		form.username.select();
		return false;
	}
	if (  form.password.value == '' )
	{
		alert ('Enter the Password');
		form.password.focus(); 
		form.password.select();
		return false;
	}
	form.submit();
}

function trimString (str) 
{
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function DataSheetSearch(intStartNumber, strQuery, strType)
{
	document.forms['sproductcode'].Query.value=strQuery;
	switch(strType)
	{
		case 'previous' : document.forms['sproductcode'].Start.value=intStartNumber-20;
break;
		case 'next' : document.forms['sproductcode'].Start.value=intStartNumber+20;
break;
		case 'page' : document.forms['sproductcode'].Start.value=(((intStartNumber-1)*20)+1);
break;		

	}
	document.forms['sproductcode'].submit();
}

function OpenContactFormPopup(strContactEmailID, strCountryID)
{
	
	var loc = window.location.href.toLowerCase();
	strDBURL = loc.match(/(.*)?\.nsf/gi);
	var sLocation = "/ContactUsPopupForm?OpenForm&ContactEmail=" + strContactEmailID + "&CountryID=" + strCountryID
	sLocation = strDBURL  + sLocation
	var params = "width=585,height=510 , resizable=no,location=no,toolbar=no,menubar=no";
	var oNewWindow = window.open(sLocation, "ContactUs", params);

}


function ShowUserName(strUserName)

{
	if (strUserName =="Anonymous")
	{
		document.getElementById('SignLogIn').style.display="block";
		document.getElementById('SignLogout').style.display="none";
	}
	else
	{
		document.getElementById('SignLogIn').style.display="none";
		document.getElementById('SignLogout').style.display="block";
		var objUser = document.getElementById("SignInUser");
		objUser.innerHTML=strUserName ;
	}
}

function checkcountry() {
	if (document.getElementById('othersbox').checked == true) {
		document.getElementById('country').disabled = true;
		document.getElementById('otherscountry').disabled = false;
	} else {
		document.getElementById('country').disabled = false;
		document.getElementById('otherscountry').disabled = true;
	}
}

//end
