
var URI='<%=URI%>';
var leftVar = 10;
var topVar = 225;
var prevTab = 0;
var isEdit = false;
function report_error(msg,url,line){
	alert(url+'#'+line+': '+msg);
}
function init(){
	self.onerror = report_error;
	return true;
}
function setMenuSelected(E){
	if(E){
		while(E.tagName!="TD") E = E.getParent();
	}
	E.className="menu2";
}
function setMenuUnselected(E){
	if(E){
		while(E.tagName!="TD") E = E.getParent();
	}
	E.className="menu1";
}
function showSetupClause(){
	//var v = URI+'/SetupAdditionalInfo.jsp';
	//window.location = v;
	//return true;
	setClickedValue(5, '/SetupAddnlInfoServlet');
}
function showPort(){
	setClickedValue(2, '/PortUserServlet?PKID='+pkid);
}
function showSetupNoticeParty(){
	//var v = URI+'/SetupNoticePartyScreen.jsp';
	//window.location = v;
	//return true;
	setClickedValue(5, '/SetupNoticePartyServlet');
}
function showSetupCustomer(){
	//var v = URI+'/SetupCustomerScreen.jsp';
	//window.location = v;
	//return true;
	setClickedValue(5, '/SetupCustomerServlet');
}
function showCustomer(){
	//var v = URI+'/CustomerScreen.jsp';
	//window.location = v;
	//return true;
	setClickedValue(2, '/CustomerScreenServlet?PKID='+pkid);
}
function showNotice(){
	setClickedValue(2, '/EndNoticePartyServlet?PKID='+pkid);
}
function showClause(){
	setClickedValue(2, '/AdditionalInfoServlet?PKID='+pkid);
}
function showProduct(){
	setClickedValue(3, '/ProductServlet');
}
function showBackPagePool(){
	setClickedValue(3,'/BackPageServlet');
}
function showNP(){
	setClickedValue(2, '/EndNoticePartyServlet?PKID='+pkid);
}
function showExchangeRates(){
	setClickedValue(3,'/ExRateServlet');
}
function showCurrency(){
	var v = URI+'/CurrencyCode.jsp'
	window.location = v;
	return true;
}
function shownpart(){
	setClickedValue(3,'/NoticePartyServlet');
}
function openNew(){
	var v = URI+'/main.jsp';
	window.location = v;
}

function showLookups(){
	var v = URI+'/CustomerScreen.jsp'
	window.location = v;
}

function showCustomerIDLookup(){
	var obj = new Object();
	obj.CustomerID = document.form.CustomerID;
	obj.ACN = document.form.ACN;
	obj.Line1 = document.form.Line1;
	obj.Line2 = document.form.Line2;
	obj.Line3 = document.form.Line3;
	obj.Line4 = document.form.Line4;
	obj.Line5 = document.form.Line5;
	obj.Line6 = document.form.Line6;
	obj.Contact = document.form.Contact;
	obj.Telephone1 = document.form.Telephone1;
	obj.Telephone2 = document.form.Telephone2;
	obj.Telephone3 = document.form.Telephone3;
	obj.Fax1 = document.form.Fax1;
	obj.Fax2 = document.form.Fax2;
	obj.Fax3 = document.form.Fax3;
	obj.CustomsCode = document.form.CustomsCode; ;
	obj.PriceLevel = document.form.PriceLevel;
	obj.GSTNumber = document.form.GSTNumber;
	obj.CreditApprovalNo = document.form.CreditApprovalNo;
	obj.Comments = document.form.Comments;

	win = showModalDialog(URI+'/Lookups/CustomerID.jsp', obj, "dialogHeight: 400px; dialogWidth: 600px; edge: sunken; center: Yes; help: Yes; resizable: Yes; status: Yes;");
	if(win == document.form.CustomerID.value){
		document.form.CustomerID.readOnly = true;
		isEdit = true;
	}
}
function showNew(){
	//var v = URI+'/NoticePartyEntryScreen.jsp';
	//window.location = v;
	//return true;
	setClickedValue(3, '/CreateNoticePartyServlet');
}
function deleteSelectedCustomers(){
	if(document.form.CustomerID.value =='' || document.form.CustomerID.value.indexOf(' ')>=0){
		alert('Please enter valid Notice Party ID.');
		document.form.CustomerID.focus();
		return false;
	}
	if(confirm("Are you sure you want to delete current lookup entry")){
		var v = URI+'/CustomerLookupDeleteServlet';
		document.form.action = v;
		document.form.submit();
	}
}
function vali(){
	if(document.form.CustomerID.value ==''){
		alert('Please enter Notice Party ID.');
		document.form.CustomerID.focus();
		return false;
	}
	if(document.form.Country.value ==''){
		alert('Please enter country of Notice Party.');
		document.form.Country.focus();
		return false;
	}
	if(document.form.Line1.value ==''){
		alert('Please enter name of Notice Party.');
		document.form.Line1.focus();
		return false;
	}
	return true;
}
function save(){
	if(vali()){
		if(isEdit==true){
			document.form.action = document.form.action +'?isEdit=true';
		}			
		document.form.submit();
		return true;
	}	
	return false;
}


