function loadContent(urlVal,content_div,mask,width,heightValue)
{
    var widthValue=width?width:600;
    var height=heightValue?heightValue:'auto';

    $("#"+content_div).html('');

    $.ajax({
        url: urlVal,
        success: function(data) {
            $("#"+content_div).html('');
            $("#"+content_div).html(data);
        }
        ,
        error: function(e){
        }
    });

    //$('#mainbody_sub').fadeIn('slow');
    $("#"+content_div).dialog({
        bgiframe: true,
        closeOnEscape: false,
        width:widthValue,
        height:height,
        position: 'top'
    });

    ;

    //    $('#mainbody_sub').fadeIn('slow');
    var maskHeight = parseInt($(document).height(), 10)+parseInt(document.getElementById(content_div).offsetHeight, 10) ;
    var maskWidth = $(window).width();

    //Set height and width to mask to fill up the whole screen

    $('#'+mask).css({
        'width':maskWidth,
        'height':maskHeight
    });

    if(jQuery.browser.msie){
        if((jQuery.browser.version)<=6.0)
        {
            $('#'+mask).css({
                position:"absolute"
            });
            $('#'+mask).css({
                'width':maskWidth,
                'height':parseInt(maskHeight, 10)+ parseInt($("#"+content_div).width(), 10)
            });
        }
        else{
            $('#'+mask).css({
                position:"fixed"
            });
        }
    }
    else
    {
        $('#'+mask).css({
            position:"fixed"
        });
    }

    $('#'+mask).show();
}
function loadContentNoScaling(urlVal,content_div,mask)
{

    $("#"+content_div).html('');

    $.ajax({
        url: urlVal,
        success: function(data) {
            $("#"+content_div).html('');
            $("#"+content_div).html(data);
        }
        ,
        error: function(e){
        }
    });

    //$('#mainbody_sub').fadeIn('slow');
    $("#"+content_div).dialog({
        bgiframe: true,
        closeOnEscape: false,
        width:892,
        height:600,
        position: 'top'
    });

    ;

    //    $('#mainbody_sub').fadeIn('slow');
    var maskHeight = parseInt($(document).height(), 10)+parseInt(document.getElementById(content_div).offsetHeight, 10) ;
    var maskWidth = $(window).width();

    //Set height and width to mask to fill up the whole screen

    $('#'+mask).css({
        'width':maskWidth,
        'height':maskHeight
    });

    if(jQuery.browser.msie){
        if((jQuery.browser.version)<=6.0)
        {
            $('#'+mask).css({
                position:"absolute"
            });
            $('#'+mask).css({
                'width':maskWidth,
                'height':parseInt(maskHeight, 10)+ parseInt($("#"+content_div).width(), 10)
            });
        }
        else{
            $('#'+mask).css({
                position:"fixed"
            });
        }
    }
    else
    {
        $('#'+mask).css({
            position:"fixed"
        });
    }

    $('#'+mask).show();
}
function loadSlideShowPopup(urlVal,content_div,mask)
{

    $("#"+content_div).html('');

    $.ajax({
        url: urlVal,
        success: function(data) {
            $("#"+content_div).html('');
            $("#"+content_div).html(data);
        }
        ,
        error: function(e){
        }
    });

    //$('#mainbody_sub').fadeIn('slow');
    $("#"+content_div).dialog({
        bgiframe: true,
        closeOnEscape: false,
        width:900,
        height:750,
        position: 'top'
    });

    ;

    //    $('#mainbody_sub').fadeIn('slow');
    var maskHeight = parseInt($(document).height(), 10)+parseInt(document.getElementById(content_div).offsetHeight, 10) ;
    var maskWidth = $(window).width();

    //Set height and width to mask to fill up the whole screen

    $('#'+mask).css({
        'width':maskWidth,
        'height':maskHeight
    });

    if(jQuery.browser.msie){
        if((jQuery.browser.version)<=6.0)
        {
            $('#'+mask).css({
                position:"absolute"
            });
            $('#'+mask).css({
                'width':maskWidth,
                'height':parseInt(maskHeight, 10)+ parseInt($("#"+content_div).width(), 10)
            });
        }
        else{
            $('#'+mask).css({
                position:"fixed"
            });
        }
    }
    else
    {
        $('#'+mask).css({
            position:"fixed"
        });
    }

    $('#'+mask).show();
}
function loadReportPopup(urlVal,content_div,mask)
{

    $("#"+content_div).html('');

    $.ajax({
        url: urlVal,
        success: function(data) {
            $("#"+content_div).html('');
            $("#"+content_div).html(data);
        }
        ,
        error: function(e){
        }
    });

    //$('#mainbody_sub').fadeIn('slow');
    $("#"+content_div).dialog({
        bgiframe: true,
        closeOnEscape: false,
        width:950,
        height:900,
        position: 'top'
    });

    ;

    //    $('#mainbody_sub').fadeIn('slow');
    var maskHeight = parseInt($(document).height(), 10)+parseInt(document.getElementById(content_div).offsetHeight, 10) ;
    var maskWidth = $(window).width();

    //Set height and width to mask to fill up the whole screen

    $('#'+mask).css({
        'width':maskWidth,
        'height':maskHeight
    });

    if(jQuery.browser.msie){
        if((jQuery.browser.version)<=6.0)
        {
            $('#'+mask).css({
                position:"absolute"
            });
            $('#'+mask).css({
                'width':maskWidth,
                'height':parseInt(maskHeight, 10)+ parseInt($("#"+content_div).width(), 10)
            });
        }
        else{
            $('#'+mask).css({
                position:"fixed"
            });
        }
    }
    else
    {
        $('#'+mask).css({
            position:"fixed"
        });
    }

    $('#'+mask).show();
}
function closeContent(content_div,mask)
{
    $('#'+content_div).hide();
    $('#'+content_div).dialog('destroy');
    $('#'+mask).hide();

}
function closeContentWithReload(content_div,mask)
{
    $('#'+content_div).hide();
    $('#'+content_div).dialog('destroy');
    $('#'+mask).hide();
    window.location.reload();

}

