﻿// JScript File
function getItemById(id)
{
    var obj = document.getElementById(id);
    return obj;
}
// Show and Hidden block
 function ToggleBlock(blockId,classHidden,classShow,status)
    {
       var obj = getItemById(blockId);
       if(status)
       {
            obj.className  =classShow;
       }else{
             obj.className  =classHidden;
       }
    }
// Event onchange User style  
 function onChangeUserStyle(blockId,ComboValue)
 {
    var valueSelect = ComboValue.options[ComboValue.selectedIndex].value ;
    var classHidden ="hidden";
    var classShow = "show";
    var status = false;
    switch(valueSelect)
    {
        case "0":
            status =false;
            break;
       case "1":
             status =true;
            break;
       case "2":
             status =true;
            break;
    }
    ToggleBlock(blockId,classHidden,classShow,status) ;
 }

function setErrorFocus(id)
{
       getItemById(id).focus();
}
function checkTerm(objThis,controlIdVisible)
{
     var status = objThis.checked ;
     DefaultCheckTerm(status,controlIdVisible);
}
function DefaultCheckTerm(status,controlIdVisible)
{
    var objVisible = getItemById(controlIdVisible);
    Page_ValidationActive = status;
   /* objVisible.disabled = !status ; */
}
function changeOptionPrice(id,price,type)
{
    var typeName ="type" + id;
    var totalName ="Catpiont_T" + id ;
    var totalHidden = "Itemtotal" + id ;
    var objType = getItemById(typeName);
    var objCatpion= getItemById(totalName) ;
    var objTotal = getItemById(totalHidden) ;
    
    objType.value = type ;
    objTotal.value = price ;
    objCatpion.innerHTML = '&euro; ' +  price.toFixed(2) ;
    caculatorTotalItem();
}
function caculatorTotalItem()
{
    var items = document.forms[0].elements;
    var intLength = items.length;
    var total = 0;
    var itemCaption = getItemById("subTotal");
    for(var i= 0; i<intLength; i++)
    {
        if(items[i].type =="hidden")
        {
            var itemName = items[i].name ;
            if(itemName.indexOf("Itemtotal") >-1)
            {
                total +=  parseFloat(items[i].value) ;
            }
        }
    } 
    
    itemCaption.innerHTML = total.toFixed(2) ;  
}
function confirmMsg(msg)
{
    return confirm(msg) ;
}


// Popup 
function initbox(id){
if (!dom&&!ie&&!ns4)
return
crossobj=(dom)?document.getElementById(id).style : ie? document.all.dropin : document.dropin
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
crossobj.top=scroll_top-450+calunits
crossobj.visibility=(dom||ie)? "visible" : "show"
dropstart=setInterval("dropin()",10)
}

function dropin(){
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
if (parseInt(crossobj.top)<30+scroll_top)
crossobj.top=parseInt(crossobj.top)+40+calunits
else{
clearInterval(dropstart)
bouncestart=setInterval("bouncein()",5)
}
}

function bouncein(){
crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
if (bouncelimit<0)
bouncelimit+=8
bouncelimit=bouncelimit*-1
if (bouncelimit==0){
clearInterval(bouncestart)
}
}

function dismissbox(){
    try
    {
        if (window.bouncestart) clearInterval(bouncestart)
        if(crossobj !=undefined)
            crossobj.visibility="hidden" ;
    }
    catch(ex){}

}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

/* code by manhnh  29/01/2008 */

function changeComboTypeReport(obj,controlChange)
{
    
    var value = obj.options[obj.selectedIndex].value;
    var text = obj.options[obj.selectedIndex].text;
    var objChange = getItemById(controlChange);
    var intLength = obj.options.length;
    var valueCompare = objChange.value ;
    if(value !="-1")
    {
        if(trim(valueCompare)==""){
            objChange.value = text
        }
        else
        {
            
            for(var i=0; i<intLength; i++)
            {
                if(trim(valueCompare) == trim(obj.options[i].text))
                {
                     objChange.value = text
                }
            }
        }
    }
    else{
         objChange.value = "";
    }
    
}
/* trim string */
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
}
/* addmore 198/02/2008 */
function onClickConfirmPassword(obhCheckBox,IdControlEffect)
{
    var objEffect = getItemById(IdControlEffect);
    if(obhCheckBox.checked)
    {
        objEffect.className= "Show";
    }
    else{
         objEffect.className= "hidden";
    }
}
function openwin(url,w_title,width,height)
{
	var maxw = window.screen.availWidth;
	var maxh = window.screen.availHeight;
	var win = window.open(url,w_title,'screenX=0,screenY=0,left='+((maxw-width)/2)+',top=0,width=' + width + ',height=' + height+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no');
	win.focus();
}
function openwinscroll(url, w_title, width, height) {
    var maxw = window.screen.availWidth;
    var maxh = window.screen.availHeight;
    var win = window.open(url, w_title, 'screenX=0,screenY=0,left=' + ((maxw - width) / 2) + ',top=0,width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
    win.focus();
}
function openPdf(url,w_title)
{

	var win = window.open(url,w_title,'screenX=0,screenY=0,top=0,toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	win.focus();
}
