function newImage(strSrc){
	
	ni = new Image();
	ni.src = strSrc;
	
	return ni;
	
}

function trim(str){

	if(typeof(str) != "string") return "";

	var regexp = /[\n\r\t ]+$/;
	str = str.replace(regexp, "");
	
	regexp = /^[\n\r\t ]+/;
	str = str.replace(regexp, "");
	
	return str;

}

function isEmail(v){

	v = trim(v);

	if(v.indexOf("..") > -1 ) return false;
	if(v.indexOf("@") == -1 )  return false;
	if(v.indexOf("@.") > -1 ) return false;
	if(v.indexOf(" ") > -1 )  return false;
	
	var re = /^[a-zA-Z._0-9-]+@[a-zA-Z0-9]{1}[a-zA-Z_0-9-]+\.[a-zA-Z]+[.]?[a-zA-Z]{0,3}$/;
	
	return re.test(v); 
	
}


function isPhone(v){
	
	v = trim(v);
	v = v.replace(" ","");

	var re = /^(\([0-9]{3}\))?[0-9]{3}[-]?[0-9]{4}$/;
	result = re.test(v);
	
	if (!result) {
	 re = /^[[0-9]{3}]?[0-9]{3}[-]?[0-9]{4}$/;
	 result = re.test(v);
	}
	
	return result;
}


function isZip(v){
	
	v = trim(v);
	v = v.replace(" ","");

	var re = /^[0-9]{5}([-][0-9]{4})?$/;
	result =  re.test(v);
	
	return result;
}


function isEmpty(str){
	
	str = trim(str);
	
	if(str == ''){
		return true;
	}
	else{
		return false;
	}

}

function isDate(strDate){
    
	// MM-DD-YYYY
	var day = "29";
	var month = "2";
	var year = "2007";
    var date = new Date();
    var blnRet = false;
    var blnDay;
    var blnMonth;
    var blnYear;
	var arr;
	
	strDate = trim(strDate);
	if(strDate.indexOf("/") > -1){
		arr = strDate.split("/");
		if(arr.length == 3){
			year  = arr[2];
			month = arr[0];
			day   = arr[1];
		}
	}
	else if(strDate.indexOf("-") > -1){
		arr = strDate.split("-");
		if(arr.length == 3){
			year  = arr[2];
			month = arr[0];
			day   = arr[1];
		}
	}

    date.setFullYear(year, month -1, day);

    blnDay   = (date.getDate()  == day);
    blnMonth = (date.getMonth() == month -1);
    blnYear  = (date.getFullYear()  == year);

    if (blnDay && blnMonth && blnYear){
        blnRet = true;
	}
	
    return blnRet;
	
}

function isNumeric(str){

	var i;
	var q;
	var c;
	
	str = str.toString();
	q = str.length;
	
	for(i = 0; i < q; i++){
		c = str.charAt(i);
		if(c < "0" || c > "9"){
			return false;
		}
	}

	return true;

}

function isCurrency(argvalue){

	argvalue = argvalue.toString();
	if(argvalue == ""){
		return false;
	}
	var validChars = "0123456789.";
	var startFrom = 0;
	
	// Currency can not be negative for SCEA ITS
	if (argvalue.charAt(0) == "-") {
		return false;
	}
	
	argvalue = argvalue.replace(/,/g, '');
	
	if(argvalue.indexOf(".") > -1){
		if(argvalue.substring(argvalue.indexOf(".")).length > 3){
			return false;
		}
	}

	for (var n = startFrom; n < argvalue.length; n++) {
	    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
	}

	return true;

}

function isLetters(argvalue){
	
	argvalue = argvalue.toString();
	argvalue = argvalue.toLowerCase();
	var validChars = "abcdefghijklmnopqrstuvwxyz";

	if(argvalue.indexOf(".") > -1){
		if(argvalue.substring(argvalue.indexOf(".")).length > 3){
			return false;
		}
	}

	for (var n = 0; n < argvalue.length; n++) {
	    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
	}

	return true;
	
}


function getLayer(id){
	
	  if (document.getElementById){
		    return document.getElementById(id);
	  }
	  else if (document.all){
		    return document.all[id];
	  }
	  else if (document.layers){
		    return document.layers[id];
	  }
	  return null;
}


