// fuction modalWin added by MCACross

function modalWin(url, width, height)
{
  if (!windowObject.win || (windowObject.win && windowObject.win.closed))
  {
    windowObject.width = width;
    windowObject.height = height;
    windowObject.name = (new Date()).getSeconds().toString();
    windowObject.left = (screen.width - windowObject.width) / 2;
    windowObject.top = (screen.height - windowObject.height) / 2;
    var windowAttributes = 'left=' + windowObject.left + ',top=' + windowObject.top + ',resizable=yes,width='+
                            windowObject.width +  ',height=' + windowObject.height +',scrollbars=yes';
    windowObject.url = url;
    windowObject.win=window.open(windowObject.url, windowObject.name, windowAttributes);
    return windowObject.win;
  }
  else
  {
    return windowObject.win;
  }
}

function CINLookup (property, styleId, textProperty,textStyleId)

{

 
if(textProperty.value!="")

{
error_arr.length=0;
if(property.value!=""){
property.value="";
}

flagVar='true';



checkMinLengthCIN(textProperty,2);



if(error_arr.length >=1){

   showErrors();

   error_arr.length=0;

   textProperty.value="";

   textProperty.focus();



return false;

 }



}


var lovName = "";
var lovType = "single";
var lovWhereFldsVal = null;
  stripMethod();
  var theForm = document.forms[0];
  var windowObject   = new Object();
  var tempCount      = arguments.length;
  var argumentsArray = new Array(2);
  /*
     Following loop extracts the user specified 'where' clause which are separated by ':'
  */
  if( lovWhereFldsVal != null)
  {
    var whereFldIndex  = lovWhereFldsVal.indexOf(":");
    var startIndex     = 0          ;
    var whereFld                    ;
    var whereFldValArr = new Array();
    var fldCount       = 0          ;
    while(whereFldIndex != -1)
    {
      whereFld = lovWhereFldsVal.substring(startIndex,whereFldIndex);
      whereFldValArr[fldCount] = theForm.elements[whereFld].value;
      fldCount++;
      lovWhereFldsVal = lovWhereFldsVal.substring(whereFldIndex+1);
      whereFldIndex  = lovWhereFldsVal.indexOf(":");
      whereFld = lovWhereFldsVal.substring(startIndex,whereFldIndex);
    }
    whereFldValArr[fldCount] = theForm.elements[lovWhereFldsVal].value;
  }
//  for(var i=0;i<tempCount;i++)
//  {
//    argumentsArray[i]=arguments[i];
//  }

argumentsArray[3]="1:"+textStyleId;
argumentsArray[4]="2:"+styleId;
tempCount=5;
  width=825;
  height=500;
  windowObject.fieldnameArray = new Array();
  /*
    Opens a window with width of 825 and heigth of 500
  */
  if (!windowObject.win || (windowObject.win && windowObject.win.closed))
  {
    for(var i=0;i<(argumentsArray.length - 3);i++)
    {
      windowObject.fieldnameArray[i] = argumentsArray[i+3];
    }
    windowObject.returnedValue = '';
    windowObject.width = width;
    windowObject.height = height;

    var index        = argumentsArray[3].indexOf(":");
    var fieldObjName = argumentsArray[3].substring(index+1,argumentsArray[3].length)
    /*if(theForm.elements[fieldObjName].disabled)
    {
      hideBlink();
      return;
    }*/
 //   if(lovType == "single")
  //  {
  //    var fieldValue   = theForm.elements[fieldObjName].value;
 //    if(fieldValue=='' || fieldValue==' ')
 //     {
 //      fieldValue="undefined";
 //     }
  //  }
  //  else if(lovType == "multi")
  //  {
  //   var fieldValue="undefined";
  //  }

    windowObject.name =(new Date()).getSeconds().toString();

    windowObject.left = (screen.width - windowObject.width) / 2;
    windowObject.top = (screen.height - windowObject.height) / 2;

    var windowAttributes = 'left=' + windowObject.left + ',top=' + windowObject.top + ',resizable=no,width='+
                            windowObject.width +  ',height=' + windowObject.height; // defines the window attributes
    windowObject.url = '';
    windowObject.win=modalWin(windowObject.url,width,height);
//    window.open(windowObject.url, windowObject.name, windowAttributes);
    windowObject.win.focus();

    /*
      Following code makes the Dynamic HTML for the LOV screen. The form of this
      dynamic HTML is submitted with the values specified by the user and LOV screen
      is displayed
    */
    var tempHtml = "";
    tempHtml += "<html>";
    tempHtml += "<body>";
    tempHtml += "<form method=post action='/"+contextRoot+"/dca/displayCIN.do?method=getCIN'>";
    tempHtml += "<input type=hidden name='stLOVName' value='" + lovName + "' >";
    tempHtml += "<input type=hidden name='stLOVType' value='" + lovType + "' >";
//    tempHtml += "<input type=hidden name='stFieldVal0' value='" + fieldValue + "' >";
    if( lovWhereFldsVal != null)
    {
      for(j=0; j<whereFldValArr.length ; j++)
      {
        tempHtml += "<input type=hidden name='arStFieldVal[j]' value='" + whereFldValArr[j] + "' >";
      }
    }
    for(var j=i;j<5-i;j++)
    {
      tempHtml += "<input type=hidden name='stFieldName" +j+"' value='' >";
    }
    if(lovType == "single")
    {
      for(var i=0;i<(tempCount-3);i++)
      {
        tempHtml += "<input type=hidden name='stFieldName" +i+"' value='" + argumentsArray[i+3] + "' >";
      }
    }
    if(lovType == "multi")
    {
      for(var i=0;i<(tempCount-3);i++)
      {
        tempHtml += "<input type=hidden name='stFieldNameArray[i]' value='" + argumentsArray[i+3] + "' >";
      }
    }
    tempHtml +="Please Wait, While application is getting the desired values...";
    tempHtml += "</form>";
    tempHtml +="</body>";
    tempHtml +="</html>";
    windowObject.win.document.write(tempHtml);
    windowObject.win.document.forms[0].submit();
    windowObject.win.focus();
  }
}



