// JavaScript Document
function Compare_Date(date1,date2)
{
	value1=explodeArray(date1,'/');if(value1.length!=3)value1=explodeArray(date1,'-');
	value2=explodeArray(date2,'/');if(value2.length!=3)value2=explodeArray(date2,'-');
	if(value1[2]>value2[2])
		return 1;
	else if((value1[2]==value2[2])&&(value1[1]>value2[1]))
		return 1;
	else if((value1[2]==value2[2])&&(value1[1]==value2[1])&&(value1[0]>value2[0]))
		return 1;
	else if((value1[2]==value2[2])&&(value1[1]==value2[1])&&(value1[0]==value2[0]))
		return 0;
	else
		return -1;
}
function Compare_DateUK(date1,date2)
{
	value1=explodeArray(date1,'/');if(value1.length!=3)value1=explodeArray(date1,'-');
	value2=explodeArray(date2,'/');if(value2.length!=3)value2=explodeArray(date2,'-');
	if(value1[0]>value2[0])
		return 1;
	else if((value1[0]==value2[0])&&(value1[1]>value2[1]))
		return 1;
	else if((value1[0]==value2[0])&&(value1[1]==value2[1])&&(value1[2]>value2[2]))
		return 1;
	else if((value1[0]==value2[0])&&(value1[1]==value2[1])&&(value1[2]==value2[2]))
		return 0;
	else
		return -1;
}
function explodeArray(item,delimiter) { 
	tempArray=new Array(1); 
	var Count=0; 
	var tempString=new String(item); 
	
	while (tempString.indexOf(delimiter)>0) { 
	tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter)); 
	tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
	Count=Count+1 
	} 
	
	tempArray[Count]=tempString; 
	return tempArray; 
} 
function in_array(needle,haystack) {
var bool = false;
for (var i=0; i<haystack.length; i++) {
  if (haystack[i]==needle) {
   bool=true;
  }
}
return bool;
} 
 function validatex(x, xtype,required) 
{ 
	if(x==''){
		if(required==true){
			return false;
			}
		else{
			return true;
		}
	}
	else{
	 arr_xtype=explodeArray(xtype,'|');
	 if(arr_xtype.length==1){
	  switch (xtype) {
		 
		case "Password":
			pass_pat = new RegExp("([~,!,@,#])");
			is_pass = pass_pat.exec(x);
			if( x =='' || x.length < 6){			
				return false;
			}			
		break
		case "Int":			
			int_pat = new RegExp("([\+-]{0,1})([0-9]{1,})");
			is_int=int_pat.exec(x);		
			if( x =='' || !is_int){			
				return false;
			}
			notint_pat = new RegExp("[^0-9\+-]");
			isnot_int=notint_pat.exec(x);		
			if(isnot_int!=null){			
				return false;
			}
			
		  break;
		case "Double":
			
			double_pat = new RegExp("([\+-]{0,1}([0-9]{1,}))|([\+-]{0,1}([0-9]{0,})\.([0-9]{1,}))|([\+-]{0,1}([0-9]{0,})\.([0-9]{1,})(e|E)[\+-]{0,1}([0-9]{1,}))");
			is_double=double_pat.exec(x);		
			if( x =='' || !is_double){			
				return false;
			}
			notfloat_pat = new RegExp("[^0-9\+-\.eE]");
			isnot_float=notfloat_pat.exec(x);		
			if( isnot_float!=null){			
				return false;
			}
		  break;
		case "Currency":
			x=un_number_format(x);
			if(!validatex(x,"Double",required))
				return false;
		  break;
		  case "Literal":
			
			Literal_pat = new RegExp("([۰-۹]+|[0-9]+)");//contains no digits
			isnotLiteral=Literal_pat.exec(x);			
			if ( isnotLiteral )
			{
				return false;
			}
			if(parseFloat(x)==x)
				return false;
				///۱۲۳۴۵۶۷۸۹۰
					
		break;
		case "Digit":			
			notDigit_pat = new RegExp("[^0-9۰-۹]");
			for(ii=0;ii<19;ii++)x=x.replace(/[\s]/,'');
			isnot_Tel=notDigit_pat.exec(x);			
			if( x =='' || isnot_Tel!=null){			
				return false;
			}
	
		   break;
		case "Tel":			
			Tel_pat = new RegExp("[^0-9۰-۹\u00A0\u2028\u2029\s\f\n\r\t\v\+-]");
			for(ii=0;ii<9;ii++)x=x.replace(/[\s]/,'');
			isnot_Tel=Tel_pat.exec(x);			
			if( x =='' || isnot_Tel!=null || x.length<8 ){			
				return false;
			}
	
		   break;	
			
			case "Mobile": 
				Tel_pat = new RegExp("[^0-9]");
				for(ii=0;ii<9;ii++)x=x.replace(/[\s]/,'');
				isnot_Tel=Tel_pat.exec(x); 
				if( x =='' || isnot_Tel!=null || x.length != 9 ){ 
				return false;
				}
				/*if(x.charAt(0)!='0'){ 
				return false;
				} */
		   break;
			case "LiteralNum":
						LN_pat = new RegExp("[^a-zA-Z0-9]");//(".+@.+[\.]{1,}.+");
						isnotLN=LN_pat.exec(x);			
						if (isnotLN!=null )
						{
							return false;
						}
			break;
		  case "DateUS":
			Date_pat = new RegExp("((([0-9]{2}|[0-9]{4})-([0-9]{1,2})-([0-9]{1,2}))|(([0-9]{2}|[0-9]{4})/([0-9]{1,2})/([0-9]{1,2})))");
			is_Date=Date_pat.exec(x);
			if( x =='' || (!is_Date)){			
				return false;
			}
			arr_date=explodeArray(x,'/');
			if( arr_date.length== 1)arr_date=explodeArray(x,'/');
			if(arr_date[1]==0 || arr_date[2]==0)return false;
			if(12 < arr_date[1])return false;
			if(31 < arr_date[2])return false;
		  break;
		  case "DateUK":
			Date_pat = new RegExp("((([0-9]{1,2})-([0-9]{1,2})-([0-9]{2}|[0-9]{4}))|(([0-9]{1,2})/([0-9]{1,2})/([0-9]{2}|[0-9]{4})))");
			is_Date=Date_pat.exec(x);
			if( x =='' || (!is_Date)){			
				return false;
			}
			arr_date=explodeArray(x,'/');
			if( arr_date.length== 1)arr_date=explodeArray(x,'/');
			if(arr_date[1]==0 || arr_date[0]==0)return false;
			if(12 < arr_date[1])return false;
			if(31 < arr_date[0])return false;
		  break;
		case "Email":
			email_pat = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
			isEmail=email_pat.exec(x);			
			if (x=='' || !isEmail )
			{
				return false;
			}
		break;
		case "":
			return true;
		break;
	
	  }
	 }else{
		 if(arr_xtype[0]=='Int' || arr_xtype[0]=='Double'){
			 if(arr_xtype[2]!='.' && parseFloat(eval(arr_xtype[2])) < x) return false;
			 if(arr_xtype[1]!='.' && x < parseFloat(eval(arr_xtype[1]))) return false;
			 if((!validatex(x,arr_xtype[0],required)))return false;
		 }
		 if(arr_xtype[0]=='Currency'){
			 arr_xtype[2]=un_number_format(arr_xtype[2]);
			 arr_xtype[1]=un_number_format(arr_xtype[1]);
			 if(arr_xtype[2]!='.' && parseFloat(eval(arr_xtype[2])) < x) return false;
			 if(arr_xtype[1]!='.' && x < parseFloat(eval(arr_xtype[1]))) return false;
			 if((!validatex(x,arr_xtype[0],required)))return false;
		 }
		 if(arr_xtype[0]=='DateUS'){
			Date_pat = new RegExp("((([0-9]{2}|[0-9]{4})-([0-9]{1,2})-([0-9]{1,2}))|(([0-9]{2}|[0-9]{4})/([0-9]{1,2})/([0-9]{1,2})))");
			is_Date=Date_pat.exec(x);
			if( x =='' || (!is_Date))return false;
			arr_date=explodeArray(x,'/');						
			if( arr_date.length== 1)arr_date=explodeArray(x,'/');
			if(arr_date[1]==0 || arr_date[2]==0)return false;
			if(12 < arr_date[1])return false;
			if(31 < arr_date[2])return false;
			////////////
			//arr_xtype[1]=(eval(arr_xtype[1]));
			//arr_xtype[2]=(eval(arr_xtype[1]));
			/////////////
			if(arr_xtype[1]!='.' && Compare_Date(arr_xtype[1],x)==1)return false;
			if(arr_xtype[2]!='.' && Compare_Date(arr_xtype[2],x)==-1)return false;			
		 }
		 if(arr_xtype[0]=='DateUK'){
			Date_pat = new RegExp("((([0-9]{1,2})-([0-9]{1,2})-([0-9]{2}|[0-9]{4}))|(([0-9]{1,2})/([0-9]{1,2})/([0-9]{2}|[0-9]{4})))");
			is_Date=Date_pat.exec(x);
			if( x =='' || (!is_Date))return false;
			arr_date=explodeArray(x,'/');
			if( arr_date.length== 1)arr_date=explodeArray(x,'/');
			if(arr_date[1]==0 || arr_date[0]==0)return false;
			if(12 < arr_date[1])return false;
			if(31 < arr_date[0])return false;
			/////////////
			//arr_xtype[1]=(eval(arr_xtype[1]));
			//arr_xtype[2]=(eval(arr_xtype[1]));
			//////////////
			if(arr_xtype[1]!='.' && Compare_DateUK(arr_xtype[1],x)==1)return false;
			if(arr_xtype[2]!='.' && Compare_DateUK(arr_xtype[2],x)==-1)return false;			
		 }
	 }
	}
  return true;
}


