﻿
function PreventSubmit()
{
    if(typeof(Page_IsValid) != "undefined")
    { 
        if(!Page_IsValid) return true;
    }
    
    if(document.getElementById("hiddenSubmit") == null) return true;
    
    var sValue = document.getElementById("hiddenSubmit").value;
    
    if(sValue == "")
    {
        document.getElementById("hiddenSubmit").value = "1";
        return true;        
    }
    else if(sValue == "1")
    {
        var resp = window.confirm ('Do you want to continue this transaction?');
        
        return resp;  
        
        //alert("Please wait while we process your request.");
        //return false;
    }    
}

function ShowMessage(msg)
{
    alert(msg);
}

//It is used to pop up confirm window after click the Cancel Button.
//It will display Yes/No instead of OK/Cancel
function IsSave(msg,cancelURL)
{
    execScript('n = msgbox("'+msg+'","4132")', "vbscript");

    if(n == 7)
    {
        window.location.href = cancelURL;
    }
}

//---------------------------------------------------//
String.prototype.len=function()
{
    return this.replace(/[^\x00-\xff]/g,"**").length;
}

//Set maxlength for multiline TextBox
//function setMaxLength(object,length)
//{
//    var result = true;
//    var controlid = document.selection.createRange().parentElement().id;
//    var controlValue = document.selection.createRange().text;
//    var tempString=object.value;
//    var tt="";
//    for(var i=0;i<length;i++)
//    {
//        if(tt.len()<length)
//            tt=tempString.substr(0,i+1);
//        else
//            break;
//    }
//    if(tt.len()>length)
//        tt=tt.substr(0,tt.length-1);
//    object.value=tt;
//}
function setMaxLength(object,length)
{
	var result = true;
	var controlid = document.selection.createRange().parentElement().id;
	var controlValue = document.selection.createRange().text;
	if (controlid == object.id && controlValue != "")
	{
		result = true;
	}
	else if (object.value.length >= length)
    {
		result = false;
	}
    if (window.event)
    {
		window.event.returnValue = result;
        return result;
	}
}

//Check maxlength for multiline TextBox when paste
//function limitPaste(object,length)
//{
//    var tempLength = 0;
//    if(document.selection)
//    {
//        if(document.selection.createRange().parentElement().id == object.id)
//        {
//            tempLength = document.selection.createRange().text.len();
//        }
//    }
//    var tempValue = window.clipboardData.getData("Text");
//    tempLength = object.value.len() + tempValue.len() - tempLength;
//    if (tempLength > length)
//    {
//        tempLength -= length;
//        var tt="";
//        for(var i=0;i<tempValue.len()-tempLength;i++)
//        {
//            if(tt.len()<(tempValue.len()-tempLength))
//                tt=tempValue.substr(0,i+1);
//            else
//                break;
//        }
//        if(tt.len()<=0)
//        {
//            window.event.returnValue=false;
//        }
//        else 
//        {
//            tempValue=tt;
//            window.clipboardData.setData("Text", tempValue);
//            window.event.returnValue = true;
//        }
//    }
//}  
function limitPaste(object,length)
{
	var tempLength = 0;
	if(document.selection)
	{
		if(document.selection.createRange().parentElement().id == object.id)
		{
			tempLength = document.selection.createRange().text.length;
		}
	}
	var tempValue = window.clipboardData.getData("Text");
	tempLength = object.value.length + tempValue.length - tempLength;
	if (tempLength > length)
	{
		tempLength -= length;
		tempValue = tempValue.substr(0,tempValue.length - tempLength);
		window.clipboardData.setData("Text", tempValue);
	}
	
	window.event.returnValue = true;
}

//function PressLength() 
//{
//    if(event.srcElement.type=="text" || event.srcElement.type=="textarea" )
//    {
//        if(event.srcElement.length!=null)
//            setMaxLength(event.srcElement,event.srcElement.length);
//    }
//}

//function LimitLength()
//{
//    if(event.srcElement.type=="text" || event.srcElement.type=="textarea" )
//    {
//        if(event.srcElement.length!=null)
//            limitPaste(event.srcElement,event.srcElement.length);
//    } 
//}
//document.documentElement.attachEvent('onkeyup', PressLength);
//document.documentElement.attachEvent('onpaste', LimitLength);
//---------------------------------------------------//
history.forward(1);

function OpenReportWindow(URL, TitleWin)
{
    window.open(URL, TitleWin, 'height=640, width=864, toolbar=no, menubar=no, scrollbars=yes, top=0, left=0, resizable=yes, status=no');
}

function OpenReportNoScrollbarWindow(URL, TitleWin)
{
    var Cwin=window.open(URL, TitleWin, 'height=640, width=864, toolbar=no, menubar=no, scrollbars=no, top=0, left=0, resizable=yes, status=no');
    Cwin.resizeTo(screen.availWidth,screen.availHeight+5);
}

//This function is used to change the css class
function ClassChange(cssStyle,object)
{
    object.className = cssStyle;
}

function confirmDeleteRecord(form, msgDel, msgSelOne)
{
    var selectcount = 0;
    var selectAllObj;
    for (i=0;i<form.elements.length;i++)
    {
        if (form.elements[i].type=="checkbox")
        {
	        if(form.elements[i].lang != "selectall" && form.elements[i].checked == true)
	        {
    	        selectcount++;
            }
        }
    }
    if(selectcount > 0)
    {
        return confirm(msgDel);
    }
    else
    {
        alert(msgSelOne);
        return false;
    }
}

