/*
    Purpose : All common Java Script functions reside here
    Date    : 29/06/2008
    By      : Anup  
*/

var oRE_EmptyString = /^(\s)*$/; 
var oRE_Tel = /^[\d]{8,14}$/; 
var oRE_Email = /^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)+$/i; 
var oRE_Date = /^([0][1-9]|[1][0-2])+[\/]([0][1-9]|[1][0-9]|[2][0-9]|[3][0-1])+[\/][\d]{4}$/i; 
   
function ValidateRegExp(sInput,oRE)
{
    if(oRE.test(sInput))
        return true;
    else
        return false;                
}

function Trim(sInput)
{
    //This function trims blank spaces from both the ends 
    //of the string "sInput"
    var oRE_EmptySpaces = /^(\s)*/;
    sInput = sInput.replace(oRE_EmptySpaces,"");

    var oRE_EmptySpaces = /(\s)*$/;
    sInput = sInput.replace(oRE_EmptySpaces,"");

    return sInput;
}        

function CopyListItem()
{
    for(var i=0; i<document.forms[0].sectionLeft.options.length;i++)
    {
        if(document.forms[0].sectionLeft.options[i].selected)
        {
            if(document.forms[0].sectionRight.options.length < 5)
            {
                if(!VerifyListItemExists(document.forms[0].sectionLeft.options[i].value))
                {
                    var oOption = document.createElement("Option");
                    oOption.text = document.forms[0].sectionLeft.options[i].text;
                    oOption.value = document.forms[0].sectionLeft.options[i].value;
                    document.forms[0].sectionRight.options.add(oOption);
                }
            }
            else
            {
                alert("Maximum 5 images can be added");    
                break;
            }    
        }
    }
}

function RemoveListItem()
{
    for(var i=parseInt(document.forms[0].sectionRight.options.length-1); i>=0;i--)
    {
        if(document.forms[0].sectionRight.options[i].selected)
        {
           document.forms[0].sectionRight.options.remove(i);
        }   
    }
}

function VerifyListItemExists(ListItemValue)
{
    if(document.forms[0].sectionRight.options.length == 0)
        return false;
    for(var i=0; i<document.forms[0].sectionRight.options.length;i++)
    {
        if(document.forms[0].sectionRight.options[i].value == ListItemValue)
        {
            alert("File already present");
            return true;
        }
    }    
    return false;
}

function ViewListItem(Section)
{
    for(var i=0; i<document.forms[0].sectionLeft.options.length;i++)
    {
        if(document.forms[0].sectionLeft.options[i].selected)
        {
            var ListItemPath = document.forms[0].sectionLeft.options[i].text;
            var ImgPath = "ImageListDisplay.asp?Section=Section" + Section + "&ListItemPath=" + ListItemPath;
            window.open(ImgPath,"","width=300,height=300,status=no,menu=no,location=no,top=" + parseInt((i*50)) + ",left=" + parseInt((i*50)) );
        }
    }        
}

function UploadListItem(Section)
{
    if(document.forms[0].sectionRight.options.length == 0)
    {
        alert("Please add some image to the right list box");
        return false;
    }        
    for(var i=0;i<document.forms[0].sectionRight.options.length;i++)
        document.forms[0].sectionRight.options[i].selected=true;
    return true;
}

function disableClick()
{
    if (event.button==2)
        return false;
}