/**
 * check if the field is empty
 */
function isEmpty(s) {
	if (s.length == 0) return true;
	if (trim(s).length == 0) return true;
	return false;
}

//	TODO: check the function
function isEmail(s) {
	return isValidEmail(s);
}

/**
 * Validates the email address.
 */
function isValidEmail(s) {
	var v = trim(s);
	var we_had_monkey = false, relief = true;
	var we_had_dot = false;
	var count = 0;
	
	// sta je dobra email adresa?
	// mora da ima jedno majmunce
	// ne sme da ima razmake, moze da ima slova, cifre, crtice
	for(i = 0; i < v.length; i++) {
		c = v.charAt(i);
		count++;
		
		// tacka ne sme da ide iza majmunceta i
		// dve tacke ne smeju da idu jedna za drugom
		if (we_had_monkey == true) {
			if (c == '.') {
				we_had_dot = true;
				if (relief == true) {
					relief = false;
					continue;
				} else {
					return false;
				}
			}
			if (relief == false) relief = true;
		} else {
			if (c == '.') continue;
			if (c == '@') {
				// ima li znakova ispred majmunceta?
				if (count == 1) {
					return false;
				}
				count = 0;
				we_had_monkey = true;
				relief = false;
				continue;
			}
		}
		
		// standardno, slova, cifre i crtice su dozvoljeni
		if ((c >= 'a')&&(c <= 'z')) continue;
		if ((c >= 'A')&&(c <= 'Z')) continue;
		if ((c >= '0')&&(c <= '9')) continue;
		if ((c == '-')||(c == '_')) continue;
		if ((c == "'")) continue;
		
		return false;
	}
	
	
	// vracamo netacno ako nismo imali majmunce
	if (we_had_monkey == false) return false;
	else {
		// vracamo netacno ako je majmunce poslednji znak
		if (c == '@') return false;
		if (c == '-') return false;
		if (c == '_') return false;
		if (c == "'") return false;
		// vracamo netacno i ako je tacka poslednji znak i pretposlednji znak
		if ((c == '.')||(v.charAt(i-2) == '.')) return false;
		// vracamo netacno i ako nismo imali tacku posle majmunceta
		if (we_had_dot == false) return false;
		// vracamo netacno i ako je pred
	}
	return true;
}


function isPassword(s) {
	return true;
}
	
function trim(s) {
	var i = 0;
	while(isspace(s.charAt(i))) i++;
	if (i == s.length) return new String('');
		
	var j = s.length - 1;
	while(isspace(s.charAt(j))) j--;
		
	return s.substring(i, j + 1);
}
	
function isspace(c) {
	if (c == ' ') return true;
	if (c == '\n') return true;
	return false;
}
	
function isFloat(string) {
	return isNaN(parseFloat(string));
}

/**
 * Checks whether parameter is a number.
 */
function isNumber(s) {
	var v = trim(s);
	var i, c, we_had_dot = false;
	
	for(i = 0; i < v.length; i++) {
		c = v.charAt(i);
		if (i == 0) if ((c == '-')||(c == '+')) continue;
		if ((c == '.')&&(we_had_dot == false)) {
			we_had_dot = true;
			continue;
		}
		if ((c < '0') || (c > '9')) return false;
	}
	
	// todo: ubaciti da vrednosti 2*10^8 budu neke globalne promenljive cija se vrednost lako moze izmeniti
	if (v > 2000000000 || v < -2000000000) {
		return false;
	}
	
	return true;
}

/**
 *
 */
function verifyDate(day, month, year) {
	if ( isEmpty(day.value) || isEmpty(month.value) || isEmpty(year.value) )
		return false;
	
	var _day = parseInt(day.value, 10);
	var _month = parseInt(month.value, 10);
	var _year = parseInt(year.value, 10);
	
	// alert('[verifyDate checkpoint 1] ' + _day + '-' + _month + '-' + _year);
	
	if (isNaN(_day) || isNaN(_month) || isNaN(_year))
		return false;
	
	if ((_month < 1) || (_month > 12)) return false;
	
	var max_day_count;
	switch(_month) {
		case  1 :
		case  3 :
		case  5 :
		case  7 :
		case  8 :
		case 10 :
		case 12 :
			max_day_count = 31;
			break;
			
		case  2 :
			if ((_year % 4) == 0) max_day_count = 29;
			else max_day_count = 28;
			break;
			
		default :
			max_day_count = 30;
	}
	
	if ((_day < 1) || (_day > max_day_count)) return false;
	return true;
}