function copy_xelements(frm_Source, frm_Dest){
str = '';
for( i = 0; i < eval('document.'+frm_Source).all.tags( 'INPUT' ).length; i++ ){
obj = eval('document.'+frm_Source).all.tags( 'INPUT' )[i];
if(obj.type!='submit' && obj.type!='button'){
dest_input = '<input name="'+obj.name+'" id="'+obj.id+'" value="'+obj.value+'" type="'+obj.type+'" checked="'+obj.checked+'"   class="noprint"';
if(obj.xtype){dest_input+=' xtype="'+obj.xtype+'"'}
if(obj.required){dest_input+=' required="'+obj.required+'"'}
if(obj.errormsg){dest_input+=' errormsg="'+obj.errormsg+'"'}
if(obj.invalidvalue){dest_input+=' invalidvalue="'+obj.invalidvalue+'"'}
dest_input+='>';
eval(frm_Dest).innerHTML = eval(frm_Dest).innerHTML + dest_input;
}
}
}
function Validate_Radio(RadioGroup) {
	var msg;
	var checked_value;

	if (RadioGroup) {
		msg='Please make a selection in the list first.';
		
		if (RadioGroup.length) {
			for (x=0; x<RadioGroup.length; x++)  {
				if(RadioGroup[x]){
				if (RadioGroup[x].checked)  {
					msg="";
					checked_value=RadioGroup[x].value;
					return checked_value;
				} 
			}
			else
				msg='List is empty.'}
		} 
		else {
			if (RadioGroup.checked) {
				msg="";
				checked_value=RadioGroup.value;
			}
		}
	}
	else {
		msg='List is empty.';
	}
	
	if (msg == ""){
	   return checked_value;
	} 
	else {
		alert(msg);
		return false;
	}
}
function getObjRequiredValue(obj){
	if(obj.className){
		classvalue=String(obj.className);
		if(classvalue!='' && obj.className){
			required_pat = new RegExp("required");
			is_Required=required_pat.exec(classvalue);
			if(!is_Required){
				return false;
			}
		}else{
			return false;
		}
	}else{
		return false;
	}
	return true;
}
function getObjXtypeValue(obj){
	if(obj.className && obj.className!=''){
		classvalue=obj.className;
		classvalue.replace(' ','');
		return classvalue.replace('required ','');
	}else{
		return '';
	}
}
function getObjFocusOnValue(obj){///////under construction
	return obj;	
}
function getObjErrormsgAlerting(obj,errormsg,frm_Source,alertingType){//alertingType is alert / span
	if(alertingType && alertingType=='span'){
		document.getElementById(String(frm_Source+'_errormsgspan')).innerHTML=errormsg;
		if(!(obj.type && obj.type=='hidden'))
			obj.focus();
	}else{//alertingType=='alert'
		alert(errormsg);
		if(!(obj.type && obj.type=='hidden'))
			obj.focus();
	}
	return;
}
function validate(frm_Source,extravalidation,alertingType){
	if(!alertingType)
		alertingType='alert';
	if(document.getElementById(String(frm_Source+'_errormsgspan')))
		document.getElementById(String(frm_Source+'_errormsgspan')).innerHTML='';
	var msg;
	var checked_value;
	radioname=new Array;
	radionameset=new Array;
	radioindex=new Array;
	radiomsg=new Array;
	radiolast=new Array;
	checkboxname=new Array;
	checkboxnameset=new Array;
	checkboxindex=new Array;
	checkboxmsg=new Array;
	checkboxlast=new Array;	
/*
your smple INPUT:
<input name="fld_First_Name" type="text" id="fld_First_Name" xtype="x1" errormsg="x2" required="x3" >
x1 is Int / Double / Tel / Date / Email /''
x2 is your error message 
x3 if it it required to be filled x3 is true else is falses
*/
r=-1;
rs=-1;
rc=-1;
rsc=-1;
eval('len = document.'+frm_Source+'.getElementsByTagName("INPUT").length');
for(i=0;i < len; i++){
	obj = eval('document.'+frm_Source).getElementsByTagName( 'INPUT' )[i];	
	if(obj.type=='text'){
		if(getObjRequiredValue(obj)){			
			Xtype=getObjXtypeValue(obj);   /*(obj.xtype)?(obj.xtype):'';*/			
			Error_Msg=(obj.alt)?(obj.alt):('Please enter a valid value');
			Value=obj.value;
			if(!validatex(Value,Xtype,1)){
				/*alert(Error_Msg);
				obj.focus();
				*/	
				getObjErrormsgAlerting(obj,Error_Msg,frm_Source,alertingType);
				return false;
			}		
		}else if(obj.xtype){			
				if(obj.value!=''){					
					Xtype=getObjXtypeValue(obj);   /*(obj.xtype)?(obj.xtype):'';*/					
					Error_Msg=(obj.alt)?(obj.alt):('Please enter a valid value');
					Value=obj.value;
					if(!validatex(Value,Xtype,0)){
						/*alert(Error_Msg);
						obj.focus();*/
						getObjErrormsgAlerting(obj,Error_Msg,frm_Source,alertingType);
						return false;
					}					
				}					
		}
	}else if(obj.type=='hidden' || obj.type=='password'){
		if(getObjRequiredValue(obj)){			
			Xtype=getObjXtypeValue(obj);   /*(obj.xtype)?(obj.xtype):'';*/			
			Error_Msg=(obj.alt)?(obj.alt):('Please enter a valid value');
			Value=obj.value;
			if(!validatex(Value,Xtype,1)){
				//alert(Error_Msg);
				//obj.focus();
				getObjErrormsgAlerting(obj,Error_Msg,frm_Source,alertingType);
				if(obj.focuson)
					document.getElementById(obj.focuson).focus();
				return false;
			}		
		}else if(obj.xtype){			
				if(obj.value!=''){					
					Xtype=getObjXtypeValue(obj);   /*(obj.xtype)?(obj.xtype):'';*/					
					Error_Msg=(obj.alt)?(obj.alt):('Please enter a valid value');
					Value=obj.value;
					if(!validatex(Value,Xtype,0)){
						//alert(Error_Msg);
						//obj.focus();
						getObjErrormsgAlerting(obj,Error_Msg,frm_Source,alertingType);
						return false;
					}					
				}					
		}
	}
	else if(obj.type=='radio'){
		if(getObjRequiredValue(obj)){
			r++;			
			radioname[r]=obj.name;			
			
			if(!in_array(radioname[r],radionameset)){
				rs++;
				radionameset[rs]=radioname[r];				
			}			
			if(obj.checked){				
				radioindex[rs]='y';
			}else{
				radiomsg[rs]=(obj.alt)?(obj.alt):("Please make a selection in the list first.");
				radiolast[rs]=obj;
			}				
		}
	}else if(obj.type=='checkbox'){
		if(getObjRequiredValue(obj)){		
			rc++;			
			checkboxname[rc]=obj.id;			
			if(!in_array(checkboxname[rc],checkboxnameset)){
				rsc++;
				checkboxnameset[rsc]=checkboxname[rc];				
			}			
			if(obj.checked){				
				checkboxindex[rsc]='y';
			}else{
				checkboxmsg[rsc]=(obj.alt)?(obj.alt):("Please select a check box in the list first.");
				checkboxlast[rsc]=obj;
			}				
		}	
	}			
}
for(jj=0;jj<=rs;jj++){	
	if(radioindex[jj]!='y'){		
		//alert(radiomsg[jj]);
		//radiolast[jj].focus();
		getObjErrormsgAlerting(radiolast[jj],radiomsg[jj],frm_Source,alertingType);
		return false;
	}
}
for(jj=0;jj<=rsc;jj++){	
	if(checkboxindex[jj]!='y'){		
		//alert(checkboxmsg[jj]);
		//checkboxlast[jj].focus();
		getObjErrormsgAlerting(checkboxlast[jj],checkboxmsg[jj],frm_Source,alertingType);
		return false;
	}
}
for(i=0;i < eval('document.'+frm_Source).getElementsByTagName( 'SELECT' ).length; i++){
	obj = eval('document.'+frm_Source).getElementsByTagName( 'SELECT' )[i];
		Invalid_Val=getObjXtypeValue(obj);/*(obj.invalidvalue)?(obj.invalidvalue):('');*/
	if(obj.value==Invalid_Val && getObjRequiredValue(obj)){
		Error_Msg=(obj.alt)?(obj.alt):('Please select from the List');		
		//alert(Error_Msg);obj.focus();
		getObjErrormsgAlerting(obj,Error_Msg,frm_Source,alertingType);
		return false;
	}
}
for(i=0;i < eval('document.'+frm_Source).getElementsByTagName( 'TEXTAREA' ).length; i++){
	obj = eval('document.'+frm_Source).getElementsByTagName( 'TEXTAREA' )[i];
		Invalid_Val=getObjXtypeValue(obj);/*(obj.xtype)?(obj.xtype):'';*/
	if((obj.innerHTML==Invalid_Val) && getObjRequiredValue(obj)){
		Error_Msg=(obj.alt)?(obj.alt):('Please enter some notes');		
		//alert(Error_Msg);obj.focus();
		getObjErrormsgAlerting(obj,Error_Msg,frm_Source,alertingType);
		return false;
	}
}
if(extravalidation && extravalidation!='')if(!eval(extravalidation+'()'))return false;
for(i=0;i < eval('document.'+frm_Source).getElementsByTagName( 'INPUT' ).length; i++){
	obj = eval('document.'+frm_Source).getElementsByTagName( 'INPUT' )[i];	
	Xtype=getObjXtypeValue(obj);
	if(Xtype!=''){
		xtypeCurrency_pat = new RegExp("Currency");
		is_Currency=xtypeCurrency_pat.exec(Xtype);
		if(is_Currency)
			obj.value=un_number_format(obj.value);
	}
}
return true;
}
///////////////////////////////
function onchange_Duration_inc(timeunit){
	if(document.getElementById('fld_Start_Hour').value!=-1 && document.getElementById('fld_End_Hour').value!=-1){
		if( (parseInt(document.getElementById('fld_Duration').value)+parseInt(document.getElementById('fld_End_Hour').value*60)+parseInt(document.getElementById('fld_End_Min').value)) < 1440 && 0 < (parseInt(document.getElementById('fld_Duration').value)+parseInt(document.getElementById('fld_Start_Hour').value*60)+parseInt(document.getElementById('fld_Start_Min').value))){//<=(60*24)){
			calc_durations(timeunit);
		}//else{
			
			//document.getElementById('fld_Duration').value=document.getElementById('fld_Duration').value-timeunit;
		//}
		/*if( (parseInt(document.getElementById('fld_Duration').value)+parseInt(document.getElementById('fld_End_Hour').value*60)+parseInt(document.getElementById('fld_End_Min').value))>=1440 ){//<=(60*24)){
			document.getElementById('fld_Duration').value=document.getElementById('fld_Duration').value-timeunit;
			mopt=parseInt(roundNumber(60/timeunit,2))+1;
			document.getElementById('fld_End_Min').options[(mopt)].selected=true;
		}*/
	}else{
		document.getElementById('fld_Duration').value=document.getElementById('fld_Duration').value-timeunit;
	}
}
function onchange_Duration_dec(timeunit){
	if(document.getElementById('fld_Start_Hour').value!=-1 && document.getElementById('fld_End_Hour').value!=-1){
		if( (parseInt(document.getElementById('fld_Duration').value)+parseInt(document.getElementById('fld_End_Hour').value*60)+parseInt(document.getElementById('fld_End_Min').value)) < 1440 && 0 < (parseInt(document.getElementById('fld_Duration').value)+parseInt(document.getElementById('fld_Start_Hour').value*60)+parseInt(document.getElementById('fld_Start_Min').value))){//<=(60*24)){
			calc_durations(timeunit);
		}//else{
			//set_duration(timeunit);
				//document.getElementById('fld_Duration').value=parseInt(document.getElementById('fld_Duration').value)+parseInt(timeunit);
		//}
		
	}else{
		document.getElementById('fld_Duration').value=parseInt(document.getElementById('fld_Duration').value)+parseInt(timeunit);
	}
}
function calc_durations(timeunit){
	duration=document.getElementById('fld_Duration').value;
	start_min=parseInt(roundNumber(document.getElementById('fld_Start_Min').value,2));
	start_hour=parseInt(roundNumber(document.getElementById('fld_Start_Hour').value,2));
	end_time=parseInt(start_hour*60)+parseInt(start_min)+parseInt(duration);
	x=end_time;
	if(0<=end_time<(24*60)){
	h=x/60;
	hopt=parseInt(roundNumber(h,2))+parseInt(1);
	if(-1<hopt<26){
		document.getElementById('fld_End_Hour').options[(hopt)].selected=true;
	
	m=x-((hopt-1)*60);
	//alert(m+' '+timeunit+' '+(m/timeunit));
	mopt_=parseInt(m/timeunit)+parseInt(1);
	//alert(hopt+':'+mopt_+'--'+timeunit);
	document.getElementById('fld_End_Min').options[mopt_].selected=true;
	
	
	x=Math.abs(duration);
	sign_t=(duration<0)?'-':' ';
	h=x/60;
	h=parseInt(roundNumber(h,2));
	m=x-h*60;
	m=parseInt(roundNumber(m,2));
	if(h < 9)h='0'+h;
	if(m < 9)m='0'+m;
	signt=(duration<0)?('-'):('+');
	document.getElementById('span_Duration').innerHTML=sign_t+'('+String(h)+':'+String(m)+')';
	//start_min=(document.getElementById('fld_Start_Min').value==-1)?(0):(document.getElementById('fld_Start_Min').value);
	
	}
	}
}
function set_duration(timeunit){
	if(document.getElementById('fld_Stat_Hour')!=-1 && document.getElementById('fld_End_Hour')!=-1){
	duration=parseInt((document.getElementById('fld_End_Hour').value-document.getElementById('fld_Start_Hour').value)*60)+parseInt(document.getElementById('fld_End_Min').value - document.getElementById('fld_Start_Min').value);
	document.getElementById('fld_Duration').value=duration;
	calc_durations(timeunit);
	}
	
}
function set_end_time(time_unit,due_date_sde) {
	if (document.getElementById('fld_Start_Min').value) {
		minno = ((document.getElementById('fld_Start_Min').value)/(time_unit))+1;
	} else {
		minno = 0;
	}
	if (document.getElementById('fld_Start_Hour').value) {
		hourno = parseInt(document.getElementById('fld_Start_Hour').value)+1;
	} else {
		hourno = 0;
	}
		calc_duration(due_date_sde);
}
function set_start_min() {
	if ((document.getElementById('fld_Start_Hour').value) && (document.getElementById('fld_Start_Min').value == -1)) {
		document.getElementById('fld_Start_Min').options[1].selected=true;
	}
}
function set_end_min() {
	if ((document.getElementById('fld_End_Hour').value) && (document.getElementById('fld_End_Min').value == -1)) {
		document.getElementById('fld_End_Min').options[1].selected=true;
	}
}
/*function calc_duration(due_date_sde) {
	if(due_date_sde=="Pre-OrderList.php")
		due_date_sde="fld_Delivery_Date";
	else if(due_date_sde=="Quote_Comp")
		due_date_sde="fld_Appointment_Date";
	else if(due_date_sde=="Pre-Order")
		due_date_sde="fld_Due_Date";
	if ((document.getElementById('fld_Start_Min').value) && (document.getElementById('fld_Start_Hour').value) && (document.getElementById('fld_End_Min').value) && (document.getElementById('fld_End_Hour').value)) {
		if (document.getElementById(due_date_sde).value == '')  document.getElementById(due_date_sde).value = today;
		start_time = Reverse_Date(document.getElementById(due_date_sde).value,'/','/') + ' ' + document.getElementById('fld_Start_Hour').value + ':' + document.getElementById('fld_Start_Min').value;
		end_time   = Reverse_Date(document.getElementById(due_date_sde).value,'/','/') + ' ' + document.getElementById('fld_End_Hour').value + ':' + document.getElementById('fld_End_Min').value;

		document.getElementById('span_Duration').innerHTML='('+time_diff(start_time, end_time)+')';
		document.getElementById('fld_Duration').value = time_diff_min(start_time, end_time);
	}
}*/

