﻿function onSilverlightError(sender, args) {

    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }
    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    //            throw new Error(errMsg);
}

function ValidateContact() {
    var name = document.getElementById('txtName');
    var email = document.getElementById('txtEmail');
    var phone = document.getElementById('txtPhoneNo');
    var company = document.getElementById('txtCompany');
    var comment = document.getElementById('txtSuggestion');
    var country = document.getElementById('cbCountry');

    if (name.value == "") {
        alert("Please enter your name");
        name.focus();
        return false;
    }
    else if (email.value == "") {
        alert("Please enter your email address");
        email.focus();
        return false;
    }
    else if (country.value == "0") {
        alert("Please select a country");
        country.focus();
        return false;
    }
    else if ((!ValidateEmailAddress(email.value))) {
        alert("Not valid email format");
        email.focus();
        return false;
    }
    else if (phone.value != "" && !(PhoneValidator(phone.value))) {
        phone.focus();
        return false;
    }
    else if (company.value == "") {
        alert("Company/Organization is required");
        company.focus();
        return false;
    }
    else if (comment.value == "") {
        alert("Please enter your business requirements");
        comment.focus();
        return false;
    }
    else
        return true;
}

function ValidateEmailAddress(sEmailAddress) {
    return ((sEmailAddress.length > 0) && (sEmailAddress.indexOf("@") > 0) && (sEmailAddress.indexOf(".", sEmailAddress.indexOf("@")) > 0));
}

function EmailValidator(emailTxt) {
    var email = document.getElementById(emailTxt);
    if (!ValidateEmailAddress(email.value)) {
        alert("Not valid email format");
        email.focus();
        return false;
    } else
        return true;
}

function PhoneValidator(phoneTxt) {
    var stripped = phoneTxt.replace(/[\-\ ]/g, ''); //phoneTxt.replace(/[\(\)\.\-\ ]/g,'');        

    if (isNaN(stripped)) {
        alert("The phone number contains illegal characters.\n Only numeric with '-' are permitted.");
        return false;
    } else //including area code & country code
        if (stripped.length < 10 || stripped.length > 12) {
        alert("The phone number is of wrong length.");
        return false;
    }
    else
        return true;
}

function validateFeedback() {
    var name = document.getElementById('txtName');
    var email = document.getElementById('txtEmail');
    var phone = document.getElementById('txtPhone');
    var comment = document.getElementById('txtComment');

    if (name.value == "") {
        alert("Please enter your name");
        name.focus();
        return false;
    }
    else if (phone.value != "" && !(PhoneValidator(phone.value))) {
        phone.focus();
        return false;
    }
    else if (email.value == "") {
        alert("Please enter your email address");
        email.focus();
        return false;
    }
    else if ((!ValidateEmailAddress(email.value))) {
        alert("Not valid email format");
        email.focus();
        return false;
    }
    else if (comment.value == "") {
        alert("Please enter your comments");
        comment.focus();
        return false;
    }
    else
        return true;
}

function ViewFile(_filename) {
    window.open(_filename, 'CustomPopUp', 'menubar=no, resizable=yes');
    return false;
}

function ViewNewsContent(url) {
    window.open(url, "Source");
}

//*********** Footer control scripts : Begins Here ************//

function Print() {
    var windowUrl = 'about:blank';
    var windowName = 'Print' + new Date().getTime();
    var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

    printWindow.document.write(document.getElementById('txtTitle').value + "<br /><br/>");
    printWindow.document.write(document.getElementById('txtContent').innerHTML);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();
}

function Email() {
    mail_str = "mailto:?subject=Check out the " + document.title;
    mail_str += "&body=I thought you might be interested in the " + document.title;
    mail_str += ". You can view it at, " + location.href;
    location.href = mail_str;
}

function Favourites() {
    window.external.AddFavorite(location.href, document.title);
}

function OpenWebsite(st) {
    window.open("http://www.mahindrasatyam.com/index.asp");
}
//********** Footer Control scripts : Ends Here ************//
//*********** Slide show scripts : Begins Here ************//

var counter = 0;
var timer;

function SlideShowTimer(maxCount) {

    if (counter >= maxCount)
        counter = 0;
    timer = window.setTimeout("SlideShowImageChange('" + maxCount + "')", 4000);

}