/**
 *
 */
function verifyDate2(_date) {
	if (isEmpty(_date))
		return false;
	
	var _day = parseInt(_date.substring(8, 10), 10);
	var _month = parseInt(_date.substring(5, 7), 10);
	var _year = parseInt(_date.substring(0, 4), 10);
	
	// alert('[verifyDate checkpoint 1] ' + _day + '-' + _month + '-' + _year);
	
	if (isNaN(_day) || isNaN(_month) || isNaN(_year))
		return false;
	
	if ((_month < 1) || (_month > 12)) return false;
	
	var max_day_count;
	switch(_month) {
		case  1 :
		case  3 :
		case  5 :
		case  7 :
		case  8 :
		case 10 :
		case 12 :
			max_day_count = 31;
			break;
			
		case  2 :
			if ((_year % 4) == 0) max_day_count = 29;
			else max_day_count = 28;
			break;
			
		default :
			max_day_count = 30;
	}
	
	if ((_day < 1) || (_day > max_day_count)) return false;
	return true;
}


/**
 * Prepare date form fields printed with print_form_date1()
 */
// todo: in development
function createDate1(outfield, infield, required) {
// todo: for print_form_date1()
	outfield.value = '9999-01-01';
	
	_date = infield.value;
	
	// todo: parse for incomplete date
	var _day = parseInt(_date.substring(0, 2), 10);
	var _month = parseInt(_date.substring(3, 2), 10);
	var _year = parseInt(_date.substring(6, 4), 10);
	
	if ((required != 'no') || (isEmpty(_date) != false))
		if (verifyDate(_day, _month, _year) == false) return false;
	
	return createDate(outfield, _day, _month, _year);
}

/**
 * Prepare date form fields printed with print_form_date2/3()
 */
function createDate(outfield, day, month, year) {
	outfield.value = '9999-01-01 00:00:00';
	
	// accept no date at all
	if (isEmpty(day.value) && isEmpty(month.value) && isEmpty(year.value)) return true;
	
	// alert(day.value + '-' + month.value + '-' + year.value);
	
	if (verifyDate(day, month, year) == false) return false;
	
	var _day = parseInt(day.value, 10);
	var _month = parseInt(month.value, 10);
	var _year = parseInt(year.value, 10);
	
	var mzero = '';
	var dzero = '';
	
	if (_month < 10) mzero = '0';
	if (_day < 10) dzero = '0';
	
	outfield.value = '' + _year + '-' + mzero + _month + '-' + dzero + _day;
	
	return true;
}

/**
 *	Checks if some data field has been modified on the page
 */

function isModified() {
	if (is_modified)
		if (!confirm('Data on this page has been modified.\nIf you proceed, changes wont\'t be saved.\nProceed anyway?'))
			return false;
	return true;
}

/**
 *	Check if the supplied string is an image
 *	
 *	Note: check is the image mandatory using isEmpty() before
 */
function isImage(filename) {

	filename = trim(filename).toLowerCase();
	if (filename == '') return true;
	var l = filename.length;
	if (l < 5) return false;

	if (filename.substr(l - 4) == '.jpg') return true;
	if (filename.substr(l - 4) == '.png') return true;
	if (filename.substr(l - 4) == '.gif') return true;
	if (filename.substr(l - 5) == '.jpeg') return true;
	if (filename.substr(l - 4) == '.pdf') return true;

	return false;
}
function isImage_editor(filename) {

	filename = trim(filename).toLowerCase();
	if (filename == '') return true;
	var l = filename.length;
	if (l < 5) return false;

	if (filename.substr(l - 4) == '.jpg') return true;
	if (filename.substr(l - 4) == '.png') return true;
	if (filename.substr(l - 4) == '.gif') return true;
	if (filename.substr(l - 5) == '.jpeg') return true;
	//if (filename.substr(l - 4) == '.pdf') return true;

	return false;
}

/**
 *	Check if the supplied number is positive integer
 *	
 *	
 */