function roundNumber(rnum, rlength) {
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		//newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	return newnumber;
}
function changebgcolor(id){
	document.getElementById(id).bgColor='#DDDDDD';
	//alert(id+'_tr');
}
function changebgcolorout(id){
	document.getElementById(id).bgColor='';
}
function FullSelect_user_form(){
	FullSelect('fld_Selected_Role_Type_No');
	FullSelect('fld_Selected_Insurance_No');
}
function lead_time(lead, cdate) {
	//alert(lead);
	
	var	startDate;
	var day_of_week;
	var wks;
	var total_lead;
	var newday;
	lead=(is_numeric(lead) && lead!='')?(lead):(0);
	if(cdate==''){
		startDate =	new	Date ();
	}else{
		value=explodeArray(cdate,'/');
		var output="20"+value[2]+"/"+value[1]+"/"+value[0];
		startDate =	new	Date (output);
	}
	//startDate = Reverse_DateInt(startDate);
	day = startDate.getDay();
	wks = parseInt(lead / 7);
	rdays = parseInt(lead - (wks * 7));

	/*if (rdays >= 0) {
		if (day == 0) {
			rdays += 1;
		}

		if ((rdays + day) > 5) {
		// Compensate for the weekend
		rdays += 2;
		} 
	}
	if (rdays < 0) {
		if ((day == 6) && (rdays == 0)) {
			rdays -= 1;
		}
		//if (day = 6) {rdays -= 1;}

		if ((rdays + day) < 1) {
			// Compensate for the weekend
			rdays -= 2;
		} 
	}*/

	total_lead = parseInt((wks * 7) + rdays);

	with (startDate) setDate(getDate()+total_lead);
	
	var d = startDate.getDate();
	var m = (startDate.getMonth()+1);
	
	(d<10) ? d = d : d = d;
	(m<10) ? m = m : m = m;
	year = String(startDate.getYear());
	year = year.substring(year.length,2);
	newday = String(d+"/"+m+"/"+year);
	
	//alert(newday);                                                                                                                                                     
	//alert(startDate);
	return newday;
}
/*function date_diff(Sdate,Edate)
{
	//Edatef = new Date();
	if (!Edate) {
		Edatef = new Date();
	} else {
		var EdateVal = Reverse_Date(Edate,'/','/');
		Edatef = new Date('20'+EdateVal);
	}
	var SdateVal = Reverse_Date(Sdate,'/','/');
	Sdatef = new Date('20'+SdateVal);
	var one_day=1000*60*60*24;
	
	date_diff_val = Math.ceil((Sdatef.getTime()-Edatef.getTime())/(one_day))
	
	return date_diff_val;
}
*/
//////////////////////////////
function show_address(itm,val,where){
	address = '';
	short_address = '';
if(document.getElementById('agent_address'+val))
				alert('W;ERLJL;WEJRG;L4EJ;LRJ');	
	//alert(itm.selectedIndex);
	//if(itm.value!=''){
		if(itm.selectedIndex==0){
			address= document.getElementById('fld_Site_Delivery_Address').value;
			if(where=='Esaddress')
				document.getElementById('fld_Default_Estimation_Type').value = 1;
			else	
				document.getElementById('fld_Default_Accounting_Type').value = 1;			
		}else if(itm.selectedIndex==1){			
			address = document.getElementById('agent_address'+val).value;
			if(where=='Esaddress')
				document.getElementById('fld_Default_Estimation_Type').value = 2;
			else
				document.getElementById('fld_Default_Accounting_Type').value = 2;			
		}else if(itm.selectedIndex==2){
			address = document.getElementById('insurer_address'+val).value;
			if(where=='Esaddress')
				document.getElementById('fld_Default_Estimation_Type').value = 3;
			else	
				document.getElementById('fld_Default_Accounting_Type').value = 3;			
		}else{
			address = document.getElementById('Address'+val).value;
			if(where=='Esaddress')
				document.getElementById('fld_Default_Estimation_Type').value = 4;
			else	
				document.getElementById('fld_Default_Accounting_Type').value = 4;			
		}	
		short_address = shorttext(address, 20, '');
	/*}else{
		if(itm.selectedIndex==0){
			if(where=='Esaddress')
				document.getElementById('fld_Default_Estimation_Type').value = 1;
			else	
				document.getElementById('fld_Default_Accounting_Type').value = 1;			
		}else if(itm.selectedIndex==1){
			short_address = '<span class=red>No Agent has been selected</span>';		
			if(where=='Esaddress')
				document.getElementById('fld_Default_Estimation_Type').value = 2;
			else
				document.getElementById('fld_Default_Accounting_Type').value = 2;			
		}else if(itm.selectedIndex==2){
			short_address = '<span class=red>No Insurer has been selected</span>';		
			if(where=='Esaddress')
				document.getElementById('fld_Default_Estimation_Type').value = 3;
			else	
				document.getElementById('fld_Default_Accounting_Type').value = 3;			
		}else{
			if(where=='Esaddress')
				document.getElementById('fld_Default_Estimation_Type').value = 4;
			else	
				document.getElementById('fld_Default_Accounting_Type').value = 4;			
		}		
	}*/		
	document.getElementById(where).innerHTML = '&nbsp;'+short_address;
	document.getElementById(where).title = address;
}
function show_Calculated_Invoice_Amount(rowno)
{
	//calculated=0;
	//for(rowno=0;document.getElementById('invc_Tick'+rowno);rowno++)
	//{		
		document.getElementById('old_invc_Cost'+rowno).value=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
		if(document.frm_Main.invc_Tick[rowno]){
			if (document.frm_Main.invc_Tick[rowno].checked) {
				calculated+=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));				
				document.getElementById('invc_Tick'+rowno).checked = true;				
			}
			else if(!document.frm_Main.invc_Tick[rowno].checked){
				calculated-=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
				document.getElementById('invc_Tick'+rowno).checked = false;
				if(document.getElementById('edit_Tick'+rowno)){
				if(document.getElementById('edit_Tick'+rowno).checked)
					document.getElementById('edit_Tick'+rowno).click();}
			}
		}else if(document.frm_Main.invc_Tick){
			if (document.frm_Main.invc_Tick.checked) {				
				calculated+=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));				
				calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;
				document.getElementById('invc_Tick'+rowno).checked = true;
				
			}
			else if(!document.frm_Main.invc_Tick.checked){
				calculated-=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
				document.getElementById('invc_Tick'+rowno).checked = false;
				if(document.getElementById('edit_Tick'+rowno).checked)
					document.getElementById('edit_Tick'+rowno).click();;				
			}			
		}		
	//}
	document.getElementById('invc_Calculated_Amount').innerHTML= Math.round(calculated*100)/100;
	
	BALANCE=document.getElementById('invc_Balance_Amount').innerHTML = Math.round((parseFloat(document.getElementById('fld_Invoice_Amount').value) - calculated)*100)/100;
}
//////////////////////////////
function disable_enable_supplier_invoice(rowno)
{
	//if(document.getElementById('invc_Invoiced_Net_Total'+rowno))
	
	if(document.getElementById('invc_Tick'+rowno))
		if(!document.getElementById('invc_Tick'+rowno).checked){
			document.getElementById('invc_Tick'+rowno).click();
			document.getElementById('invc_Tick'+rowno).checked=true;
		}	
	if(document.getElementById('edit_Tick'+rowno).itisdisabled==1){
		document.getElementById('invc_Invoiced_Net_Total'+rowno).readOnly = false;
		//document.getElementById('invc_Invoiced_Net_Total'+rowno).className ='Num_txtBox';		
		document.getElementById('invc_Invoiced_VAT_Total'+rowno).readOnly = false;
		//document.getElementById('invc_Invoiced_VAT_Total'+rowno).className ='Num_txtBox';	
		document.getElementById('invc_Invoiced_Quantity'+rowno).readOnly = false;
		//document.getElementById('invc_Invoiced_Quantity'+rowno).className ='Qty_txtBox'; 
		document.getElementById('Down_Image'+rowno).disabled = false;
		document.getElementById('Up_Image'+rowno).disabled = false;
		if(document.getElementById('invc_Invoiced_Quantity'+rowno).value==0){
			//document.getElementById('invc_Up_Image'+rowno).click();
			document.getElementById('invc_Invoiced_Quantity'+rowno).value++;
			//calculate_cost(rowno);///////////////////////////////////////////////////
		}
		document.getElementById('edit_Tick'+rowno).itisdisabled=0;
	}else{
		document.getElementById('invc_Invoiced_Net_Total'+rowno).readOnly = true;
		//document.getElementById('invc_Invoiced_Net_Total'+rowno).className ='Num_txtBox_disabled';		
		document.getElementById('invc_Invoiced_VAT_Total'+rowno).readOnly = true;
		//document.getElementById('invc_Invoiced_VAT_Total'+rowno).className ='Num_txtBox_disabled';	
		document.getElementById('invc_Invoiced_Quantity'+rowno).readOnly = true;
		//document.getElementById('invc_Invoiced_Quantity'+rowno).className ='Qty_txtBox_disabled'; 
		document.getElementById('Down_Image'+rowno).disabled = true;
		document.getElementById('Up_Image'+rowno).disabled = true;
		document.getElementById('edit_Tick'+rowno).itisdisabled=1;
	}		
	//if(document.getElementById('invc_Invoiced_VAT_Total'+rowno))
 	//if(document.getElementById('invc_Invoiced_Quantity'+rowno))
	//if(document.getElementById('invc_Down_Image'+rowno))
	//if(document.getElementById('invc_Up_Image'+rowno))
	
}
function show_Calculated_Invoice_Amount(rowno)
{
	//calculated=0;
	//for(rowno=0;document.getElementById('invc_Tick'+rowno);rowno++)
	//{	
	balance=document.getElementById('invc_Balance_Amount').innerHTML;
	calculated=document.getElementById('invc_Calculated_Amount').innerHTML;
	oldcalc=calculated;
	net=document.getElementById('invc_Invoiced_Net_Total'+rowno).value;
	vat=document.getElementById('invc_Invoiced_VAT_Total'+rowno).value;
	qty=document.getElementById('invc_Invoiced_Quantity'+rowno).value;
	if(validatex(net,'Double|0|.',1) && validatex(vat,'Double|0|.',1) && validatex(qty,'Int|1|.',1) ){
		val=(parseFloat(net)+parseFloat(vat));
		if(document.getElementById('invc_Tick'+rowno).checked){
			calculated=parseFloat(val)+parseFloat(calculated);
			//document.getElementById('invc_Tick'+rowno).checked = true;
		}
		else if(!document.getElementById('invc_Tick'+rowno).checked){
				calculated-=val;
				//document.getElementById('invc_Tick'+rowno).checked = false;
				if(document.getElementById('edit_Tick'+rowno)){
					if(document.getElementById('edit_Tick'+rowno).checked)
					document.getElementById('edit_Tick'+rowno).checked=false;
					document.getElementById('invc_Invoiced_Net_Total'+rowno).readOnly = true;
					//document.getElementById('invc_Invoiced_Net_Total'+rowno).className ='Num_txtBox_disabled';		
					document.getElementById('invc_Invoiced_VAT_Total'+rowno).readOnly = true;
					//document.getElementById('invc_Invoiced_VAT_Total'+rowno).className ='Num_txtBox_disabled';	
					document.getElementById('invc_Invoiced_Quantity'+rowno).readOnly = true;
					//document.getElementById('invc_Invoiced_Quantity'+rowno).className ='Qty_txtBox_disabled'; 
					document.getElementById('Down_Image'+rowno).disabled = true;
					document.getElementById('Up_Image'+rowno).disabled = true;
					document.getElementById('edit_Tick'+rowno).itisdisabled=1;
				}
		}
	}/*
		document.getElementById('old_invc_Cost'+rowno).value=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
		if(document.frm_Main.invc_Tick[rowno]){
			if (document.frm_Main.invc_Tick[rowno].checked) {
				calculated+=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));				
				document.getElementById('invc_Tick'+rowno).checked = true;				
			}
			else if(!document.frm_Main.invc_Tick[rowno].checked){
				calculated-=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
				document.getElementById('invc_Tick'+rowno).checked = false;
				if(document.getElementById('edit_Tick'+rowno)){
				if(document.getElementById('edit_Tick'+rowno).checked)
					document.getElementById('edit_Tick'+rowno).click();}
			}
		}else if(document.frm_Main.invc_Tick){
			if (document.frm_Main.invc_Tick.checked) {				
				calculated+=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));				
				calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;
				document.getElementById('invc_Tick'+rowno).checked = true;
				
			}
			else if(!document.frm_Main.invc_Tick.checked){
				calculated-=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
				document.getElementById('invc_Tick'+rowno).checked = false;
				if(document.getElementById('edit_Tick'+rowno).checked)
					document.getElementById('edit_Tick'+rowno).click();;				
			}			
		}		
	//}*/
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(Math.round(calculated*100)/100));
	
	balance=document.getElementById('invc_Balance_Amount').innerHTML =number_format(String(Math.round((parseFloat(document.getElementById('fld_Invoice_Amount').value) - calculated)*100)/100));

}
function calculate_cost_supplier_inv(rowno) {
	var net_total, vat_total, pre_net_total, pre_vat_total ;
	if(document.getElementById('invc_Supplier_Unit_Cost'+rowno).value==0)
	{
		if(parseInt(document.getElementById('invc_Invoiced_Quantity'+rowno).value)!=0)
			document.getElementById('invc_Supplier_Unit_Cost'+rowno).value=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value)/(parseInt(document.getElementById('invc_Invoiced_Quantity'+rowno).value)?parseInt(document.getElementById('invc_Invoiced_Quantity'+rowno).value):1));
	}
	net_total = (document.getElementById('invc_Invoiced_Quantity'+rowno).value * document.getElementById('invc_Supplier_Unit_Cost'+rowno).value);
	vat_total = (((document.getElementById('invc_Supplier_Unit_Cost'+rowno).value * document.getElementById('invc_VAT'+rowno).value)/100) * document.getElementById('invc_Invoiced_Quantity'+rowno).value);
	pre_total=parseFloat(document.getElementById('old_invc_Cost'+rowno).value);
	//calculated-=(pre_total);
	calculated=parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML);
	calculated-=(pre_total);
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(calculated));
	
	balance=parseFloat(document.getElementById('invc_Balance_Amount').innerHTML);
	balance=parseFloat(balance)+parseFloat(pre_total);
	document.getElementById('invc_Balance_Amount').innerHTML=number_format(String(balance));
	/**/
	document.getElementById('invc_Invoiced_Net_Total'+rowno).value = Math.round(net_total*100)/100;
	document.getElementById('invc_Invoiced_VAT_Total'+rowno).value = Math.round(vat_total*100)/100;
	//calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;	
	document.getElementById('old_invc_Cost'+rowno).value=(parseFloat(net_total)+parseFloat(vat_total));
	show_Calculated_Invoice_Amount(rowno);
}
function calculate_cost_supplier_inv_vatinput(rowno) {
	//var net_total, vat_total, pre_net_total, pre_vat_total ;
	if(document.getElementById('invc_Supplier_Unit_Cost'+rowno).value==0)
	{
		if(parseInt(document.getElementById('invc_Invoiced_Quantity'+rowno).value)!=0)
			document.getElementById('invc_Supplier_Unit_Cost'+rowno).value=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value)/(parseInt(document.getElementById('invc_Invoiced_Quantity'+rowno).value)?parseInt(document.getElementById('invc_Invoiced_Quantity'+rowno).value):1));
	}
	net_total = (document.getElementById('invc_Invoiced_Quantity'+rowno).value * document.getElementById('invc_Supplier_Unit_Cost'+rowno).value);
	vat_total =document.getElementById('invc_Invoiced_VAT_Total'+rowno).value; 
	/*(((document.getElementById('invc_Supplier_Unit_Cost'+rowno).value * document.getElementById('invc_VAT'+rowno).value)/100) * document.getElementById('invc_Invoiced_Quantity'+rowno).value);
	*/
	pre_total=parseFloat(document.getElementById('old_invc_Cost'+rowno).value);
	//calculated-=(pre_total);
	calculated=parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML);
	calculated-=(pre_total);
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(calculated));
	
	balance=parseFloat(document.getElementById('invc_Balance_Amount').innerHTML);
	balance=parseFloat(balance)+parseFloat(pre_total);
	document.getElementById('invc_Balance_Amount').innerHTML=number_format(String(balance));
	/**/
	document.getElementById('invc_Invoiced_Net_Total'+rowno).value = Math.round(net_total*100)/100;
	document.getElementById('invc_Invoiced_VAT_Total'+rowno).value = Math.round(vat_total*100)/100;
	//calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;	
	document.getElementById('old_invc_Cost'+rowno).value=(parseFloat(net_total)+parseFloat(vat_total));
	show_Calculated_Invoice_Amount(rowno);
}
function calculate_vat_total(rowno) 
{
	var vat_total;	
	calculated=parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML);
	calculated-=parseFloat(document.getElementById('old_invc_Cost'+rowno).value);
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(calculated));
	
	balance=parseFloat(document.getElementById('invc_Balance_Amount').innerHTML);
	balance=parseFloat(balance)+parseFloat(document.getElementById('old_invc_Cost'+rowno).value);
	document.getElementById('invc_Balance_Amount').innerHTML=number_format(String(balance));
	
	vat_total = ((document.getElementById('invc_Invoiced_Net_Total'+rowno).value * document.getElementById('invc_VAT'+rowno).value)/100);
	document.getElementById('invc_Invoiced_VAT_Total'+rowno).value = Math.round(vat_total*100)/100;
	document.getElementById('invc_Supplier_Unit_Cost'+rowno).value=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value)/(parseInt(document.getElementById('invc_Invoiced_Quantity'+rowno).value)?parseInt(document.getElementById('invc_Invoiced_Quantity'+rowno).value):1));
	//calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;
	document.getElementById('old_invc_Cost'+rowno).value=String(vat_total+parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value));
	show_Calculated_Invoice_Amount(rowno);
}
///////////////////////////
function blank_show_Calculated_Invoice_Amount(rowno)
{
	//calculated=0;
	//for(rowno=0;document.getElementById('invc_Tick'+rowno);rowno++)
	//{	
	balance=document.getElementById('invc_Balance_Amount').innerHTML;
	calculated=document.getElementById('invc_Calculated_Amount').innerHTML;
	oldcalc=calculated;
	net=document.getElementById('blankCompTotalNet'+rowno).value;
	vat=document.getElementById('blankCompTotalVat'+rowno).value;
	qty=document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value;
	if(validatex(net,'Double|0|.',1) && validatex(vat,'Double|0|.',1) && validatex(qty,'Int|1|.',1) ){
		val=(parseFloat(net)+parseFloat(vat));
		if(document.getElementById('blank_invc_Tick'+rowno).checked){
			calculated=parseFloat(val)+parseFloat(calculated);
			//document.getElementById('invc_Tick'+rowno).checked = true;
		}
		else if(!document.getElementById('blank_invc_Tick'+rowno).checked){
				calculated-=val;
				//document.getElementById('invc_Tick'+rowno).checked = false;
				/*if(document.getElementById('blank_edit_Tick'+rowno)){
					if(document.getElementById('blank_edit_Tick'+rowno).checked)
					document.getElementById('blank_edit_Tick'+rowno).checked=false;
					document.getElementById('invc_Invoiced_Net_Total'+rowno).readOnly = true;
					//document.getElementById('invc_Invoiced_Net_Total'+rowno).className ='Num_txtBox_disabled';		
					document.getElementById('invc_Invoiced_VAT_Total'+rowno).readOnly = true;
					//document.getElementById('invc_Invoiced_VAT_Total'+rowno).className ='Num_txtBox_disabled';	
					document.getElementById('invc_Invoiced_Quantity'+rowno).readOnly = true;
					//document.getElementById('invc_Invoiced_Quantity'+rowno).className ='Qty_txtBox_disabled'; 
					document.getElementById('Down_Image'+rowno).disabled = true;
					document.getElementById('Up_Image'+rowno).disabled = true;
					document.getElementById('edit_Tick'+rowno).itisdisabled=1;
				}*/
		}
	}/*
		document.getElementById('old_invc_Cost'+rowno).value=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
		if(document.frm_Main.invc_Tick[rowno]){
			if (document.frm_Main.invc_Tick[rowno].checked) {
				calculated+=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));				
				document.getElementById('invc_Tick'+rowno).checked = true;				
			}
			else if(!document.frm_Main.invc_Tick[rowno].checked){
				calculated-=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
				document.getElementById('invc_Tick'+rowno).checked = false;
				if(document.getElementById('edit_Tick'+rowno)){
				if(document.getElementById('edit_Tick'+rowno).checked)
					document.getElementById('edit_Tick'+rowno).click();}
			}
		}else if(document.frm_Main.invc_Tick){
			if (document.frm_Main.invc_Tick.checked) {				
				calculated+=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));				
				calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;
				document.getElementById('invc_Tick'+rowno).checked = true;
				
			}
			else if(!document.frm_Main.invc_Tick.checked){
				calculated-=(parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value));
				document.getElementById('invc_Tick'+rowno).checked = false;
				if(document.getElementById('edit_Tick'+rowno).checked)
					document.getElementById('edit_Tick'+rowno).click();;				
			}			
		}		
	//}*/
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(Math.round(calculated*100)/100));
	
	balance=document.getElementById('invc_Balance_Amount').innerHTML =number_format(String(Math.round((parseFloat(document.getElementById('fld_Invoice_Amount').value) - calculated)*100)/100));

}
function blank_calculate_vat_total(rowno) 
{
	if(validatex(document.getElementById('blankCompTotalNet'+rowno).value,'Double|0|.',1)){
	var vat_total;	
	
	calculated=parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML);
	calculated-=parseFloat(document.getElementById('blank_old_invc_Cost'+rowno).value);
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(calculated));
	
	balance=parseFloat(document.getElementById('invc_Balance_Amount').innerHTML);
	balance=parseFloat(balance)+parseFloat(document.getElementById('blank_old_invc_Cost'+rowno).value);
	document.getElementById('invc_Balance_Amount').innerHTML=number_format(String(balance));
	
	vat_total = ((document.getElementById('blankCompTotalNet'+rowno).value * document.getElementById('blank_invc_VAT'+rowno).value)/100);
	document.getElementById('blankCompTotalVat'+rowno).value = Math.round(vat_total*100)/100;
	document.getElementById('blank_invc_Supplier_Unit_Cost'+rowno).value=(parseFloat(document.getElementById('blankCompTotalNet'+rowno).value)/(parseInt(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value)?parseInt(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value):1));
	//calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;
	document.getElementById('blank_old_invc_Cost'+rowno).value=String(vat_total+parseFloat(document.getElementById('blankCompTotalNet'+rowno).value));
	blank_show_Calculated_Invoice_Amount(rowno);
	}else{
		alert('please enter a valid number');
		document.getElementById('blankCompTotalNet'+rowno).focus();
	}
}
function RemoveTrSupplierInv(rowno){

	val=parseFloat(document.getElementById('blankCompTotalVat'+rowno).value)+parseFloat(document.getElementById('blankCompTotalNet'+rowno).value);
	calculated=parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML);
	calculated-=val;
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(calculated));
	balance=parseFloat(document.getElementById('invc_Balance_Amount').innerHTML);
	balance=parseFloat(balance)+parseFloat(val);
	document.getElementById('invc_Balance_Amount').innerHTML=number_format(String(balance));
	document.getElementById('blankCompTotalVat'+rowno).value='0';
	document.getElementById('blankCompTotalNet'+rowno).value='0';
	
}
function blank_calculate_cost_supplier_inv_vatinput(rowno) {
	//var net_total, vat_total, pre_net_total, pre_vat_total ;
	if(document.getElementById('blank_invc_Supplier_Unit_Cost'+rowno).value==0)
	{
		if(parseInt(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value)!=0)
			document.getElementById('blank_invc_Supplier_Unit_Cost'+rowno).value=(parseFloat(document.getElementById('blankCompTotalNet'+rowno).value)/(parseInt(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value)?parseInt(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value):1));
	}
	net_total = (document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value * document.getElementById('blank_invc_Supplier_Unit_Cost'+rowno).value);
	vat_total =document.getElementById('blankCompTotalVat'+rowno).value; 
	/*(((document.getElementById('invc_Supplier_Unit_Cost'+rowno).value * document.getElementById('invc_VAT'+rowno).value)/100) * document.getElementById('invc_Invoiced_Quantity'+rowno).value);
	*/
	pre_total=parseFloat(document.getElementById('blank_old_invc_Cost'+rowno).value);
	//calculated-=(pre_total);
	calculated=parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML);
	calculated-=(pre_total);
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(calculated));
	
	balance=parseFloat(document.getElementById('invc_Balance_Amount').innerHTML);
	balance=parseFloat(balance)+parseFloat(pre_total);
	document.getElementById('invc_Balance_Amount').innerHTML=number_format(String(balance));
	/**/
	document.getElementById('blankCompTotalNet'+rowno).value = Math.round(net_total*100)/100;
	document.getElementById('blankCompTotalVat'+rowno).value = Math.round(vat_total*100)/100;
	//calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;	
	document.getElementById('blank_old_invc_Cost'+rowno).value=(parseFloat(net_total)+parseFloat(vat_total));
	blank_show_Calculated_Invoice_Amount(rowno);
}
function blank_calculate_cost_supplier_inv(rowno) {
	var net_total, vat_total, pre_net_total, pre_vat_total ;
	if(document.getElementById('blank_invc_Supplier_Unit_Cost'+rowno).value==0)
	{
		if(parseInt(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value)!=0)
			document.getElementById('blank_invc_Supplier_Unit_Cost'+rowno).value=(parseFloat(document.getElementById('blankCompTotalNet'+rowno).value)/(parseInt(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value)?parseInt(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value):1));
	}
	net_total = (document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value * document.getElementById('blank_invc_Supplier_Unit_Cost'+rowno).value);
	vat_total = (((document.getElementById('blank_invc_Supplier_Unit_Cost'+rowno).value * document.getElementById('blank_invc_VAT'+rowno).value)/100) * document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value);
	pre_total=parseFloat(document.getElementById('blank_old_invc_Cost'+rowno).value);
	//calculated-=(pre_total);
	calculated=parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML);
	calculated-=(pre_total);
	document.getElementById('invc_Calculated_Amount').innerHTML=number_format(String(calculated));
	
	balance=parseFloat(document.getElementById('invc_Balance_Amount').innerHTML);
	balance=parseFloat(balance)+parseFloat(pre_total);
	document.getElementById('invc_Balance_Amount').innerHTML=number_format(String(balance));
	/**/
	document.getElementById('blankCompTotalNet'+rowno).value = Math.round(net_total*100)/100;
	document.getElementById('blankCompTotalVat'+rowno).value = Math.round(vat_total*100)/100;
	//calculated_all+= ((parseFloat(document.getElementById('invc_Invoiced_Net_Total'+rowno).value) + parseFloat(document.getElementById('invc_Invoiced_VAT_Total'+rowno).value))) - document.getElementById('old_invc_Cost'+rowno).value;	
	document.getElementById('blank_old_invc_Cost'+rowno).value=(parseFloat(net_total)+parseFloat(vat_total));
	blank_show_Calculated_Invoice_Amount(rowno);
}
function blank_QTY_Supplier_Inv(rowno,step){
	if(validatex(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value,'Int|1|.',1) && validatex(document.getElementById('blankCompTotalVat'+rowno).value,'Double|0|.',1) && validatex(document.getElementById('blankCompTotalNet'+rowno).value,'Double|0|.',1)){
		document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value-=-step;
		blank_calculate_cost_supplier_inv(rowno);
	}else{
		if(!validatex(document.getElementById('blank_invc_Invoiced_Quantity'+rowno).value,'Int|1|.',1))
			document.getElementById('blank_invc_Invoiced_Quantity'+rowno).focus();
		if(!validatex(document.getElementById('blankCompTotalVat'+rowno).value,'Double|0|.',1))
			document.getElementById('blankCompTotalVat'+rowno).focus();
		if(!validatex(document.getElementById('blankCompTotalNet'+rowno).value,'Double|0|.',1))
			document.getElementById('blankCompTotalNet'+rowno).focus();		
		alert('Please enter a valid value.');
	}
}
function NewInvoiceOrNot(SupplierInvoiceStep2Keys,Counter){
	new_invoice=0;
	for(var i in SupplierInvoiceStep2Keys ){
		//alert('kjhgjhgkjhgkjhgkjhgkj');
		if(document.getElementById('invc_Tick'+i).checked){
		   new_invoice=1;
		}
	}
	for(i=0;i<=Counter;i++){
		if(document.getElementById('blankCompTotalVat'+i) && document.getElementById('blankCompTotalNet'+i)){
			if(document.getElementById('blankCompTotalVat'+i).value!=0 && document.getElementById('blankCompTotalVat'+i).style.display!='none')
				new_invoice=1;
			if(document.getElementById('blankCompTotalNet'+i).value!=0 && document.getElementById('blankCompTotalNet'+i).style.display!='none')
				new_invoice=1;
		}
	}
	//alert(Counter);
	return new_invoice;
}
function get_Selected_Rows_Supplier_Inv(SupplierInvoiceStep2Keys){
	solution=new Array;
	for(var i in SupplierInvoiceStep2Keys){
		if(!isNaN(parseInt(i))){
			if(document.getElementById('invc_Tick'+i) && document.getElementById('invc_Tick'+i).checked){
				solution[i]=new Array;
				solution[i]['fld_Order_Comp_No']=document.getElementById('invc_Order_Comp_No'+i).value;
				solution[i]['fld_Component_No']=document.getElementById('invc_Component_No'+i).value;
				solution[i]['fld_Project_No']=document.getElementById('fld_Project_No'+i).value;
				solution[i]['fld_Component_Reference']=document.getElementById('invc_Component_Reference'+i).value;
				solution[i]['fld_Component_Name']=document.getElementById('invc_Component_Name'+i).value;
				solution[i]['fld_Invoiced_Quantity']=document.getElementById('invc_Invoiced_Quantity'+i).value;
				solution[i]['fld_Invoiced_Net_Total']=document.getElementById('invc_Invoiced_Net_Total'+i).value;
				solution[i]['fld_Invoiced_VAT_Total']=document.getElementById('invc_Invoiced_VAT_Total'+i).value;
				solution[i]['fld_Component_Type']=document.getElementById('invc_Comp_typ'+i).value;


				//alert(solution[i]['fld_Order_Comp_No']+'-'+solution[i]['fld_Component_No']+'-'+solution[i]['fld_Project_No']+'-'+solution[i]['fld_Component_Reference']+'-'+solution[i]['fld_Component_Name']+'-'+solution[i]['fld_Invoiced_Quantity']+'-'+solution[i]['fld_Invoiced_Net_Total']+'-'+solution[i]['fld_Invoiced_VAT_Total']);
			}
		}
	}
	return solution;
}

