﻿// JScript File

window.onload = function()
{
    NetBlur('txtNetWorkName');
}    


function Validate()
{
    var d = e("txtNetWorkName");
    if(isNull(trim(d.value)) == true || trim(d.value) == "give your network a name")
    {
        e("Msg").innerHTML = "please enter your network name";
        d.focus();
        return false;
    }
    if(isName(trim(d.value)) == false)
    {
        e("Msg").innerHTML = "please enter valid network name";
        d.focus();
        return false;
    }
    return true;
}

function NetBlur(obj)
{
    obj = e(obj);
    if(trim(obj.value) == "" || trim(obj.value) == "give your network a name" )
    {
        obj.className = 'txtBPage';
        obj.value = "give your network a name";
    }
    else
        obj.className = 'txtBPageT';
}

function NetEntry(obj)
{
    obj.className = 'txtBPageT';
    if(trim(obj.value) == "give your network a name" )
    {
        obj.value = "";
    }
}

function entPress(obj)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode==13)
	{
	    if(Validate()==true)
	        document.form1.submit();
	    else
	        return false;
    }
}


/******************Validation*******************************/


var strSplChrs = "-+{}' \"[]()&#.'//|@!$%^-/'_=.?:;,"
//function to remove all the trailing and leading spaces in a string, returns the string with no //leading and trailing spaces
function trim(obj)
{		
	if (typeof(obj)=='object') obj=obj.value
	for(i=obj.length-1;i>=0;i--)
		if(obj.charAt(i)!=' ') break		
	obj=obj.substring(0,i+1)
	for(j=0;j<=i+1;j++)
		if(obj.charAt(j)!=' ') break
	return obj.substring(j,i+1)
}

//function to check for null values, returns true or false
function isNull(obj)
{
	//alert("came here");
	if (typeof(obj)=='object') 
	    obj = obj.value
	//alert('obj=' + obj)
	obj=trim(obj);
	return obj.length == 0 ? true:false;
}


function isName(obj)
{
    if (typeof(obj)=='object') obj=obj.value;
    var TestStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ._";
    for(var i=0;i<obj.length;i++)
    {
        if(TestStr.indexOf(obj.charAt(i))<0)
        {
            return false;
        }
    }
    return true;
}

/****************************************Validation end***********************/