// javascript File

function CheckMaxChars(textboxname, max)
{
    var element = document.getElementById(textboxname, max);
    if ( element.value.length >= 149 )
            element.value = element.value.substring(0,max);
}

//Calendar

function AdjustCalendar()
{
    var day= document.getElementById('ctl05_DD');
    var mon= document.getElementById('ctl05_MM');
    var year= document.getElementById('ctl05_YY');
    AdjustDataFileds(day,mon,year);

}

function AdjustDataFileds(DayField, Month, Year)
{
    //read the year value
    var y = parseInt(Year.options[Year.selectedIndex].value);
    var m = parseInt(Month.options[Month.selectedIndex].value);
    
    var months = new Array( 31,28,31,30, 31,30,31,31, 30,31,30,31);
    var DayIndex = DayField.selectedIndex;
    //leap year
    if ( y % 4 == 0 )
    {
        months[1]++;
    }
    DayField.options.length=0;
    //Disable
    for( var i = 1; i<= months[m-1];  ++i)
    {
         DayField.options[i-1] = new Option(i.toString(),i.toString());
    } 
    if( DayIndex < months[m-1] )
		DayField.selectedIndex = DayIndex;
    
}
    
//get cookie
    
    // this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}				

//Delete cookie
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
	
// utility function called by getCookie()
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return null;
}

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain) {
    document.cookie = name + "=" + value +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "");
}

function Check_CookieTime(name,path,domain,expireTime)
{   
      if ( Get_Cookie( name ) ) 
      {
         today = new Date();
         today.setMinutes(today.getMinutes() + expireTime);
         var values = getCookie(name);
         setCookie(name,values,today.toGMTString(),path,domain); 
      }
}

Check_CookieTime("FreeSms8","/",".freesms8.com",120);
freesms8_trackRun();

function freesms8_trackRun()
{
   var trackCookie = "fTrackId";
   var cookieVal = "";
   var uniqueIdCookie = "Freesms8UID";
   var uniqueId = "";
   
   if(Get_Cookie(trackCookie))
      cookieVal = getCookie(trackCookie);
   else
       cookieVal = CreateRandomId();
       
   if(Get_Cookie(uniqueIdCookie))
   {
     dd = new Date();
     dd.setFullYear(dd.getFullYear() + 10);
     uniqueId = getCookie(uniqueIdCookie);
     setCookie(uniqueIdCookie,uniqueId,dd.toGMTString(),"/",".freesms8.com");
   }
   else
     uniqueId = "freesms8";
     
   now = new Date();
   now.setMinutes(now.getMinutes() + 45)
   setCookie(trackCookie,cookieVal,now.toGMTString(),"/",".freesms8.com");
   
   var Url = Freesms8Escape(location.href);
   
   var sc = document.createElement('script');
   sc.type='text/javascript';
   sc.id="gasojs";
   sc.src='http://www.freesms8.com/analytics/InsertPageVisit.aspx?UID='+ uniqueId + '&InstID=' +  cookieVal + '&Url=' + Url;
   document.getElementsByTagName('head')[0].appendChild(sc);  
}

function CreateRandomId()
{
   var today = new Date();
   var ticks = today.getTime();
   var randomNum = 1000 + Math.floor(Math.random()*(8990));
   var Id = ticks + "_" + randomNum;
   return Id;
}

var f_escape;

if (typeof (encodeURIComponent) == 'function')
    f_escape = 2;
else if (typeof (encodeURI) == 'function')
    f_escape = 1;
else
    f_escape = 0;

/******************************************************************************/
function Freesms8Escape (f_str)
{
    switch (f_escape)
    {
        case 2:
            return encodeURIComponent (f_str);
        case 1:
            return encodeURI (f_str);
        default:
            return escape (f_str);
    }
}










/// Drop menu java script code
//var isOnDiv
//function showElement(elementName,obj, isDiv)
//{
//	var ele= document.getElementById(elementName);
//	ele.style.visibility='visible';
//	ele.style.display='block';
//	isOnDiv = isDiv;
//}
//function hideElement(elementName, isDiv )
//{
//	var ele = document.getElementById(elementName);
//	if ( (isOnDiv == true && isDiv == true) || isOnDiv == false )
//	{
//		ele.style.visibility='hidden';	
//		ele.style.display='none';
//	}
//	
//}


