﻿// JScript File
$(document).ready(function(){
    if(parent.document.getElementsByTagName("iframe").length > 0)
    {
        parent.location.href = "login.aspx?logout = true";
    }
    var d = new Date();
    var localTime = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds()
    
    $("#hdnClientDate").attr('value', localTime);    
    
    $("form input").keypress(function (e) {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
         $('#form1').submit();
        return false;
    } else {
        return true;
    }
    });
    $("#hdnChkJS").val("js enabled");
    var options = document.getElementsByTagName("option");
    for(i=0;i<options.length;i++)
    {
        if(options[i].value == "0")
        {
            options[i].style.backgroundColor = "#F4F4F4";
            options[i].style.fontWeight = "bold";
        }
    }
});
function Validate()
{
    var errmsg = "";
    var isValidate = true;    
    var setFocus = false;
	if(document.forms[0].txtuname.value == "")
	{
		errmsg = "Please enter Username\n";
		document.forms[0].txtuname.focus();		
		isValidate = false;		
		setFocus = true;
	}  
	if(document.forms[0].txtPwd.value == "")
	{
		errmsg += "Please enter Password\n";		
		if(!setFocus)
		{
		    document.forms[0].txtPwd.focus();
		    setFocus = true;
		}		 
		isValidate = false;
	}
	if (document.forms[0].cmbBranch.options[document.forms[0].cmbBranch.selectedIndex].value == "Select Campus" || 
	    document.forms[0].cmbBranch.options[document.forms[0].cmbBranch.selectedIndex].value == "0")
	{
		errmsg += "Please select Campus";
		if(!setFocus)
		{
		    document.forms[0].cmbBranch.focus()
		    setFocus = true;
		}
		isValidate = false;
    }  			    
    if(!isValidate)
        alert(errmsg);
        
	return isValidate;
}
			
function redirectForgotPwd()
{
    var branch = document.forms[0].cmbBranch.options[document.forms[0].cmbBranch.selectedIndex].value;			  
    if(branch != "")
        window.location.href = "../" + branch + "/ForgotPassword.asp";
    else
    alert("Please select branch"); 
			  
    return false; 
}
			
function itSupport()
{
    var myFeatures = 'width=' + 430 + ',height=' + 567 ;
    myFeatures += ',resizable=no,scrollbars=yes,top=85,left=250,alwaysLowered=no,alwaysRaised=yes,alwaysOnTop=yes';         
			  
    var hWnd = window.open("itSupport.htm",'MyGIIS',myFeatures); 
			  
    return false;
}
			
function selectBranch(strBranch)
{			  
    var ctrlBranch = document.forms[0].cmbBranch;
    for(i=0;i<=ctrlBranch.length-1;i++)
    {	
        if(ctrlBranch.options[i].value.toLowerCase()==strBranch.toLowerCase())
        {			      
            ctrlBranch.selectedIndex = i;
            //displayCtryFag();
            break;
        }
    }
}

function displayCtryFag()
{
    var ctrlBranch = document.getElementById("cmbBranch");
    var ctrlImgFlag = document.getElementById("imgFlag");
    var ctrlSpan = document.getElementById("CountryFlag");
			  
    for(i=0;i<=arBranch.length;i++)
    {
        if(arBranch[i] != '' && arBranch[i] == ctrlBranch.options[ctrlBranch.selectedIndex].value)
        {				  
            ctrlSpan.style.display = 'inline';
            ctrlImgFlag.src = '_images/flags/'+ arCountryFlag[i] + '.gif';	
            break;			  
        } 
        else
        {
            ctrlSpan.style.display = 'none';				  
            ctrlImgFlag.src = '_images/flags/trans.gif';				  
        } 
    }
}