function SlideShowImageChange(imgCount) {
    var host = document.getElementById('Xaml1');
    host.content.SlideShow.ChangeImage(counter);
    counter++;
    SlideShowTimer(imgCount);
}


function StopSlideShow() {
    window.clearTimeout(timer);
}

function ForceIncrementCounter() {

    counter++;
}

function OnImageSelectionSetCounter(index) {
//    alert(index);
    counter = index;
}

//********** Slide Show scripts : Ends Here ************//
//********** HTML Content Panel : Starts Here *********//

function DisplayContent(bVisiblity) {
    var displayContent = document.getElementById('divContent');

    if (bVisiblity == 'visible') {
        document.getElementById('IsContentDisplayed').value = "true";
        PaintIFrame();
    }
    displayContent.style.visibility = bVisiblity;
}

function LoadContentData(title, data) {
    document.getElementById('txtContent').innerHTML = data;
    document.getElementById('txtTitle').value = title;

}

function PaintIFrame() {
    //alert(document.getElementById('IsContentDisplayed').value);
    if (document.getElementById('IsContentDisplayed').value == "true") {
        var displayContent = document.getElementById('divContent');
        var sl = document.getElementById('silverlightControlHost');
        var posX = getDimX(sl) + 242;
        var posY = getDimY(sl) + 96;
        posX = posX.toString() + "px";
        posY = posY.toString() + "px";
        //alert(posX);
        displayContent.style.left = posX; //"474px";
        displayContent.style.top = posY; //"163px";

        var contentFrame = document.getElementById('iFrameContent');
        contentFrame.src = "ContentPanel.html";
    }
}

function HideHTMLContentPanel() {
    if (document.getElementById('IsContentDisplayed').value == "true") {
        document.getElementById('divContent').style.visibility = 'hidden';
        var contentFrame = document.getElementById('iFrameContent');
        document.getElementById('IsContentDisplayed').value = "false";
        contentFrame.src = "";
    }
}

function getDimX(el) {
    for (var lx = 0; el != null;
            lx += el.offsetLeft, el = el.offsetParent);
    //alert(lx);
    return lx
}

function getDimY(el) {
    for (var ly = 0; el != null;
            ly += el.offsetTop, el = el.offsetParent);
    //alert(ly);
    return ly
}

//********** HTML Content Panel : Ends Here *********//

//********** OS Detection function : Starts Here *********//

function DetectOS() {
    var os, ua = navigator.userAgent;
    if (ua.match(/Win(dows )?NT 6\.1/)) {
        os = "Windows 7"; 			// Windows 7 
    }
    else if (ua.match(/Win(dows )?NT 6\.0/)) {
        os = "Windows Vista"; 			// Windows Vista
    }
    else if (ua.match(/Win(dows )?NT 5\.2/)) {
        os = "Windows Server 2003"; 		// Windows Server 2003 
    }
    else if (ua.match(/Win(dows )?(NT 5\.1|XP)/)) {
        os = "Windows XP"; 			// Windows XP 
    }
    else if (ua.match(/Win(dows)? (9x 4\.90|ME)/)) {
        os = "Windows ME"; 			// Windows ME 
    }
    else if (ua.match(/Win(dows )?(NT 5\.0|2000)/)) {
        os = "Windows 2000"; 			// Windows 2000 
    }
    else if (ua.match(/Win(dows )?98/)) {
        os = "Windows 98"; 			// Windows 98 
    }
    else if (ua.match(/Win(dows )?NT( 4\.0)?/)) {
        os = "Windows NT"; 			// Windows NT 
    }
    else if (ua.match(/Win(dows )?95/)) {
        os = "Windows 95"; 			// Windows 95 
    }
    else if (ua.match(/Mac|PPC/)) {
        os = "Mac OS"; 				// Macintosh 
    }
    else if (ua.match(/Linux/)) {
        os = "Linux"; 				// Linux 
    }
    else if (ua.match(/(Free|Net|Open)BSD/)) {
        os = RegExp.$1 + "BSD"; 			// BSD 
    }
    else if (ua.match(/SunOS/)) {
        os = "Solaris"; 				// Solaris 
    }
    else {
        location.replace("http://msalliance.satyam.com/MSAASPNET/MSA/UI/Home.aspx"); 			// OS 
    }
}

//********** OS Detection function : Ends Here *********//