function isPosInteger(inputVal) {
	inputStr = inputVal.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if (oneChar < '0' || oneChar > '9') {
			return false;
		}
	}
	return true;
	
}

/*
 *
 *  Format Number
 *
 *
 */
/*
	This variables must be included in script:
	
	var separator = ',';  
	var decpoint = '.'; 
	var percent = '%';
	var currency = '$'; 
	
 */
 
function formatNumber(number, format, print) {  
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null; 
    var useSeparator = format.indexOf(separator) != -1; 
    var usePercent = format.indexOf(percent) != -1; 
    var useCurrency = format.indexOf(currency) != -1; 
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency); 
    number = "" + number;


    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";


    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";


    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);

      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  
        else break;
      }
    }


    sleftEnd = strip(sleftEnd, '#');
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd; 
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : ""); 
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
}

function strip(input, chars) {  
    var output = ""; 
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
}

function separate(input, separator) { 
    input = "" + input;
    var output = "";  
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
}


<!-- new alterbox code -->
var lastVisitedId = '';
function newAlertBox(id)	{
	
	lastVisitedId = id;
	var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	var docheightcomplete=(standardbody.offsetHeight>standardbody.scrollHeight)? standardbody.offsetHeight : standardbody.scrollHeight
	var docwidthcomplete=(standardbody.offsetWidth>standardbody.scrollWidth)? standardbody.offsetWidth : standardbody.scrollWidth

	document.getElementById("popup").style.height = docheightcomplete+"px";
	document.getElementById("popup").style.width = docwidthcomplete + 'px';

	if (navigator.appName != "Microsoft Internet Explorer")	{
		document.getElementById(lastVisitedId).style.position = "fixed";
	}
	else	{
		document.getElementById(lastVisitedId).style.position = "absolute";
	}

	selects = document.getElementsByTagName("select");

	if(document.getElementById(lastVisitedId).style.display == ''){ 
		document.getElementById(lastVisitedId).style.display = 'none'; 
		document.getElementById('popup').style.display = 'none'; 
		for (i = 0; i != selects.length; i++)		{
			selects[i].style.visibility = 'visible';
		}	
	} else { 
		document.getElementById(lastVisitedId).style.display = '';
		document.getElementById('popup').style.display = '';
	
		for (i = 0; i != selects.length; i++)		{
			if(selects[i].name != 'idofemp')	{
				selects[i].style.visibility = 'hidden';
			}
		}	
		scroll(0,0);
	}
}
function closeAlertBox()	{
	document.getElementById(lastVisitedId).style.display = 'none'; 
	document.getElementById('popup').style.display = 'none'; 
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) 
	{
	selects[i].style.visibility = 'visible';
	}
} 
<!-- new alterbox code -->

function gothisdirectly(path,value,vs)	{
location.href = path;
if(vs!='N')
d.s(value);
//d.o(value);
} 
// ---------------------------------HTTP REQUEST OBJECT---------------------------------------------------------------
function createRequestObject()
 { 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	    objXMLHttp=new XMLHttpRequest();
	else if (window.ActiveXObject)
	    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	return objXMLHttp;
 }
 
// ---------------------------------HTTP REQUEST OBJECT---------------------------------------------------------------
// ---------------------------------FREEZE SCREEN-----------------------------------------------------------------------
function FreezeScreen(msg)
 {
      scroll(0,0);
      var outerPane = document.getElementById('FreezePane');
      var innerPane = document.getElementById('InnerFreezePane');
	  innerPane.style.display='block';
      if (outerPane) outerPane.className = 'FreezePaneOn';
      if (innerPane) innerPane.innerHTML =  '&nbsp;<font color="White"size="2" face="Trebuchet MS"><b>'+msg+'</b></font>';
	  innerPane.style.display='block';
   }
   
