/*
	KD MALAYA [ GLOBAL JAVASCRIPT]
*/

function checkEmail() {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Feedback.xemail.value)){
		return (true);
	}
	alert("Invalid E-mail Address! Please re-enter.");
	document.forms['Feedback'].xemail.focus();
	return (false);
}

function checkFeedback(myForm) {

	var aa = document.forms['Feedback'].xname.value;
	var bb = document.forms['Feedback'].xsubject.value;
	var cc = document.forms['Feedback'].xmsg.value;
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.xemail.value)) {
		if (aa != "" && bb != "" && cc != "") {
			return (true);
		}	
	}
	//	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.xemail.value)){
	//}
	alert("Please check your feedback submission field.\n- Your E-mail must be (user@domain)");
	return (false);
}

function checkVFeedback(myForm) {

	var aa = document.forms['Feedback'].xticketid.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.xemail.value)) {
		if (aa != "") {
			return (true);
		}	
	}
	alert("Invalid E-mail Address! Please re-enter.\n- Your E-mail must be (user@domain)");
	document.forms['Feedback'].xemail.focus();
	return (false);
}

function log_out()
{
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm('Are you sure you want to log out?')) {
		return true;
	} else {
		ht[0].style.filter = "";
		return false;
	}
}


function CheckPassword()
{
	var aa = document.forms['ChangePasswd'].Passwd.value;
	var bb = document.forms['ChangePasswd'].RePasswd.value;
	if (aa=="" || bb=="") {
		alert("Please type your new password to change it!");
		document.forms['ChangePasswd'].Passwd.select();
		return false;	
	} else if (aa.length < 4) {
		alert("Your password must be at least 4 characters long!");
		document.forms['ChangePasswd'].Passwd.select();
		return false;	
	} else if (aa==bb) {
		return true;
	} else {
		alert("Type the password exactly the same in both fields!");
		document.forms['ChangePasswd'].Passwd.select();
		return false;
	}
}

function CheckFormQ1(RefNo)
{
	//var aa = document.forms['QS'].workscope_doc.value;
	var bb = document.forms['QS'].quotation_doc.value;
	var cc = document.forms['QS'].total_price.value;
	var dd = document.forms['QS'].supplyday.value;
	
	/*if (aa=="") {
		alert("Please check your Workscope Document!");
		document.forms['QS'].workscope_doc.select();
		return false;	
	} else */
	if (bb=="") {
		alert("Please check your Quotation Document!");
		document.forms['QS'].quotation_doc.select();
		return false;
	} else if (cc=="" || cc=="0.00") {
		alert("Please check your Total Price (RM)!");
		document.forms['QS'].total_price.select();		
		return false;
	} else if (dd=="" || dd==0) {
		alert("Please check your Duration Day!");
		document.forms['QS'].supplyday.select();		
		return false;
	} else {
		if (confirm('Are you sure you want to submit?\n\nReference No: '+ RefNo +'')) {
			return true;
		} else {
			return false;
		}
	}
}

function CheckFormQ2(RefNo)
{
	if (confirm('The submission will be inserted into our database!!!.\nYou cannot submit for the second time on this quotation.\n\nAre you sure you want to submit?\n\nReference No: '+ RefNo +'')) {
		return true;
	} else {
		return false;
	}
}



function CheckFormQ22(RefNo,Total)
{
	if (confirm('Reference No. : '+ RefNo +'\n\n TOTAL OFFER is RM '+ Total +' \n(AMOUNT TO BE PAID BY KD MALAYA).\n\nThe submission will be inserted into KD MALAYA QOS System !!!.\nYou cannot submit for the second time on this quotation.\n\nAre you sure you want to submit ? \n\n[Click OK for YES or click Cancel for NO]')) {
		return true;
	} else {
		return false;
	}
}

function QuotationDetails(QuotationID,ReferenceNo,OSCode,FinanceNo,WebOnline,submission) {
	if (submission==true) {
		smission = "&submission=true";
	} else {
		smission = "&submission=false";
	}
	QuotationDirect = "index.php?page=QuotationList&op=QD&QID="+ QuotationID +"&T=" + OSCode + "&RN="+ ReferenceNo +"&FNO=" + FinanceNo + "&ENONLINE="+ WebOnline + smission;
	window.location.href = QuotationDirect;
}

function QuotationViewEdit(QuotationID,ReferenceNo,IDItem,OSCode,FinanceNo,WebOnline) {
	QuotationDirect = "index.php?page=QuotationList&op=QVE&QID="+ QuotationID +"&T=" + OSCode + "&RN="+ ReferenceNo +"&IDI="+ IDItem +"&FNO=" + FinanceNo + "&ENONLINE="+ WebOnline;
	window.location.href = QuotationDirect;
}

function AddItem(QuotationID,ReferenceNo,IDItem,OSCode,FinanceNo,WebOnline) {
	QuotationDirect = "index.php?page=QuotationList&op=AddItem&QID="+ QuotationID +"&T=" + OSCode + "&RN="+ ReferenceNo +"&IDI="+ IDItem +"&FNO=" + FinanceNo + "&ENONLINE="+ WebOnline;
	window.location.href = QuotationDirect;
}

function EditItem(QuotationID,ItemID,IDI,ReferenceNo,OSCode,FinanceNo,WebOnline) {
	QuotationDirect = "index.php?page=QuotationList&op=EditItem&QID="+ QuotationID +"&T=" + OSCode + "&RN="+ ReferenceNo +"&ID="+ ItemID +"&IDI="+ IDI +"&FNO=" + FinanceNo + "&ENONLINE="+ WebOnline;
	window.location.href = QuotationDirect;
}