function saveData(){
		document.form.Comments.value=escape(document.form.Comments.value);
		var v = URI+'/SaveCustomer1';
		document.form.action = v;
		document.form.submit();
	
}

function saveClau(){
	
		var v = URI+'/SaveClauase1';
		document.form.action = v;
		document.form.submit();
	
}

function saveCurrenc(){
	if(removeSpace(document.form.Name.value) ==''){
		alert('Please enter valid Currency Name.');
		document.form.Name.focus();
		return false;
	}
	if(removeSpace(document.form.Subdivision.value) ==''){
		alert('Please enter valid Currency Subdivision.');
		document.form.Subdivision.focus();
		return false;
	}
	
		var v = URI+'/SaveCurrency1';
		document.form.action = v;
		document.form.submit();
	
}
function removeSpace(s){
	var str = s;
	while(str.indexOf(' ')>=0){
		str = str.substring(0, str.indexOf(' '))+str.substring(str.indexOf(' ')+1, str.length);
	}
	return str;
}

function checkForFloat(field){
	if(field==null) return true;
	var val = field.value;
	if(val=='') return;
	if(val.indexOf('.') < 0) val += '.0';
	val = parseFloat(val).toString();
	if(isNaN(val)){
		alert("Please enter valid Decimal value.");
		field.value='';
		field.focus();
		return false;
	}
	if(val.indexOf('.') < 0) val += '.0';
	field.value=val;
	return true;
}

function delCustomerId(){
	var selectedID = getSelectedIDs();
	if(selectedID == ''){
		alert('Please first Select a Notice Party Entry.');
		return;
	}
	if(!confirm('Do you want to delete selected Notice Party Entries.')){
		return;
	}
	var selectedIDArr = selectedID.split('#');
	var url = URI+'/RemoveNotice?';
	for(var i=0; i<selectedIDArr.length; i++){
		if(selectedIDArr[i].toLowerCase()=='id'){
			alert("Notice Party ID 'ID' can not be deleted.");
			return false;
		}
		if(selectedIDArr[i].length>0)
			url+='NID='+selectedIDArr[i]+'&';
	}
	window.location=url;
}

function openCustomer(){
	var chk = document.form.chk;
	if(!chk) return;
	if(chk.length){
		for(var i=0;i<chk.length;i++){
			if(chk[i].checked){
				window.location =URI+"/EndNoticePartyEntryScreen.jsp?PKID="+pkid+"&ID=" + escape(chk[i].value);
				return true;
			}
		}
	} else {
		if(chk.checked){
			window.location =URI+"/EndNoticePartyEntryScreen.jsp?ID=" + escape(chk.value);
			return true;
		}
	}
	alert('No Notice Party Entry Selected.');
	return false;
}

function allNoticeShowScreen(){
	var chk = document.form.chk;
	if(!chk) return;
	if(chk.length){
		for(var i=0;i<chk.length;i++){
			if(chk[i].checked){
				window.location =URI+"/AllNoticePartiesEntryScreen.jsp?ID=" + escape(chk[i].value);
				return true;
			}
		}
	} else {
		if(chk.checked){
			window.location =URI+"/AllNoticePartiesEntryScreen.jsp?ID=" + escape(chk.value);
			return true;
		}
	}
	alert('No Notice Party Entry Selected.');
	return false;
}

