﻿//Banner Links Script start
	function enableLink(id, url) {

	    if (id == 0) {
	        id = Get_Cookie("urlID");
	    }
	    Set_Cookie('urlID', url, '', '/', '', '');

	    for (i = 1; i <= 15; i++) {
	        var link = document.getElementById(i);
	        if (link != null) {
	            if (id != i) {
	                link.style.color = '#71c8e4';
	                link.style.textDecoration = "none";
	                link.style.cursor = "pointer";
	                link.style.fontWeight = 'normal';

	            } else {
	                link.style.color = "#000000";
	                link.style.textDecoration = "none";
	                link.style.fontWeight = 'bold';
	                link.style.cursor = "default";

	            }
	        }
	    }
	}
	//Banner Links Script End

	
	// JavaScript Document
function getid(id)
{
	return document.getElementById(id);
}


function showlogin() {
    
    if (getid('loginBoxBtm').style.display != 'block') {
        if (getid('bannerOuter')) {
            getid('login').src = 'Images/icon_login_down.gif';
        }
        else {
            getid('login').src = '../Images/icon_login_down.gif';
        }
        getid('loginBoxBtm').style.display = 'block';
    } else {
        if (getid('bannerOuter')) {
            getid('login').src = 'Images/icon_login.gif';
        }
        else {
            getid('login').src = '../Images/icon_login.gif';
        }
        getid('loginBoxBtm').style.display = 'none';
    }
}


//function showlogin()
//{
//	if(getid('loginBoxBtm').style.display!='block')
//	{
//		getid('login').src='../Images/icon_login_down.gif';
//		getid('loginBoxBtm').style.display='block';
//	}else{
//		getid('login').src='../Images/icon_login.gif';
//		getid('loginBoxBtm').style.display='none';
//	}
//}

var dvid;
function curosal()
{
	dvid = 0;
	if(getid('bannerRight'))
	{
		var dls = getid('bannerRight').getElementsByTagName('dl');
		var divs = getid('bannerLeft').getElementsByTagName('div');
		for(i=0;i<dls.length;i++)
		{
			dls[i].id = 'dl'+i;
			dls[i].onmouseover = new Function('showCnt('+i+')');
			dls[i].onmouseout = new Function('showCnt(5)');
		}
		for(j=0;j<divs.length;j++)
		{
			if(divs[j].className == 'bannerLeft'){
				divs[j].id = 'div'+dvid;
				divs[j].style.display = 'none';
				dvid++;
			}
		}
		getid('div'+(dvid-1)).style.display = 'block';
	}
}
var stridnum = 5;
function showCnt(id)
{
	if(id!=stridnum){
		getid('div'+id).style.display = 'block';
		getid('div'+stridnum).style.display = 'none';
		stridnum = id;
	}
}
window.onload = curosal;
function loginRsponse()
{
	var httpRequest; 
	try
	{
		httpRequest = new XMLHttpRequest();
	} catch (e)
		{
		try
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
			{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				alert("Your browser broke!");
				return false;
			}
		}
	}
	httpRequest.onreadystatechange = function() {

	    if (httpRequest.readyState == 4) {
	        var strResponse = httpRequest.responseText;
	        strResponse = strResponse.substring(0, 1);

	        if (strResponse == '0') {
	            alert('Username or Password is not matching');
	        } 
	        //VIKIRAJ 30 nov 2010 for handling inactive users
	        else if (strResponse == '8') {
	        //need to change 8 to 99
	            alert('Username is not active. Please contact the Administrator.');
	        } else if (strResponse == '1') {
	            window.location = 'http://localhost:3003/MediAngelsPortal/AdminPages/GetPassword.aspx';
	        } else if (strResponse == '2') {
	            window.location = 'http://orkut.com';
	        } else if (strResponse == '3') {
	            window.location = 'http://localhost:3003/MediAngelsPortal/DashBoards/MISReport_AllQueryTypes.aspx';
	        } else if (strResponse == '4') {
	            //window.location = 'http://localhost:3003/MediAngelsPortal/ProfileForms/DoctorProfile.aspx';
	            window.location = 'http://localhost:3003/MediAngelsPortal/DashBoards/DoctorPendingConsultation.aspx';
	        } else if (strResponse == '6') {
	            window.location = 'http://localhost:3003/MediAngelsPortal/DashBoards/ConsumerMain.aspx';
	        }
	    }
	}