function ajaxPost(urlVal,formId){
    $.ajax({
        url: urlVal,
        data: $('#'+formId).serialize(),
        type: 'post',
        cache: false,
        dataType: 'html',
        success: function (data) {
            ;
            window.location.reload();
        }
    });
}
function ajaxPostWithReloadUi(urlVal,formId,containerId){
    $.ajax({
        url: urlVal,
        data: $('#'+formId).serialize(),
        type: 'post',
        cache: false,
        dataType: 'html',
        success: function (data) {
            ;
            $("#"+containerId).html('');
            $("#"+containerId).html(data);
        }
    });
}
function ajaxPostWithRedirectUi(urlVal,formId,redirectUrl){
    $.ajax({
        url: urlVal,
        data: $('#'+formId).serialize(),
        type: 'post',
        cache: false,
        dataType: 'html',
        success: function (data) {
            ;
            window.location=redirectUrl;
        }
    });
}
function ajaxNonPost(urlVal,needConfirmation,confirmationText){
    if(needConfirmation==true){
        if(confirm(confirmationText)==false){
            return false;
        }
    }
    
    $.ajax({
        url: urlVal,
        cache: false,
        success: function (data) {
            ;
            window.location.reload();
        }
    });
    return true;
}
function ajaxNonPostReloadUi(urlVal,containerId){

    $.ajax({
        url: urlVal,
        cache: false,
        success: function (data) {
            ;
            $("#"+containerId).html('');
            $("#"+containerId).html(data);
        }
    });
    return true;
}
function ajaxNonPostReloadSameUi(urlVal,UrlSameui,containerId,mask){

    $.ajax({
        url: urlVal,
        cache: false,
        success: function (data) {
        ;

        }
    });
    closeContent(containerId,mask);
    loadContent(UrlSameui,containerId,mask);
    return true;
}
function filterCharactors(idz){
    existingVal=$('#'+idz).val();
    splitedchars=existingVal.split("");
    outputStr="";
    var noOfsplitedChars=0;
    var charaterLimit=false;
    var characters=2;
    var noOfChars=0;

    for(i=0;i<splitedchars.length;i++){
        accept=false;
        for(a=0;a<=9;a++){
            if(splitedchars[i]==a){
                accept=true;
            }
        }
        if(splitedchars[i]=='$' || splitedchars[i]==',' || splitedchars[i].charCodeAt(0)=='8364' || splitedchars[i]=='.' || splitedchars[i].charCodeAt(0)=='162' || splitedchars[i].charCodeAt(0)=='163' || splitedchars[i].charCodeAt(0)=='165' || splitedchars[i].charCodeAt(0)=='402'){
            accept=true;
            if(splitedchars[i]=='.'){
                if(noOfsplitedChars==0){
                    noOfsplitedChars++;
                    charaterLimit=true;
                }
                else{
                    accept=false;
                }
                if(charaterLimit){
                    noOfChars++;

                    if(noOfChars>characters){
                        accept=false;
                    }

                   
                }
            }
           

        }

        if(accept){
            outputStr=outputStr+splitedchars[i];
        }
    }

    $('#'+idz).val(outputStr);


}

function setFileUploader(divId,filEle,maxFileSizeCount){
    	
    var multi_selector = new MultiSelector( document.getElementById( divId ), maxFileSizeCount );
    multi_selector.addElement( document.getElementById( filEle ) );

}

function cancelDialogBox(content_div,mask,loadDefaultImage,url,divDefaultImage,divOtherImages){

    closeIframeContent(content_div,mask,loadDefaultImage,url,divDefaultImage,divOtherImages);
}