function openSetupCustomer(){
	var chk = document.form.chk;
	if(!chk) return;
	if(chk.length){
		for(var i=0;i<chk.length;i++){
			if(chk[i].checked){
				window.location =URI+"/SetupNoticePartyEntryScreen.jsp?ID=" + escape(chk[i].value);
				return true;
			}
		}
	} else {
		if(chk.checked){
			window.location =URI+"/SetupNoticePartyEntryScreen.jsp?ID=" + escape(chk.value);
			return true;
		}
	}
	alert('No Notice Party Entry Selected.');
	return false;
}
function checkAll(){
	var chk = document.form.chk;
	if(!chk) return;
	if(chk.length){
		for(var i=0;i<chk.length;i++){
			chk[i].checked = document.form.all.checked;
			setSelected(chk[i].checked);
		}
	} else {
		chk.checked = document.form.all.checked;
		setSelected(chk.checked);
	}
}
function setSelected(checked){
//	alert(checked);
}

function getSelectedIDs(){
	var chk = document.form.chk;
	var val = '';
	if(!chk) return;
	if(chk.length){
		for(var i=0;i<chk.length;i++){
			if(chk[i].checked){
				val += escape(chk[i].value)+'#';
			}
		}
	} else {
		if(chk.checked){
			val += escape(chk.value)+'#';
		}
	}
	return val;
}

function TrimStr(ctrl){
	//code to chk if the string is of only space
	var j = 0;
	var allSpaceFound = true;
        var strData = ctrl;
	while(j < strData.length){
		if(strData.charAt(j) != ' '){	
			j++;		
			allSpaceFound = false;	
			break;
		}else{
			j++;
			allSpaceFound = true;	
		}
	}
	if(allSpaceFound){
		var noData = '';
		return noData;
	}

	//code to chk if the string is of only space

	var str = ctrl;	
	j = 0;
	var i = 0;
	while(i < str.length){
		if(str.charAt(i) == ' '){	
			j++;			
		}
		else{
			break;
		}
		i++;
	}	
	var cnt1 = str.length;
	var cnt2 = str.length;
	cnt1 = cnt1-1;	
	while(cnt1 > 0){
		if(str.charAt(cnt1) == ' ')	{	
			cnt2--;			
		}
		else{
			break;
		}
		cnt1--;
	}	
	var newString = str.substring(j, cnt2); 		
	return newString;
}

function searchNotice(){
	if(document.form.PartyName.value=="" && document.form.Country.value==""){
		alert("Please enter any one field to search.");
		return false;
	}
	var url = "/EndNoticePartySearchScreen.jsp?PKID="+pkid+"&PartyName="+escape(document.form.PartyName.value)+"&Country="+escape(document.form.Country.value);
	setClickedValue(2, url);
	return true;
}

function searchAll(){
	setClickedValue(2, '/EndNoticePartyServlet?PKID='+pkid);
}

function searchSearchNotice(){
	if(document.form.PartyName.value=="" && document.form.Country.value==""){
		alert("Please enter any one field to search.");
		return false;
	}
	var url ="/SearchSetupNoticePartyScreen.jsp?PartyName="+escape(document.form.PartyName.value)+"&Country="+escape(document.form.Country.value);
	setClickedValue(5, url);
	return true;
}

function searchSetupAll(){
	//var url = URI+"/SetupNoticePartyScreen.jsp";	
	//window.location=url;	
	//return false;
	setClickedValue(5, '/SetupNoticePartyServlet');
}


function searchAllNoticePartyScreen(){
	
	if(document.form.PartyName.value=="" && document.form.Country.value==""){
		alert("Please enter any one field to search.");
		return false;
	}
	var url = URI+"/AllNoticePartiesSearchScreen.jsp?PartyName="+escape(document.form.PartyName.value)+"&Country="+escape(document.form.Country.value);
	window.top.location.href = url;
	return true;
}
function searchAllNPScreen(){
	var url = URI+"/AllNoticeParties.jsp";
	window.top.location.href = url;
	return true;
}