//outdated id name
	if (getid('bannerOuter')) {
	    loginUrl = 'Login.aspx';
	}
	else {
	    loginUrl = '#';
	}

	loginUrl = 'http://localhost:3003/MediAngelsPortal/Login.aspx'; 
	httpRequest.open('GET', loginUrl+'?user=' + encodeURIComponent(getid('username').value) + '&pwd=' + encodeURIComponent(getid('password').value), true);
	httpRequest.send(null);
}

function OuterloginRsponse() {
    var httpRequest;
    try {
        httpRequest = new XMLHttpRequest();
    } catch (e) {
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("Your browser broke!");
                return false;
            }
        }
    }
    httpRequest.onreadystatechange = function() {

        if (httpRequest.readyState == 4) {
            var strResponse = httpRequest.responseText;
            strResponse = strResponse.substring(0, 1);

            if (strResponse == '0') {
                alert('Username or Password is not matching');
            }
            //VIKIRAJ 30 nov 2010 for handling inactive users
            else if (strResponse == '8') {
                alert('Username is not active. Please contact the Administrator.');
            }
            else if (strResponse == '1') {
                window.location = 'http://localhost:3003/MediAngelsPortal/AdminPages/GetPassword.aspx';
            } else if (strResponse == '2') {
                window.location = 'http://orkut.com';
            } else if (strResponse == '3') {
                window.location = 'http://localhost:3003/MediAngelsPortal/DashBoards/MISReport_AllQueryTypes.aspx';
            } else if (strResponse == '4') {
                window.location = 'http://localhost:3003/MediAngelsPortal/DashBoards/DoctorPendingConsultation.aspx';
            } else if (strResponse == '6') {
                window.location = 'http://localhost:3003/MediAngelsPortal/DashBoards/ConsumerMain.aspx';
            }
        }
    }

    loginUrl = 'http://localhost:3003/MediAngelsPortal/Login.aspx';

    httpRequest.open('GET', loginUrl + '?user=' + encodeURIComponent(getid('username').value) + '&pwd=' + encodeURIComponent(getid('password').value), true);
    httpRequest.send(null);
}


// Function checks whether the entered string is a combination of interger/characters and space. If not an alpha numeric character then it displays an error message
function isalphawithspace(objName, str, errMsg) {
    var numaric = str;
    for (var j = 0; j < numaric.length; j++) {
        var alphaa = numaric.charAt(j);
        var hh = alphaa.charCodeAt(0);
        if ((hh > 64 && hh < 91) || (hh > 96 && hh < 123) || (hh == 32)) {
        }
        else {

            objName.focus();
            alert(errMsg);
            return false;
        }
    }
    return true;
}




//Merging with the old common_validation.js file VIKIRAJ 25Nov2010


// Function checks whether the entered string is a combination of interger/characters, space,numbersSign,coma,hyphen,dot. 
//If not an alpha numeric character then it displays an error message [space32 #35 ,44 -45 .46 ]
function isalphanumericwithSpecialChars(objName, str, errMsg) {
    var numaric = str;
    for (var j = 0; j < numaric.length; j++) {
        var alphaa = numaric.charAt(j);
        var hh = alphaa.charCodeAt(0);
        if ((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123) || (hh == 32) || (hh == 35) || (hh == 44) || (hh == 45) || (hh == 46)
            || (hh == 92 || (hh == 40) || (hh == 41) || (hh == 38))
            ) {
        }
        else {
            objName.focus();
            alert(errMsg);
            return false;
        }
    }
    return true;
}

function isalphanumericwithSpecialCharsOtherThanReturn(objName, str, errMsg) {
    var numaric = str;
    for (var j = 0; j < numaric.length; j++) {
        var alphaa = numaric.charAt(j);
        var hh = alphaa.charCodeAt(0);

        if ((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123) || (hh == 32) || (hh == 35) || (hh == 44) || (hh == 45) || (hh == 46)
            || (hh == 92 || (hh == 40) || (hh == 41) || (hh == 38) || (hh == 10))
            ) {
        }
        else {
            objName.focus();
            alert(errMsg);
            return false;
        }
    }
    return true;
}

