﻿// JScript File

function displayConfirm(msg)
{
    return window.confirm(FormatAlertMsg(msg, ""));
}


function FormatAlertMsg( msg, title )
{
	AlertString = title + "\n-------------------------------------------------------------------------\n\n" + msg + "\n\n-------------------------------------------------------------------------";
	return AlertString;
}


function GoToUrl(url)
{   
    window.location.href = url;
    return false;
}

function CheckImageType(filePath)
{
    //alert(filePath);
    var res = /\.(gif|jpg|jpeg|png)$/i.test(filePath); 
    //alert(res);
    return res;
}


function ChangeCheckBoxStatus(vStatus, name)
{
    var chkList;
    chkList = document.getElementsByTagName('INPUT');
    if (chkList.length > 0) 
    { 
        for (var i=0; i < chkList.length; i++) 
        { 
            if (chkList[i].type == "checkbox" && chkList[i].name.indexOf(name) >= 0) 
            { 
                chkList[i].checked = vStatus; 
            } 
        } 
    } 
}

function GetSelectedCheckBox(name, foundMsg, notFoundMsg)
{
    var countSelected;
    var chkList;
    countSelected = 0;
    chkList = document.getElementsByTagName('INPUT');
    if (chkList.length > 0) 
    { 
        for (var i=0; i < chkList.length; i++) 
        { 
            if (chkList[i].type == "checkbox" && chkList[i].name.indexOf(name) >= 0) 
            { 
                if (chkList[i].checked == true) 
                { 
                    countSelected++; 
                } 
            } 
        } 
    }    

    if (countSelected > 0)
    {
        if (foundMsg.length > 0)
        {
            return displayConfirm(foundMsg);
        }
        else
        {
            return true;
        }
    }
    else 
    { 
        if (notFoundMsg.length > 0)
        {
            alert(FormatAlertMsg(notFoundMsg, ""));
        }
        return false; 
    } 
}

function AddToCart()
{

}

function SetPageInitialHeight()
{
    var ctrl = document.getElementById("content");
	if (ctrl != null)
	{
		var ch = ctrl.offsetHeight;
    	if (ch != "undefined" && ch < 500)
   		{
		        ctrl.style.height = 500 + 'px';
		}

	}
}
	
/** Pops up a new window in the middle of the screen **/

function popupwin(mypage, myname, w, h, scroll)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) 
	{ 
	    win.window.focus(); 
	}
}

/** This will check for valid domain name **/	
function checkDomain(nname)
{
    var arr = new Array('.com','.net','.org','.biz','.info','.edu','.gov');

    var mai = nname;
    var val = true;

    var dot = mai.lastIndexOf(".");
    var dname = mai.substring(0,dot);
    var ext = mai.substring(dot,mai.length);
    //alert(ext);
	
    if(dot>2 && dot<57)
    {
        for(var i=0; i<arr.length; i++)
        {
            if(ext == arr[i])
            {
                val = true;
                break;
            }	
            else
            {
                val = false;
            }
        }
        if(val == false)
        {
            alert("Your domain extension "+ext+" is not correct");
            return false;
        }
        else
        {
            for(var j=0; j<dname.length; j++)
            {
                var dh = dname.charAt(j);
                var hh = dh.charCodeAt(0);
                if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
                {
                    if((j==0 || j==dname.length-1) && hh == 45)	
                    {
                        alert("Domain name should not begin or end with '-'");
                        return false;
                    }
                }
                else
                {
                    alert("Your domain name should not have special characters");
                    return false;
                }
	        }
        }
    }
    else
    {
        alert("Your Domain name is too short/long");
        return false;
    }	
    return true;
}


function SetLOSImageForIE6()
{
    var strBrowser = navigator.userAgent;

	if (strBrowser.indexOf("MSIE 6.0") > 0)
	{
		var ctrl_losImage = document.getElementById("losImage");
		if (ctrl_losImage != null)
		{
			ctrl_losImage.style.paddingLeft = "8px";
		}
		
	}
}


// Redirect to the help page if cookie is not enabled at client browser
//*************************************************************************

function TakesCookies()
{
	var GetsCookie = (navigator.cookieEnabled)?true:false
	// If the browser does not support cookie check
	if(typeof navigator.cookieEnabled=="undefined" && !cookieEnabled)
	{
		// Try setting up a test cookie
		document.cookie = "SampleCookie";
		// And see if it got set successfully
		GetsCookie = (document.cookie.indexOf("SampleCookie")!=-1)?true:false
	}
	return GetsCookie;
}
		
function CookieTest()
{
	// TakesCookies is now set to the proper value
	var path=window.location.href.toString().substring(window.location.href.toString().lastIndexOf('/')+1);
	var cookiePagePath="/driver.aspx?Topic=Cookie+Help";
	if(path != cookiePagePath)
	{
		if(TakesCookies()==false)
		{
			//alert("This browser does not accept cookies");
			window.location = '/driver.aspx?Topic=Cookie+Help';
		}
	}
}