//JSDOC   Function Name: checkMinLength()
//JSDOC   Description  : This function checks the size of value entered should be
//JSDOC                               greater than minimum length specified
//JSDOC                  It takes two parameters, objCurrent and objMinLength
//JSDOC                  objCurrent : Object passed whose value needs to be validated
//JSDOC                  objMinLength : minimum length of the value entered.
//JSDOC  This function does not accept special characters.
//JSDOC  The function returns true/false.

function checkMinLengthCIN(objCurrent,objMinLength)
{
  if(flagVar=='true')
  {
    var objValue = objCurrent.value;
    objValue     = trimCIN(objValue);
    if(objValue && objValue.length < objMinLength)
    {
      var objectName = getObjectLabel(objCurrent.id, objCurrent);
      var str = COM00133+' '+objMinLength+ ' '+ COM00134 + objectName;
      setError(str);
		if(error_arr.length==1 && firstErrorField=="")
		{
			firstErrorField = objCurrent.getAttribute('name');
		}
      return false;
    }
  }
  return true;
}

//JOADOC   Function Name:  trim()
//JOADOC   Description  :  This function removes the leading & trailing spaces entered by the user
//JOADOC                   in any input element.
//JOADOC                   It takes only one parameter, string of value.
//JOADOC                   s : The string containg data.
//JOADOC   It returns the value of the object.
function trimCIN( s )
{
  if(!s)
  {
    return;
  }
  if(s.length == 0)
  {
    return s;
  }
  var i = 0, j = s.length - 1;

  for(; i <= j; i++)
  {
    var c = s.charAt(i);
    if(c != ' ' & c != '\n' & c != '\t')
    {
      break;
    }
  }

  // If i passed j, we have an empty string
  if(i > j)
  {
    return "";
  }

  for(; j > i; j--)
  {
    var c = s.charAt(j);
    if(c != '\n' & c != '\t')
    {
      break;
    }
  }

  if (i > 0 || j < s.length - 1)
  {
    return s.substring(i, j+1 );
  }
  else
  {
    return s;
  }
} /* trim end */

