/*
	Script name	: cp-common.js
	Location	: 
	Contents	: validation / common functions for channel partner sites
	Creator		: Dmitri Kushak <dmitri.kushak@globalx.com.au>
*/

/* ++++ COMMON VARIABLES SECTION
   Common error messages and other shared info goes here
   -------------------------------------------------------------------------
*/

/* ---- COMMON VARIABLES SECTION */


/* --------------------------------------------------------------------------
   Function	: dispDisclaimer
   Purpose	: displays a channel partner disclaimer
*/
function dispDisclaimer()
{
	var Disclaimer='';
	document.write(Disclaimer);
}

/* --------------------------------------------------------------------------
   Function	: dispCopyright
   Input	: String 'cpname': channel partner name to display
   Purpose	: displays a channel partner copyright info
*/
function dispCopyright( cpname )
{
	var curYear	= new Date().getFullYear();
	var Copyright	= '<div class="copyright">&copy;&nbsp;'+cpname+',&nbsp;'+curYear+'</div>';

	document.write(Copyright);
}

/* --------------------------------------------------------------------------
   Function	: checkRegForm()
   Purpose	: checks the fields in the CP registration form
*/
function checkRegForm()
{
	var regForm	= document.forms.FormReg;
	var company	= regForm.company.value;
	var street	= regForm.street.value;
	var postcode	= regForm.postcode.value;
	var contact	= regForm.contact.value; 
	var email	= regForm.email.value;
	var phone	= regForm.telephone.value;
	var fax		= regForm.fax.value;
	var recipient	= regForm.recipient.value;
	var regcode	= regForm.verification_code.value;
	var errMsg	= "Please specify";

	// This means that the template has not been configured for the particular channel partner
	if (recipient=='Default')	{ alert( "Recipient=Default, form misconfigured"); return false; }

	if (company=='')       { alert( errMsg+" the company name");   regForm.company.focus(); return false; }
//	if (street=='')        { alert( errMsg+" the address");        regForm.street.focus(); return false; }
//	if (postcode=='')      { alert( errMsg+" a postcode");         regForm.postcode.focus(); return false; }
//	if (contact=='')       { alert( errMsg+" a contact name");     regForm.contact.focus(); return false; } 
//	if (email=='')         { alert( errMsg+" an email address");   regForm.email.focus(); return false; }
//	if (phone=='')         { alert( errMsg+" a phone number");     regForm.telephone.focus(); return false; }
//	if (fax=='')           { alert( errMsg+" a fax number");       regForm.fax.focus(); return false; }
//	if (regcode!='zM&')    { alert( errMsg+" the spam prevention code"); regForm.verification_code.focus(); return false; }

 // TBC:
 //  - Check postcode - digits only
 //  - CHeck email (must have @ and one dot in the domain part
 //  - Check phone/fax (no alphanumeric symbols)
 //  - Check ABN/ACN, postcode - must be numbers (?)

	return true;
}

/* --------------------------------------------------------------------------
   Function	: dispDate()
   Purpose	: displayes curretn date
*/
function dispDate()
{
	var d		= new Date();
	var weekday	= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var monthname	= new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var dateText	= weekday[d.getDay()] + ", " + d.getDate() + " " + monthname[d.getMonth()] + " " + d.getFullYear();

	document.write( dateText );
}

function checkManRequestForm()
{
	var manForm	= document.forms.manReqForm;
	var recipient	= manForm.recipient.value;
	var name	= manForm.manReqName.value;
	var company	= manForm.manReqCompany.value;
	var phone	= manForm.manReqPhoneNo.value;
	var email	= manForm.manReqEmail.value;
	var fax		= manForm.manReqFaxNo.value;
	var matter	= manForm.manReqMatter.value;
	var searchtype	= manForm.manReqSearchType.value;
	var details	= manForm.manReqDetails.value;

	// This means that the template has not been configured for the particular channel partner
	if ( recipient == 'Default' )	{ alert('Form misconfigured - no valid recipient set'); return false;		}

	// Check empty fields
	if ( name == '' )		{ alert('Please specify a name');	manForm.manReqName.focus(); return false;}
	if (( phone == '' ) && ( email == '' ))
	 {
		alert('Please specify a contact number or email, or both');	manForm.manReqName.focus(); return false;
	 }
	if (( searchtype == '' ) && ( details == '' ))
	 {
		alert('Please specify a search type or some details, or both');	manForm.manReqName.focus(); return false;
	 }
	if ( searchtype == 'Eg. title search' )	{ alert('Please spesify a search type'); manForm.manReqSearchType.focus(); return false; }
	
	return true;
}