//To check the string is empty
function not_empty_chk(obj_str, str1) {
    if (trim(str1) == "" || trim(str1) == null)
    //if(str1=="" || str1== null)
    {
        return false;
    }
    return true;
}

//To check the string is empty
function empty_chk(obj_str, str1, error_msg) {
    if (trim(str1) == "" || trim(str1) == null) {
        obj_str.focus();
        alert(error_msg)
        return false;
    }
    return true;
}

function checkDropdownValue(objValue, strValue) {
    if (objValue.indexOf(strValue) >= 0)
        return true;
    alert("Please select a valid Speciality")

    return false;
}
// To check whether a dropdown box is selected or not, when it has a default text.
function checkDropDownboxSelected(objName, strErrorMsg) {
    if (objName.selectedIndex == 0) {
        alert(strErrorMsg)
        objName.focus();
        return false;
    }
    return true;
}

function checkDropDownboxSelectedOrNot(objName) {
    if (objName.selectedIndex == 0) {
        return false;
    }
    else {
        return true;

    }

}


// Function checks whether the entered string is a combination of intergers only. If not an numeric then it displays an error message
function isNumericWithSpace(objName, str, errMsg) {
    var numeric = str;
    for (var j = 0; j < numeric.length; j++) {
        var alphaa = numeric.charAt(j);
        var hh = alphaa.charCodeAt(0);

        if ((hh > 47 && hh < 59) || (hh == 32) || (hh == 43)) {

        }
        else {
            objName.focus();
            alert(errMsg);
            return false;
        }
    }
    return true;
}

// Validation for decimal.
function IsFloat(objName, str, errMsg) {
    var regexpression = new RegExp('^[0-9]*(\.)?[0-9]+$');
    if (!str.match(regexpression)) {
        objName.focus();
        alert(errMsg);
        return false;
    }
    return true;
}

//Date should not be grater than today.         
function checkdate(str) {
    var month = str.split("/")[1];
    var day = str.split("/")[0];
    var year = str.split("/")[2];

    var dt = new Date(year, month - 1, day);
    var today = new Date();
    if (dt > today) {
        return false;
    }
    return true;
}

//To Trim the value entered to textbox 
function trim(s) {
    return s.replace(/^\s*/, "").replace(/\s*$/, "");
}

//Email Validation
function emailCheck(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        alert("Please enter a valid E-mail ID")
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr-1) {
        alert("Please enter a valid E-mail ID")
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr-1) {
        alert("Please enter a valid E-mail ID")
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        alert("Please enter a valid E-mail ID")
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        alert("Please enter a valid E-mail ID")
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        alert("Please enter a valid E-mail ID")
        return false
    }

    if (str.indexOf(" ") != -1) {
        alert("Please enter a valid E-mail ID")
        return false
    }
    return true
}

function Set_Cookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + value +
                    ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
                    ((path) ? ";path=" + path : "") +
                    ((domain) ? ";domain=" + domain : "") +
                    ((secure) ? ";secure" : "");
}