// ---------------------------------FREEZE SCREEN-----------------------------------------------------------------------
function viewCustomer() {
    var f = document.c_list;	
    if (f.corp_id.value != -1 ) {
	    var selectedIndexVal = f.corp_id.value;
		var selectedIndexValOpt = f.corp_id_opt.value;
		if(selectedIndexVal=='0')
		{
			if(selectedIndexValOpt=='orders')
			{
			var url='default_order_manager.php';
		 	go('printer/'+ url);
			//Get_Customerid(selectedIndexVal);
			}
			if(selectedIndexValOpt=='settings')
			{
			var url='preferences.php';
		 	go('printer/'+ url);
			}
			if(selectedIndexValOpt=='products')
			{
			var url='products_wizards.php?adv=on';
		 	go('printer/'+ url);
			}
			if(selectedIndexValOpt=='rfq')
			{
			var url='rfq.php?corporateid=0';
		 	go('printer/'+ url);
			}
		}
		if(selectedIndexVal !='0' && selectedIndexVal !='-1')
		{
			if(selectedIndexValOpt=='orders')
			{
				var url='orders.php?customerid='+selectedIndexVal;
				go('printer/'+ url);
			}

			if(selectedIndexValOpt=='products')
			{
			var url='customers_products.php?corporateid='+selectedIndexVal+'&categoryid='+selectedIndexVal;
			go('printer/'+ url);
		 	}
			
			if(selectedIndexValOpt=='settings')
			{
			var url='customers_configure.php?corporateid='+selectedIndexVal;
			go('printer/'+ url);
		 	}
			
			if(selectedIndexValOpt=='rfq')
			{
			var url='rfq.php?corporateid='+selectedIndexVal;
			go('printer/'+ url);
		 	}
		}
	}
	
}
// ---------------------------------ChangeLanguageD---------------------------------------------------------------
function ChangeLanguage(languageid)
{
	FreezeScreen("Loading....")
	//alert(languageid);
	//echo "TEST $PHP_SELF";
	xUrl = window.location;
	xUrl += '';
	if (xUrl.indexOf("languageid=")  > 0 ) {
		xUrl = xUrl.replace('languageid=','');
	}
	if (xUrl.indexOf('?') > 0) {
		xUrl += '&languageid=' + languageid;
	}
	else
		xUrl += '?languageid=' + languageid;
	window.location.href=xUrl;

}
// ---------------------------------ChangeLanguage---------------------------------------------------------------
// ---------------------------------funcgo---------------------------------------------------------------
function funcgo() 
	{ 
		var f = document.c_list;    
		if (f.navig12.value == '') 
		{
		alert('Please enter some text .');
		return false;
		}
        f.action = 'customers.php?typ=y';
        f.submit();
    
    }
