﻿// Commom Functions for site 
function Get_Domain()
{
    var Domain = ""
    var Scheme = window.location.href.split(/\/+/g)[0];
    var Host = window.location.href.split(/\/+/g)[1];
    var Section = window.location.href.split(/\/+/g)[2];
    if (Host == "localhost")
    {
        Domain = Scheme + "//" + Host + "/" + Section;
    }
    else
    {
        Domain = Scheme + "//" + Host;
    }
    return Domain
}

function Fit_to_Page()
{
    //Height
    var obj_height = document.getElementById("ctl00_div_Content_Placeholder")
    if ((obj_height.scrollHeight) < 350)
    {
        obj_height.style.height = "350px"
    }
            
    //width
    var obj_width = document.getElementById("ctl00_div_Content_Placeholder")
    return true    
}

function Fit_to_Area()
{
    //Height
    var obj_height = document.getElementById("ctl00_div_Content_Placeholder")
    if ((obj_height.scrollHeight) < 338)
    {
        obj_height.style.height = "338px"
    }
    //width
    var obj_width = document.getElementById("ctl00_div_Content_Placeholder")
    return true    
}

function Fit_to_Menu()
{
    //Height
    var obj_content_div = document.getElementById("ctl00_div_Content_Placeholder")
    var obj_mnu = document.getElementById("menu0")
    var obj_left_div = document.getElementById("ctl00_div_left")
  
  try
  {
    if ((obj_content_div.scrollHeight) < obj_mnu.scrollHeight)
    {
        obj_content_div.style.height = obj_mnu.scrollHeight + 20 + "px";
        obj_left_div.style.height = obj_mnu.scrollHeight + 20 + "px";
        //obj_content_div.style.width = (obj_content_div.scrollWidth - (obj_mnu.scrollWidth + 5)) + "px";
    }
    //width of left div
    if ((obj_left_div.scrollWidth) < obj_mnu.scrollWidth)
    {
        obj_left_div.style.width = obj_mnu.scrollWidth + 10 + "px";
        obj_content_div.style.width = (obj_content_div.scrollWidth - (obj_mnu.scrollWidth + 10)) + "px";
    }
    }
    catch(err)
    {
       if ((obj_content_div.scrollHeight) < 350)
       {
        obj_content_div.style.height = "350px";
        obj_left_div.style.height = "350px"; 
       }
       
    }
    
    return true    
}

function Fit_to_Width()
{
    //Height
    var obj_height = document.getElementById("ctl00_div_Content_Placeholder")
    if ((obj_height.scrollHeight) < 350)
    {
        obj_height.style.height = "350px"
    }
            
    //width
    var obj_cms = document.getElementById("ctl00_CPH1_lblContent")
    var obj_width = document.getElementById("ctl00_div_Content")
    try
    {
        if ((obj_cms.scrollWidth) >  obj_width.scrollWidth)
        {
            obj_width.style.width = obj_cms.scrollWidth + "px"
            document.getElementById("ctl00_div_right_menu").style.visibility = "hidden";
        }
    }        
    catch(err)
    {
    
    }
    return true
}