function loadInAIfram(urlVal,content_div,mask,loadDefaultImage,url,divDefaultImage,divOtherImages,title){
    var widthValue=800;
    var widthValueIframe=780;
    var height=500;
    if (!title)
        title="Upload Images";
    window.scroll(0,0);
    $("#"+content_div).html('');
    
    $("#"+content_div).append("<table class=\"content\" width=\""+widthValueIframe+"\" id='tmpTable' cellpadding=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr class=\"dialog_header\" cellpadding><td class=\"dialog_title\">"+title+"</td><td align=\"right\" class=\"close_button\" onclick=\"closeIframeContent('"+content_div+"','"+mask+"','"+loadDefaultImage+"','"+url+"','"+divDefaultImage+"','"+divOtherImages+"');\" >X</td><td>&nbsp;</td></tr><tr ><td id='iframeHolder'></td></tr></table>");

    $("#iframeHolder").append(
        '<IFRAME id="proxyWindow" src="'+urlVal+'" align="center" width="'+widthValueIframe+'" height="'+height+'px" frameborder="0" scrolling="no">');

    $("#"+content_div).dialog({
        bgiframe: true,
        closeOnEscape: false,
        width:widthValue,

        position: 'top'
    });

    ;

    //    $('#mainbody_sub').fadeIn('slow');
    var maskHeight = parseInt($(document).height(), 10)+parseInt(document.getElementById(content_div).offsetHeight, 10) ;
    var maskWidth = $(window).width();

    //Set height and width to mask to fill up the whole screen

    $('#'+mask).css({
        'width':maskWidth,
        'height':maskHeight
    });

    if(jQuery.browser.msie){
        if((jQuery.browser.version)<=6.0)
        {
            $('#'+mask).css({
                position:"absolute"
            });
            $('#'+mask).css({
                'width':maskWidth,
                'height':parseInt(maskHeight, 10)+ parseInt($("#"+content_div).width(), 10)
            });
        }
        else{
            $('#'+mask).css({
                position:"fixed"
            });
        }
    }
    else
    {
        $('#'+mask).css({
            position:"fixed"
        });
    }

    $('#'+mask).show();
}
function closeIframeContent(content_div,mask,loadDefaultImage,url,divDefaultImage,divOtherImages)
{
    $('#tmpTable').remove();
    $('#'+content_div).hide();
    $('#'+content_div).dialog('destroy');
    $('#'+mask).hide();

    // All calls set to false, does not load other images. Needs to be fixed.
    if(loadDefaultImage=='true')
    {
        loadImage(url,divDefaultImage,divOtherImages);
    }else{
        window.location.reload();
    }

}

function loadImage(url,divDefaultImage,divOtherImages){

    $.ajax({
        url: url,
        datatype: 'json',
        success:  function (data) {
            // $('#'+divDefaultImage).html('');
            $('#'+divOtherImages).html('');
     
            var dataVal = eval( "(" + data + ")" );
            $('#'+divDefaultImage).html(dataVal.image);
            $('#div_other_images').hide();
//            if(dataVal.showRotateLink==true){
//                $('#rotateLink').css("display","");
//            }
//            else{
//                $('#rotateLink').css("display","none");
//            }
            $('#'+divOtherImages).html(dataVal.otherImages);
        }
    });
    
}
function downloadFile(urlVal)
{
    $.download(urlVal);
}

function addNewFileUploadController(tableId,tableRowName,fileUploadName){
    $("#"+tableRowName).clone().html('').html('<th ><input type=\"file\" name=\"'+fileUploadName+'\" class=\"box\"/></th>').appendTo("#"+tableId).val('').removeAttr("id");
}

function setSortValue(elementName,sortAsc,sortDesc){
    if($('#'+elementName).val()==sortAsc)
        $('#'+elementName).val(sortDesc);
    else
        $('#'+elementName).val(sortAsc);
}

function validateFileUploadForm(){

    var valid=false;
    $(document).ready(function() {
        $("#files_upload_panel").find("input[type=file]").each(function(i) {
            if ($(this).val()!=""){
                $('#loadingArea').show();
                valid=true;
            }


        });
    });

    return valid;
}

function formSubmission(next){
    if(changed){
            if (confirm("Do you want to save changes, before leaving this page?")) {
                    document.getElementById('next_url').value=next;
                    document.formEditObjectInformation.submit();
            }else{
                    location.href=next;
            }
    }else{
            location.href=next;
    }

}

var trim = function (o) {
            return o.replace(/^\s+|\s+$/g, "");
};

function printThis(){

        htmlStr='<html><body>';
        if(document.getElementById('includeImages').checked){
                htmlStr+=document.getElementById('table_for_printing').innerHTML;
        }else{
                htmlStr+=document.getElementById('table_for_printing_no_image').innerHTML;
        }
        htmlStr+='</body></html>';

        document.getElementById('tableStr').value=htmlStr;

        document.myFormz.submit();

}