// ---------------------------------funcgo---------------------------------------------------------------
function emailThisPdf_fun_res()	{
	if(http.readyState==4)    	{
		var r=http.responseText;
		
	    document.getElementById("emailthispdf_load").style.display = 'none';  
		document.getElementById("emailthispdf_content").innerHTML = r;
	    document.getElementById("emailthispdf_content").style.display='block';
	    document.getElementById("emailthispdf_container1").style.display='block';
	}
	else	{
		document.getElementById("emailthispdf_load").style.display="block";
	}
}
function emailThisPdf_fun(val,jobid)	{
	if(val == 'ods_job')	{
		var url="emailThisPdf_action.php?jobid="+jobid+"&val="+val;
		
		http=createRequestObject();
		http.onreadystatechange=emailThisPdf_fun_res; 
		http.open("GET",url);
		http.send(null);
		
	}
	else if (document.getElementById("emailthispdf_container1").style.display=='none') {
		displayFloatingDiv_emailthispdf('emailthispdf_container');
		document.getElementById("emailthispdf_container1").style.display="block";
		document.getElementById("emailthispdf_load").innerHTML = '<img src="ajax-loader-4.gif"> Loading...';

		var url="emailThisPdf_action.php?jobid="+jobid+"&val="+val;
		
		if(val == 'ods_product')	{
			getDiv('ods_product');
			return false;
		}
		http=createRequestObject();
		http.onreadystatechange=emailThisPdf_fun_res; 
		http.open("GET",url);
		http.send(null);
	}
	else	{
		if(val == 'close')	{
			document.getElementById("emailthispdf_container1").style.display='none';
			hiddenFloatingDiv_first('emailthispdf_container');
		}
		else	if(val == 'Send')	{
			var f = document.forms['emailThisPdf_form'];
			var emailArray = document.getElementById('to_email').value.split(',');
			var i=0;
			var alerttxt = 'Please enter a valid Email ID.';
			document.getElementById("to_email_txt").style.display = 'none';
			document.getElementById("to_email_valid").style.display = 'none';
			document.getElementById("email_subject_txt").style.display = 'none';
			if(isEmpty(document.getElementById('to_email').value))	{
				document.getElementById("to_email_txt").style.display = '';
				f.to_email.focus();
				return false;
			}
			for(i = 0; i < emailArray.length; i++)	{
				if(!isEmail(emailArray[i]))	{
					document.getElementById("to_email_valid").style.display = '';
					f.to_email.focus();
					return false;
				}
			}
			if(isEmpty(document.getElementById('email_subject').value))	{
				document.getElementById("email_subject_txt").style.display = '';
				f.email_subject.focus();
				return false;
			}
			f.submit();
			document.getElementById("emailthispdf_content").style.display = 'none';
			document.getElementById("emailthispdf_load").innerHTML = '<img src="ajax-loader-4.gif"> Sending Message...';
			document.getElementById("emailthispdf_load").style.display = 'block';	
		}
	}
}
var timeHolder = '';
function emailThisPdf_res(val)	{
	document.getElementById("emailthispdf_load").innerHTML = '<div style="clear:both;color:#FF0000;font-size:14px;font-weight:bold;padding:5px;padding-bottom:0px;"><img class="fright" style="cursor:pointer" src="../common/images/close-small.gif" width="17" height="17" alt="Close" border="0" onClick="clearTimeOutAndClose()"></div><div style="clear:both;color:#FF0000;font-size:14px;font-weight:bold;">Message Sent</div>';
	timeHolder = setTimeout("hiddenFloatingDiv_first('emailthispdf_container')",3000);
}
function clearTimeOutAndClose()	{
	clearTimeout(timeHolder);
	hiddenFloatingDiv_first('emailthispdf_container');
}
function setTextAreaHeight(objects)        {
	var obj=objects.value;
	var id=objects.id
	// alert("objects.value=="+objects.value);
	var i = 0;
	var rowCount = 0;
	while(obj.length != i) {
	if (obj.charAt(i) == '\n')        {
	rowCount = eval(rowCount+1);
	}
	i++;
	}
	if(rowCount > 3)
	document.getElementById(id).rows = eval(rowCount+2);
	else
	document.getElementById(id).rows = eval(4);
}
// ---------------------------- TO check whether the filename is csv file name -------------------------------
function isCSVFile(filename) {

	filename = trim(filename).toLowerCase();
	if (filename == '') return true;
	var l = filename.length;
	if (l < 5) return false;

	if (filename.substr(l - 4) == '.csv') return true;

	return false;
}
// ---------------------------- /TO check whether the filename is csv file name ----------------------------
// ---------------------------- following function is used for show price development -------------------
var isOds = '';
var display_job_price = 'Y';

	function showprice()	{
		if(document.getElementById("showprice_id") && display_job_price == 'N') {
		document.getElementById("showprice_id").style.display = 'none';
		return false;
		}
         if(document.getElementById("showprice_id"))
		document.getElementById("showprice_id").style.display = '';
		var allow_flag = true;
		if(isOds == 'Y')
		var fname = document.forms['odsform'];
		else
		var fname = document.forms['order_preview'];

		var price=0;
		var unitQuantity=0;
		var unitPrice=0;
		var unitWeight=0;
		var Quantity=0;
		if(stocKItem=='Y')	{
			if(document.order_preview.order_type[1].checked==true)		{
				var qty = fname.replenish_qty.value;
				price = repl_price_array[qty];
			}
			else	{
				if(qtyChoiceTYpe=='O')	{
					Quantity   = fname.qty.value;
					unitPrice = fname.unitPrice.value;
					unitQuantity =fname.unitQty.value;
					unitWeight =fname.unitWeight.value;
					price = (Quantity * unitPrice)/(unitQuantity);
				}
				else	{
					var qty = fname.qty.value;
					price = price_array[qty];
				}
			}
		}
		else if(qtyChoiceTYpe=='O')	{
			Quantity   = fname.qty.value;
			unitPrice = fname.unitPrice.value;
			unitQuantity =fname.unitQty.value;
			unitWeight =fname.unitWeight.value;
			price = (Quantity * unitPrice)/(unitQuantity);
		}
		else	{
			var qty = fname.qty.value;
			price = price_array[qty];
		}
		var fieldIDValue = 0;
		var fieldID = '';
		var fieldIDPrice = 0;
		if(is_additional > 0)	{
			for (var j = 0; j < loop_array.length-1; j++) {
			fieldIDValue = ''
				if(loop_array[j][1] == 'D')	{
					fieldID = loop_array[j][1]+loop_array[j][0];
					fieldIDValue = eval('fname.'+fieldID+'.value');

					if(fieldIDValue != '')
					{
					if(add_array[fieldIDValue][1] == 'F'){

					fieldIDPrice = eval(fieldIDPrice+add_array[fieldIDValue][0]);

					} else if(add_array[fieldIDValue][1] == 'P') {
					   fieldIDPrice = eval(fieldIDPrice+(price/100)*add_array[fieldIDValue][0]);
					}
					}
				}
				if(loop_array[j][1] == 'C')	{
					fieldID = loop_array[j][1]+loop_array[j][0];
					if(eval('fname.'+fieldID+'.checked'))	{
						fieldIDValue = eval('fname.'+fieldID+'.value');

					if(add_array[fieldIDValue][1] == 'F'){

					fieldIDPrice = eval(fieldIDPrice+add_array[fieldIDValue][0]);

					} else if(add_array[fieldIDValue][1] == 'P') {

					 fieldIDPrice = eval(fieldIDPrice+(price/100)*add_array[fieldIDValue][0]);

					}
					}
				}
				if(loop_array[j][1] == 'R')	{
					fieldID = loop_array[j][1]+loop_array[j][0];
					for(k = 0;k<eval('fname.'+fieldID+'.length'); k++)	{
					var kfieldID = fieldID+'['+k+']';
						if(eval('fname.'+kfieldID+'.checked') && eval('fname.'+kfieldID+'.value') != 'none')	{
							fieldIDValue = eval('fname.'+kfieldID+'.value');

							if(add_array[fieldIDValue][1] == 'F'){
							fieldIDPrice = eval(fieldIDPrice+add_array[fieldIDValue][0]);
							} else if(add_array[fieldIDValue][1] == 'P') {
							 fieldIDPrice = eval(fieldIDPrice+(price/100)*add_array[fieldIDValue][0]);
							}


						}
					}
				}
			}
		}
	//alert(fieldIDPrice+" === "+price);
		var totalEstPrice = parseFloat(fieldIDPrice)+parseFloat(price);
		//alert(totalEstPrice);
		if(document.getElementById("showprice_id"))
		document.getElementById("showprice_id").innerHTML = "Price: <b>"+currency+""+formatNumber(totalEstPrice, ',.00')+"</b>";
	}