function DeleteItem(QuotationID,ItemID,IDI,ReferenceNo,OSCode,FinanceNo,WebOnline) {
	if (confirm('Are you sure you want to delete this item?')) {
		window.location.href='index.php?page=QuotationList&op=DeleteItem&QID='+ QuotationID +'&ID='+ ItemID +'&IDI='+ IDI +'&T='+ OSCode +'&RN='+ReferenceNo+'&FNO='+FinanceNo+'&ENONLINE='+WebOnline;
		return true;
	} else {
		return false;
	}
}
/*
function QuotationDetails(QuotationID,FinanceNo,WebOnline) {
	QuotationDirect = "QuotationDetails.php?TID=" + QuotationID + "&FNO=" + FinanceNo + "&ENONLINE="+ WebOnline + "&submission=false";
	window.open(QuotationDirect,"QuotationDetails","status=yes,resizable=yes,scrollbars=yes,width=540,height=450,left=0,top=0");
}
*/

function ViewSubmission(QuotationID,FinanceNo,WebOnline) {
	QuotationView = "ViewSubmission.php?TID=" + QuotationID + "&FNO=" + FinanceNo + "&ENONLINE="+ WebOnline;
	window.open(QuotationView,"QuotationView","status=yes,resizable=yes,scrollbars=yes,width=540,height=450,left=0,top=0");
}

function GetFile(Type,NoRujukan,KodPembekal,Vendor,WebOnline) {
	GetTheFile = "GetFile.php?Type=" + Type + "&NR=" + NoRujukan + "&KP=" + KodPembekal + "&FNO=" + Vendor + "&ENONLINE="+ WebOnline;
	window.open(GetTheFile,"GetTheFile","status=yes,resizable=yes,scrollbars=yes,width=540,height=450,left=0,top=0");
}

function Announcement(AnnID,FinanceNo,WebOnline) {
	AnnouncementDirect = "Announcement.php?AID=" + AnnID + "&FNO=" + FinanceNo + "&ENONLINE="+ WebOnline;
	window.open(AnnouncementDirect,"AnnouncementDetails","status=yes,resizable=yes,scrollbars=yes,width=540,height=450,left=0,top=0");
}

function OpenTerms() {
	TermsDirect = "TermsConditions.php";
	window.open(TermsDirect,"Terms","status=yes,resizable=yes,scrollbars=yes,width=500,height=535,left=0,top=0");
}

function RegistrationForm() {
	RegDirect = "RegistrationForm.php";
	window.open(RegDirect,"RegistrationForm","status=yes,resizable=yes,scrollbars=yes,width=620,height=535,left=0,top=0");
}

function CancelSubmission(ReferenceNo,DateSubmitted,FinanceNo,WebOnline) {
	if (confirm('Are you sure you want to cancel this submission?\n\nReference No: '+ ReferenceNo +'\nSubmission Date: '+ DateSubmitted +'')) {
		window.location.href='index.php?page=MySubmission&op=CS&ReferenceNo='+ReferenceNo+'&FNO='+FinanceNo+'&ENONLINE='+WebOnline+'';
		return true;
	} else {
		return false;
	}
}

function CancelQuotation(ReferenceNo,FormatType,FinanceNo,WebOnline) {
	if (confirm('Are you sure you want to cancel this submission?\n\nReference No: '+ ReferenceNo +'\n')) {
		window.location.href='index.php?page=QuotationList&T='+ FormatType +'&FNO='+FinanceNo+'&ENONLINE='+WebOnline+'';
		return true;
	} else {
		return false;
	}
}


// START CHECK ALL INBOX
var ies  = document.all  ? 1 : 0;
//==========================================
// highlite
//==========================================

function hl(cb)
{
	if (ies)
	{ 
		while (cb.tagName != "TR")
		{
			cb = cb.parentElement;
		}
	}
	else
	{
		 while (cb.tagName != "TD")
		 {
			 cb = cb.parentNode;
		 }
	}
		 
	cb.className = 'profile';
   
}

//==========================================
// down-lite
//==========================================

function dl(cb)
{
   if (ies)
   {
	   while (cb.tagName != "TR")
	   {
		   cb = cb.parentElement;
	   }
   }
   else
   {
	   while (cb.tagName != "TD")
	   {
		   cb = cb.parentNode;
	   }
   }
   cb.className = 'profile';
}

function InboxCheckAll(cb)
{
	var fmobj = document.MessageBox;
	for (var i=0;i<fmobj.elements.length;i++)
	{
		var e = fmobj.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled))
		{
			e.checked = fmobj.allbox.checked;
			if (fmobj.allbox.checked)
			{
			   hl(e);
			}
			else
			{
			   dl(e);
			}
		}
	}
}

function cca(cb)
{
   if (cb.checked)
   {
	   hl(cb);
   }
   else
   {
	   dl(cb);
   }
}

// END CHECK ALL INBOX



function chkAddItem()
{
	var a = document.forms['QS'].ItemName.value;
	var b = document.forms['QS'].ItemPrice.value;
	var c = document.forms['QS'].Quantity.value;
	var d = document.forms['QS'].ItemUnit.value;
	
	if (a=="") {
		alert("Please check your Item Name!");
		document.forms['QS'].ItemName.select();
		return false;
	} else if (b=="" || b=="0.00") {
		alert("Please check your Item Price!");
		document.forms['QS'].ItemPrice.select();
		return false;		
	} else if (c=="" || c=="0") {
		alert("Please check your Item Quantity!");
		document.forms['QS'].Quantity.select();
		return false;		
	} else if (d=="") {
		alert("Please check your Item Unit!");
		document.forms['QS'].ItemUnit.select();
		return false;		
	} else {
		return true;
	}
}