function Get_Cookie(name) {

    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) &&
            (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

//------------------------------------------------------------------------------------------------------------

// The function works on key press events, allows numbers only, not even space or any other spl characters.
function numbersonly(e) {

    var unicode = e.charCode ? e.charCode : e.keyCode
    if (unicode < 48 || unicode > 57) //if not a number
        return false //disable key press
}

/*Function used to validate whether Second date is less than First date.*/
function validateBetweenDates(fromDate, toDate) {
    var dt1, dt2;
    var datecurr, date_Entered;
    var strDate, strMonth, strYear, strCurrFullDate, returnCode;

    dt1 = fromDate;
    if (dt1 != null) {
        dt2 = toDate;
        arrCurDate1 = dt1.split("/");
        arrCurDate2 = dt2.split("/");

        strCurrFullDate1 = arrCurDate1[0] + "/" + arrCurDate1[1] + "/" + arrCurDate1[2];
        strCurrFullDate2 = arrCurDate2[0] + "/" + arrCurDate2[1] + "/" + arrCurDate2[2];

        returnCode = fnCompareDate(strCurrFullDate1, strCurrFullDate2);
        if (1 == returnCode) {
            return true;
        }
        else if ((0 == returnCode) || (-1 == returnCode)) {
            return false;
        }
    }
}

/*Function used to compare the date entered in the Textbox with current date.*/
function fnCompareDate(Date1, Date2) {
    var arrDate1, arrDate2, dtDate1, dtDate2, intDtCmp
    intDtCmp = 0;
    if ((Date1 != "") && (Date2 != "")) {
        arrDate1 = Date1.split("/"); //splits the date entered in Textbox "-".
        arrDate2 = Date2.split("/"); //splits the current date with "-".

        dtDate1 = new Date(arrDate1[2], arrDate1[1], arrDate1[0]);
        dtDate2 = new Date(arrDate2[2], arrDate2[1], arrDate2[0]);

        if ((dtDate1.getDate() == dtDate2.getDate()) && (dtDate1.getMonth() == dtDate2.getMonth()) && (dtDate1.getFullYear() == dtDate2.getFullYear())) {
            intDtCmp = 1;
        }
        else if (dtDate1.getFullYear() < dtDate2.getFullYear()) {
            intDtCmp = -1;
        }
        else if ((dtDate1.getMonth() < dtDate2.getMonth()) && (dtDate1.getFullYear() == dtDate2.getFullYear())) {
            intDtCmp = -1;
        }
        else if ((dtDate1.getDate() < dtDate2.getDate()) && (dtDate1.getFullYear() == dtDate2.getFullYear()) && ((dtDate1.getMonth() == dtDate2.getMonth()))) {
            intDtCmp = -1;
        }
        else {
            intDtCmp = 1;
        }
    }
    return intDtCmp;
}


/**
* DHTML textbox character counter script. 
*/
//var maxL=500;
var infoText = "Characters Remaining: ";
var bName = navigator.appName;
function taLimit(taObj, maxL) {
    if (taObj.value.length >= maxL) return false;
    return true;
}

function taCount(taObj, Cnt, maxL) {
    objCnt = createObject(Cnt);
    objVal = taObj.value;
    if (objVal.length > maxL) {
        objVal = objVal.substring(0, maxL);
        taObj.value = objVal;
        alert("You have reached the text limit specified. The excess text, if any, has been truncated.");
    }
    if (objCnt) {
        if (bName == "Netscape") {
            objCnt.textContent = infoText + (maxL - objVal.length);
        }
        else { objCnt.innerText = infoText + (maxL - objVal.length); }
    }
    return true;
}
function taCountRuntime(taObjVal, Cnt, maxL) {
    objCnt = createObject(Cnt);
    objVal = taObjVal;
    if (objVal.length > maxL) objVal = objVal.substring(0, maxL);
    if (objCnt) {
        if (bName == "Netscape") {
            objCnt.textContent = infoText + (maxL - objVal.length);
        }
        else { objCnt.innerText = infoText + (maxL - objVal.length); }
    }
    return true;
}
function createObject(objId) {
    if (document.getElementById) return document.getElementById(objId);
    else if (document.layers) return eval("document." + objId);
    else if (document.all) return eval("document.all." + objId);
    else return eval("document." + objId);
}

//This Function Allow user to select date by using calendar Control only
//Once Date is selected and if any changes are made after that it validate the string
function isDate(obj, dtStr) {
    var dtCh = "/";
    var minYear = 1900;
    var maxYear = 2100;

    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strDay = dtStr.substring(0, pos1)
    var strMonth = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        alert("Please use calendar to select date. \nThe date format should be : dd/mm/yyyy")
        return false
    }

    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        alert("Please enter a valid day")
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        alert("Please enter a valid month")
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        obj.value = dtStr.substring(0, 10);
        alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1) {
        //|| isInteger(stripCharsInBag(dtStr, dtCh))==false
        obj.value = dtStr.substring(0, 10);
        alert("Please enter a valid date")
        return false
    }
    return true
}

function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function removeHTMLTags(str) {
    if (document.getElementById) {
        var strInputCode = str; //document.getElementById("input-code").innerHTML;
        /* 
        This line is optional, it replaces escaped brackets with real ones, 
        i.e. < is replaced with < and > is replaced with >
        */
        strInputCode = strInputCode.replace(/&(lt|gt);/g, function(strMatch, p1) {
            return (p1 == "lt") ? "<" : ">";
        });
        var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
        return strTagStrippedText;
    }
}