function get_Selected_blank_Rows_Supplier_Inv(){//blank = Extra
	/*solution=new Array;
	for(i=0;i<=Counter;i++){
		if(document.getElementById('blankCompTotalVat'+i)){
			if(document.getElementById('blankCompTotalVat'+i).value!=0 || document.getElementById('blankCompTotalNet'+i).value!=0)
				solution[i]=i;
		}
	}
	return solution;*/
	return 'sjaasjdflj';
}
function Determine_Address_Type(selectedindex){
	address_type=selectedindex-(-1);
	if(address_type==1){
		determined=document.getElementById('client_no').value;
	}else if(address_type==2){
		determined=document.getElementById('fld_Agent_No').value;
	}else if(address_type==3){
		determined=document.getElementById('fld_Insurer_No').value;
	}
	return determined;
}
function set_price_list_insurer(price_list)	{
	len=document.getElementById('fld_Price_List_No').options.length;
	for(j=0;j<len;j++)	{
			val=document.getElementById('fld_Price_List_No').options[j].value;		
		if(val==price_list) { 
			document.getElementById('fld_Price_List_No').options[j].selected = true; 
		} 
	}
}
function supplier_inv_validation(){
	if (isNaN(parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML))){
		alert('Please reopen this PopUp Layer');
		return false;
	}
	if (isNaN(parseFloat(document.getElementById('invc_Balance_Amount').innerHTML))){
		alert('Please reopen this PopUp Layer');
		return false;
	}
	if (parseFloat(document.getElementById('invc_Balance_Amount').innerHTML) < 0){
		alert('Balance must be Posetive.');
		return false;
	}
	if (parseFloat(document.getElementById('invc_Calculated_Amount').innerHTML) > parseFloat(document.getElementById('invc_Invoice_Amount').innerHTML)){
		alert('Calculated must be Less than or equal to Invoice.');
		return false;
	}
	return true;	
}
///////////////////
function check_variation(){
	if(document.getElementById('fld_Old_Insurer_No').value!=document.getElementById('fld_Insurer').value || document.getElementById('fld_Old_Policy_No').value!=document.getElementById('fld_Policy_No').value || document.getElementById('fld_Old_Authorisation').value!=document.getElementById('fld_Authorisation').value || document.getElementById('fld_Old_Excess').value!=document.getElementById('fld_Excess').value)
		if(confirm('The Insurer detail have been modified - click OK to update the original Referral?')){
			document.getElementById('project_change').value=1;
			return true;
		}else{
			return true;
		}
	else
		return true;	
}
function Set_Address_Type()
{
	sel=document.getElementById('fld_Invoice_Address').selectedIndex;
	//alert(sel);
	if(sel>=0)
	{
		document.getElementById('fld_Invoice_Address_Type').value=sel;
	}
}
function show_provider_num(user_id){
	providers = explodeArray(document.getElementById('provider_num').value,',');
	if(user_id != 0 && user_id!=''){
		for(i = 0; i < providers.length; i++){
			num_pro = explodeArray(providers[i],'-');
				if(num_pro[0]==user_id)
					return num_pro[1];
				else
					continue;
		}
	}else{
		return '<span class="red"><strong>Please select a Doctor</span></strong>';
	}	
}
function moveOrder(f,bDir,sName,element) {
 var el = f.elements[element + "[]"]
 var idx = el.selectedIndex
 if (idx==-1) 
  alert("You must first select the item to reorder.")
 else {
  var nxidx = idx+( bDir? -1 : 1)
  if (nxidx<0) nxidx=el.length-1
  if (nxidx>=el.length) nxidx=0
  var oldVal = el[idx].value
  var oldText = el[idx].text
  el[idx].value = el[nxidx].value
  el[idx].text = el[nxidx].text
  el[nxidx].value = oldVal
  el[nxidx].text = oldText
  el.selectedIndex = nxidx
 }
}