function Show_Cal_Window(txtForm,txtDate)
{
var strURL = Get_Domain() + "/Calendar.aspx"
intWidth = 250
intHeight = 190

if (navigator.appName.toUpperCase().match(/MICROSOFT INTERNET EXPLORER/) != null)
{
strURL = strURL + "?type=modal&dteSelected=" + document.getElementById(txtDate).value
var answer = window.showModalDialog(strURL ,null,'center=1;status=no;help=no;dialogWidth=' + intWidth + 'px;dialogHeight=' + intHeight + 'px')
if (answer != undefined)
{
    document.getElementById(txtDate).value = answer
}
}
else
{
var winModalWindow

intWidth = 210
intHeight = 170

//add the flag for Netscape
strURL = strURL + "?type=win&field=" + txtDate + "&form=" + txtForm + "&dteSelected=" + document.getElementById(txtDate).value
//Get the Center screen coordinates
intLeft = (screen.availWidth - intWidth) / 2
intTop = (screen.availHeight - intHeight) / 2
window.top.captureEvents(Event.CLICK|Event.FOCUS)
//window.top.onclick=IgnoreEvents
//window.top.onfocus=HandleFocus
winModalWindow = window.open(strURL,"window","dependent=yes,width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft + ",resizable=0,menubar=0,status=0")
winModalWindow.focus()
}
}

function Show_Time_Window(txtForm,txtTime)
{
var strURL = Get_Domain() + "/Time_Picker.aspx"
intWidth = 250
intHeight = 100

strURL = strURL + "?timSelected=" + document.getElementById(txtTime).value
var answer = window.showModalDialog(strURL ,null,'center=1;status=no;help=no;dialogWidth=' + intWidth + 'px;dialogHeight=' + intHeight + 'px')
if (answer != undefined)
{
    document.getElementById(txtTime).value = answer
}    
}

function ShowWindow(strURL,intWidth,intHeight)
{
window.showModalDialog(strURL ,null,'center=1;status=no;help=no;dialogWidth=' + intWidth + 'px;dialogHeight=' + intHeight + 'px')
}

function Print_Preview(strTitle,strPrint,strOrders)
{

intWidth = 625
intHeight = 500
intLeft = (screen.availWidth - intWidth) / 2
intTop = (screen.availHeight - intHeight) / 2

if (strPrint == "") { strPrint = "divPrint";}

var winModalWindow
winModalWindow = window.open ("","window","dependent=yes,width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft + "menubar=no,toolbar=no,scrollbars=yes")
winModalWindow.document.writeln('<HTML><HEAD><title>' + strTitle + ' (Print Preview)</title>')
winModalWindow.document.writeln('<LINK href="' + Get_Domain() + '/Print_Preview.css" type="text/css" rel="stylesheet">')
//winModalWindow.document.writeln('<script type="text/javascript" src="' + Get_Domain() + '/Print_Script.js" ></script>')
winModalWindow.document.writeln('<style type="text/css" rel="stylesheet" media="print" >.Print {visibility:hidden} .Show {visibility:visible;text-align:center;font-size:85%}</style>')
winModalWindow.document.writeln('<base target="_self"></HEAD>')
//Adding Body Tag
winModalWindow.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');
winModalWindow.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');
//Adding form Tag
winModalWindow.document.writeln('<form method="post">');
//Creating two buttons Print and Close within a HTML table
winModalWindow.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');
winModalWindow.document.writeln('<INPUT ID="PRINT" type="button" class="Print" value="Print" ');
winModalWindow.document.writeln('onclick="javascript:location.reload(true);window.print();">');
//winModalWindow.document.writeln('onclick="Do_Print();">');
winModalWindow.document.writeln('<INPUT ID="CLOSE" class="Print" type="button" value="Close" onclick="window.close();">');
winModalWindow.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');

if (strOrders == "")
{
    //Writing the fixed print area of the calling page
    winModalWindow.document.writeln('<TABLE width=100% align=center style=font-size:100% >');
    try
    {
        winModalWindow.document.writeln('<TR><TD align=center>' + document.getElementById("ctl00_CPH1_lblHeader").innerHTML +'</TD></TR>');
        winModalWindow.document.writeln('<TR><TD align=center>' + document.getElementById("ctl00_CPH1_pnlPrint").innerHTML +'</TD></TR>');
        document.getElementById("ctl00_CPH1_pnlLoc").style.visibility = "hidden";
    }
    catch(e){}    
    winModalWindow.document.writeln('<TR><TD style="text-align:center">' + document.getElementById(strPrint).innerHTML +'</TD></TR>');
    try
    {
        var ctrlPage = document.getElementById("ctl00_CPH1_lblPage_Print")
        document.getElementById("ctl00_CPH1_lblPage_Print").setAttribute("class", "Show");
        winModalWindow.document.writeln('<TR><TD align=center>' + ctrlPage.innerHTML +'</TD></TR>');
    }
    catch(e){}
    winModalWindow.document.writeln('</table>')
}
else
{
    //Get the Invoice Count
    var intInv = document.getElementById(strOrders).value
    //Writing print area of the calling page
    for (var inti=0; inti < intInv; inti ++)
    {
        if (inti <=9)
        {
            strIndex = "0" + inti
        }
        else
        {
            strIndex = inti
        }
        var hide = 0
        if (document.getElementById("ctl00_CPH1_dlist_Main_ctl" + strIndex + "_pnlPayment_Error"))
        {
            var hide = 0
        }
        if(hide != -1)
        {
            winModalWindow.document.writeln('<TABLE width=100% align=center ><TR><TD style="border-color:#b3b3b3;border-width:1px;border-style:none;text-align:center">' + document.getElementById("ctl00_CPH1_dlist_Main_ctl" + strIndex + "_pnlDetails").innerHTML +'</TD></TR></table>');
            //Add Page Break
            if ((inti + 1) < intInv)
            {
                if ((/MSIE (\d+\.\d+);/.test(navigator.userAgent)) == false)
                {
                   winModalWindow.document.writeln("<div class='Break'></div>")
                }  
            }
         }   
    }
}
winModalWindow.document.writeln('</form></body></HTML>');
winModalWindow.focus() 
}

function printdiv(printpage)
{
//var headstr = "<html><head><title></title></head><body>";
//var footstr = "</body>";
//var newstr = document.getElementById(printpage).innerHTML;
//var oldstr = document.body.innerHTML;
//document.body.innerHTML = headstr+newstr+footstr;
window.print(); 
//document.body.innerHTML = oldstr;
return false;
}

function swapImages(strImage,strBtn)
{
	strBtn = "ctl00_CPH1_" + strBtn
	document.getElementById(strBtn).src = Get_Domain() + "/admin/images/" + strImage
}

function go_home()
{
   var strURL = Get_Domain() + "/default.aspx"
   document.location.replace(strURL)
}

function display_tabs(intAction)
{
    try
    {
        if (intAction == 0)
        {
           document.getElementById("menu0").style.visibility = "hidden";
        }
        else
        {
           document.getElementById("menu0").style.visibility = "visible";
        }
    }
    catch(err)
    {
    
    }
    return true
}