// ---------------------------- /following function is used for show price development -------------------
//----------------------------------ADDITIONAL ATTACH FILES-----------------------------------------------------------
var is_storefront = 'N';
function attach_files_qp() {
	if (document.getElementById("additional_file").style.display=='block') {
        if(is_storefront == 'Y')
		document.getElementById("attach_text").innerHTML = '<a href="javascript:attach_files_qp()" class="buttonType2small"><span>Upload</span></a>';
		else
		document.getElementById("attach_text").innerHTML = '<a href="javascript:attach_files_qp()">Attach a file</a>';
		document.getElementById("additional_file").style.display='none';
	} else {
		document.getElementById("attach_text").innerHTML = '';
		document.all.frame_additional_files.src="upload_job_file.php";
		document.getElementById("additional_file").style.display='block';
	}
}
function attach_files_res(res) {
		if(isOds == 'Y')
		var f = document.forms['odsform'];
		else
		var f = document.forms['order_preview'];
var t=trim2(res);
f.imagename.value=t;
f.imgname.value=t;
		document.getElementById("additional_file").style.display='none';
        if(is_storefront == 'Y')
        document.getElementById("attach_text").innerHTML = '<label style="float: left;padding: 3px 10px 4px;">'+t+"</label> &nbsp;"+showviewtype(t)+"&nbsp; <a href='javascript:clear_file_details();' class='buttonType2small' style='margin-left:3px;'><span>clear</span></a>";
		else
        document.getElementById("attach_text").innerHTML = "<div style='float:left;padding-top:5px;'>"+t+" &nbsp;</div><div style='padding-top:5px;float:left'>"+showviewtype(t)+"</div><div style='float:left;padding-top:5px;'>&nbsp; <a href='javascript:clear_file_details();' style='color:grey;'>clear</a></div>";
}
function showviewtype(filename) {
	filename = trim(filename).toLowerCase();
	if (filename == '') return true;
	var l = filename.length;
	if (l < 5) return false;

	if (filename.substr(l - 4) == '.jpg' || filename.substr(l - 4) == '.png' || filename.substr(l - 4) == '.gif' || filename.substr(l - 5) == '.jpeg') {
        if(is_storefront == 'Y')   {
            if(isOds == 'Y')
            return '<a href="javascript:open_image_preview(\''+filename+'\');" class="buttonType2small"><span>View File</span></a>';
            else
            return '<a href="javascript:Create_ImagePreview_new(\''+lightbox_pathfilename+filename+'\',1);" class="buttonType2small"><span>View File</span></a>';
        }
        else {
            if(isOds == 'Y')
            return '<img src="../common/images/icon-view.gif" onclick="open_image_preview(\''+filename+'\');" title="Preview" style="cursor: pointer;" align="bottom">';
            else
            return '<img src="../common/images/icon-view.gif" onclick="Create_ImagePreview_new(\''+lightbox_pathfilename+filename+'\',1);" title="Preview" style="cursor: pointer;" align="bottom">';
    }
    }
    else if(filename.substr(l - 4) == '.pdf' )        {
        if(is_storefront == 'Y')
        return '<a href="javascript:showPdfPreview(\''+filename+'\');" class="buttonType2small"><span>View File</span></a>';
        else
    return '<img src="../common/images/icon-pdf.gif" title="Preview" style="cursor: pointer;" align="bottom" onclick="showPdfPreview(\''+filename+'\')">';
    }
    else {
        if(is_storefront == 'Y')
        return '<a href="download.php?name='+filename+'" class="buttonType2small"><span>View File</span></a>';
        else
    return '<a href="download.php?name='+filename+'">Download</a>';
    }
}
function open_image_preview(name) {
  var xyz =window.open( "open_image_preview.php?name="+name+"", "imgwin", "width=650,height=500,scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=yes,menubar=no" )
}
function clear_file_details()  {
		if(isOds == 'Y')
		var f = document.forms['odsform'];
		else
		var f = document.forms['order_preview'];
        if(is_storefront == 'Y')
		document.getElementById("attach_text").innerHTML = '<a href="javascript:attach_files_qp()" class="buttonType2small"><span>Upload</span></a>';
		else
		document.getElementById("attach_text").innerHTML = '<a href="javascript:attach_files_qp()">Attach a file</a>';
        f.imagename.value='';
        f.imgname.value='';
		document.getElementById("additional_file").style.display='none';
}
 function showPdfPreview(filename)  {
         var f = document.forms['search'];
         f.action = "download.php?name="+filename;
         f.target = '_blank';
         f.method= 'post';
         f.submit();
 }
//----------------------------------ADDITIONAL ATTACH FILES-----------------------------------------------------------

//---------------------------------Below js is for Order Processing - Jean slowness issue----------------
function light() {
	var mouseY = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;

	var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	var docheightcomplete=(standardbody.offsetHeight>standardbody.scrollHeight)? standardbody.offsetHeight : standardbody.scrollHeight
	var docwidthcomplete=(standardbody.offsetWidth>standardbody.scrollWidth)? standardbody.offsetWidth : standardbody.scrollWidth

	document.getElementById("lightup").style.height = docheightcomplete+"px";
	document.getElementById("lightup").style.width = docwidthcomplete + 'px';
	document.getElementById("lightup").style.display = '';

	var event_left = (docwidthcomplete/2)-100;
	document.getElementById("lightup_msg_blk").style.top = mouseY+180+"px";
	document.getElementById("lightup_msg_blk").style.left = event_left+"px";
	document.getElementById("lightup_msg_blk").style.display = '';
}
//--------------------------------- /Below js is for Order Processing - Jean slowness issue----------------