function setDisplay(strName, strStatus){
	
	var ly = getLayer(strName);
	
	if(ly){ 
		ly.style.display = strStatus;
	}
	
}

function setInnerHTML(strName, strTxt){
	
	var ly = getLayer(strName);
	
	if(ly){ 
		ly.innerHTML = strTxt;
	}
	
}

function clearNotCurrency(o){
	
	var str = o.value;
	var regexp = /[^0-9.]/g;
	
	str = str.replace(regexp, "");
	o.value = str;
	
}

function FormSelect(form, strField, strValue){ 

	if(strValue == ""){
		strValue = '0';
	}

	var un = form[strField].length;

    for(j=0; j < un; j++){
       if(form[strField].options[j].value == strValue){ 
            form[strField].options[j].selected = true
       }
    }
    
    return;
}

function FormCheckRadio(form, strField, strValue){
	
	var un = form[strField].length; 
    for(j=0; j < un; j++){
       if(form[strField][j].value == strValue){ 
            form[strField][j].checked = true;
       }
    }
    
    return;
	
}

function FormCheck(form, strField, strValue){ 

	if(strValue == ""){
		return; 
	}
	else{
		var r = /[ ]{1,}/gi;
		strValue = strValue.replace(r, "");
		strValue = ',' + strValue + ',';
	}

	var un = form[strField].length;
	var comp = '';
    for(j=0; j < un; j++){
	   comp = ',' + form[strField][j].strValue + ',';
       if(strValue.indexOf(comp) > -1)
            form[strField][j].checked = true
    }
    
    return;
}

function validateDate(f, field, strMsgEmpty, strMsgError){
	
	if(isEmpty(f[field].value)){
		alert(strMsgEmpty);
		f[field].focus();
		return false;
	}
	else if(!isDate(f[field].value)){
		alert(strMsgError);
		f[field].focus();
		return false;
	}
	
	return true;
	
}

function delete_rec(deleteurl) {
	if (confirm('Are you sure you want to delete this record? ')) {
		document.location=deleteurl;
	}
}

/*-- formatCurrency (12548697, ',','.'); ---*/
function formatCurrency(num, thousandssign, decimalsign)
{
	num = num.toString().replace(',','');
	if(isNaN(num)) {
		return "0.00";
	}
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) {
		cents = "0" + cents;
	}
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
		num = num.substring(0,num.length-(4*i+3))+thousandssign+
		num.substring(num.length-(4*i+3));
	}
	return (((sign)?'':'-') + num + decimalsign + cents);
}

function showHide(element_name, label, strDisplay, strHide) {
	
	var element = getLayer(element_name);
	var strQueryString = location.search;
	var strCookieName = '';
	var bolShow = true; 
	
	if(strQueryString.indexOf("incomplete") > -1){
		strCookieName = 'ilist';
	}
	else if(strQueryString.indexOf("pending") > -1){
		strCookieName = 'plist';
	}
	else if(strQueryString.indexOf("finished") > -1){
		strCookieName = 'flist';
	}
	
	if(element.style.display != 'none' && element.style.display != 'block'){
		if(typeof(codDisplay) != "undefined"){
			if(codDisplay == '1'){
				bolShow = false; 
			}
		}
	}
	else if (element.style.display != 'none') {
		bolShow = false; 
	}
	
	if (!bolShow){
		setDisplay (element_name,'none');
		if (typeof label != "undefined") {
			setInnerHTML(label, strDisplay);
			if(strCookieName != ''){
				setCookie(strCookieName, '0', 365);
			}
		}
	}
	else {
		element.style.display = 'block';
		if (typeof label != "undefined") {
			setInnerHTML(label, strHide);
			if(strCookieName != ''){
				setCookie(strCookieName, '1', 365);
			}
		}
	}
	
}

function HasClassName(objElement, strClass)
{

   // if there is a class
   if ( objElement.className ) {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');
      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ ){
         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper ){
            // we found it
            return true;
         }
      }
   }
   // if we got here then the class name is not there
   return false;
}


function onLoad() {
	//stub
}

function setCookie(c_name, value, expiredays){

	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+"="+escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

}