﻿/* Col Equalize;
function colHeight(colsarr){
	var heights = new Array();
	for (var i =0;i<colsarr.length;i++){
		if(jQuery(colsarr[i]).length > 1){
			var sec = new Array();
			jQuery(colsarr[i]).each(function(count,obj){
				sec[count]=jQuery(obj).height();
			});
			heights[i] = Math.max.apply(null, sec);
		}else {
			heights[i]= jQuery(colsarr[i]).height();
		}
	};
	var maxheight = Math.max.apply(null, heights);
	for(var i=0;i<colsarr.length;i++){
		jQuery(colsarr[i]).height(maxheight);
	};
};
jQuery(document).ready(function(){
	colHeight(['.equalheight']);
})*/

// tooltip function
function showToolTip(obj) {
	var class_arr = new Array();
	var class_elem = null;
	objClass = jQuery(obj).attr('class');
	class_arr[0] = objClass.match('tt_trigger_reg');
	class_arr[1] = objClass.match('tt_trigger_champ');
	class_arr[2] = objClass.match('tt_trigger_off_reg');
	class_arr[3] = objClass.match('tt_trigger_off_champ');
	class_elem = class_arr.join('');
	//alert(class_elem);
	switch (class_elem) {
		case 'tt_trigger_reg':
			if (jQuery(obj).attr('rel') > 0 && jQuery(obj).attr('nowrap') > 0) {
				jQuery(obj).qtip({
					content: '<strong>Печелиш '+jQuery(obj).attr('rel')+' <img alt="кредита" src=file/style/myzoo/icons/cookie.gif /></strong><span>С Шампионски профил би спечелил: '+jQuery(obj).attr('nowrap')+'</span>',
					style: { name: 'mystyle'}, 
					position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle' } },
					show: { effect: { type: 'fade', length: 500 }, delay: 500 }, 
					hide: { effect: { type: 'fade', length: 500 } }
				});
			}
			break;
		case 'tt_trigger_champ':
			if (jQuery(obj).attr('nowrap') > 0) {
				jQuery(obj).qtip({
					content: '<strong>Печелиш '+jQuery(obj).attr('nowrap')+' <img alt="кредита" src=file/style/myzoo/icons/cookie.gif /></strong><span>',
					style: { name: 'mystyle' }, 
					position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle' } },
					show: { effect: { type: 'fade', length: 500 }, delay: 500 }, 
					hide: { effect: { type: 'fade', length: 500 } }
				});
			}
			break;
		case 'tt_trigger_off_reg':
			if (jQuery(obj).attr('rel') > 0) {
				jQuery(obj).qtip({
					content: '<strong>Губиш '+jQuery(obj).attr('rel')+' <img alt="кредита" src=file/style/myzoo/icons/cookie.gif /></strong><span>',
					style: { name: 'mystyle' },
					position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle' } },				
					show: { effect: { type: 'fade', length: 500 }, delay: 500 }, 
					hide: { effect: { type: 'fade', length: 500 } }
				});
			}
			break;
		case 'tt_trigger_off_champ':
			if (jQuery(obj).attr('nowrap') > 0) {
				jQuery(obj).qtip({
					content: '<strong>Губиш '+jQuery(obj).attr('nowrap')+' <img alt="кредита" src=file/style/myzoo/icons/cookie.gif /></strong><span>',
					style: { name: 'mystyle' }, 
					show: { effect: { type: 'fade', length: 500 }, delay: 500 }, 
					hide: { effect: { type: 'fade', length: 500 } }
				});
			}
	}
}

function searchsuggest(obj) {
	var data = jQuery(obj).val();
	if (data != '') {
		jQuery.ajax({
			type: "POST",
			url: jQuery('#site_url').val() + "autosuggest/index",
			data: "data="+data,
			success: function(msg){
				jQuery("#display").html(msg).show();
			}
		});
		return false;
	} else {
		jQuery('#display').hide();
		jQuery('#display').html('');
	}
}

function getFriends(obj) {

	jQuery.ajax({
			async:false,
			url:jQuery('#site_url').val()+'account/friends/myFriends',
			type:'POST',
			dataType:'json',
			success: function(data){
				obj.next().slideDown('500');
				if (data.length > 0) {
					html_code = ''; 
					for (i=0; i < data.length; i++) {
						html_code += '<li><label><input type="radio" name="select_friend" value="'+data[i].userid+'"> '+data[i].first_name+' '+data[i].last_name+'</label></li>'
					}
					jQuery('#friends_list').find('li').remove().end().append(html_code);
					shareWithFriendsBtn();
				} else {
					jQuery('#friends_list').before('<span>Все още нямате приятели</span>');
				}
			},
			error: function(data){
				alert(data);
			}
	});
}

function shareWithFriendsBtn() {
	jQuery(function(){
		jQuery('.user_short_list label').click(function(){
			jQuery('.user_short_list').next('.button').show();
		});
	});
}

function shareLink() {
	var data = 'u='+jQuery("input:radio[name='select_friend']:checked").val();

	jQuery.ajax({
			async:false,
			url:jQuery('#site_url').val()+'account/friends/shareLink',
			data:data,
			type:'POST',
			dataType:'text',
			success: function(data){
				if (data == 'success') {
					jQuery('.share_result').html('Страницата бе успешно споделена.');
				}
			},
			error: function(data){
				alert(data);
			}
	});
}

function newCaptcha(){
	jQuery.ajax({
			async:false,
			url:jQuery('#site_url').val()+'account/generateCaptcha',
			data:'i=sProtCode',
			type:'POST',
			dataType:'text',
			success: function(data){
				jQuery('#captcha_image').attr('src', data);
			},
			error: function(data){
				alert(data);
			}
	});
}


jQuery(document).ready(function(){

	// Tabs 
	jQuery('.tabs div.box').show();
	jQuery('.tabs div.box + div.box').hide();
	jQuery('.tabs').children('ul').children('li:first-child').addClass('current'); // Set the class of the first link to active
	jQuery('.tabs > ul li a').click(function(){ //When any link is clicked
		jQuery(this).parent().siblings('li').removeClass('current'); // Remove active class from all links
		jQuery(this).parent().addClass('current'); //Set clicked link class to active
		var currentTab = jQuery(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
		jQuery(this).parent().parent().siblings('div').hide(); // Hide all divs
		jQuery(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});
	
	//Navigation
	jQuery(".nav_li").hover(
		function() { 
			if(jQuery(this).find('.subnav_ul').size()){
				jQuery(this).children('.subnav_ul').fadeIn('1000');
				jQuery(this).addClass('hover');
			}
		},
		function() { 
			jQuery(this).children('.subnav_ul').stop(true, true).fadeOut('500');
			jQuery(this).removeClass('hover');
		}
	);

	// Tooltips
	jQuery.fn.qtip.styles.mystyle = {
		name: 'light',
		border: { width: 1, radius: 1, color: '#999999' },
		padding: 15,
		width: 250
	};

	//JS hide 
	//Inner login show
	jQuery('.col1 .login_box_title').click(function(){
		jQuery('#login_hidden').toggle();
	});
	
	//Notification slider
	jQuery('.newmessage:not(.empty)').click(function(){
		jQuery('.newmessage_cont').slideDown('500');
		jQuery('.events_cont').stop(true, true).slideUp('500');
	});
	jQuery('.events:not(.empty)').click(function(){
		jQuery('.events_cont').slideDown('500');
		jQuery('.newmessage_cont').stop(true, true).slideUp('500');
	});
	jQuery('.slider').mouseleave(function(){
		jQuery('.slider_middle').slideUp('500');
	});
	
	//Autosuggest 
	jQuery('.autosuggest').mouseleave(function(){
		jQuery('.display').hide(); 
	});
});

/**
 * Flash Object
 * @author Raymond Benc aka natio <www.raybenc.com>
 * @param string sSrc File source
 * @param int iWidth width
 * @param int iHeight height
*/

function EmbedVideo(sSrc, iWidth, iHeight)
{
	document.write('<object width="'+ iWidth +'" height="'+ iHeight +'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">');
	document.write('<param name="movie" value="'+ sSrc +'" />');
	document.write('<param name="allowfullscreen" value="true" />');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed wmode="transparent" allowfullscreen="true" src="'+ sSrc +'" width="'+ iWidth +'" height="'+ iHeight +'"  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function checkUsMode(bUsName)
{
	c = document.getElementById('fldCountrySel');
	s = document.getElementById('fldStateSel');
    z = document.getElementById('fldZip');
    if (c && s && z)
    {
    	z.disabled = s.disabled = (c.value != (bUsName ? sUsName : sUsVarId));
	}
	else
	{
		if (c && s)
		{
			s.disabled = (c.value != (bUsName ? sUsName : sUsVarId));	
		}
	}
	if(s && s.disabled)
	{
		s.selectedIndex = 0;
	}
	if(z && z.disabled)
	{
			z.value = '';
	}
}

function sId(sElementId)
{
	return document.getElementById(sElementId);
}

function clicktoHideAll()
{
	document.rootnode= document.documentElement;
	if(document.attachEvent &&
	document.compatMode!= 'CSS1Compat'){
		document.rootnode=document.body;
	}
	document.rootnode.onclick= function(e){
		e= window.event||e;
		var who= e.target||e.srcElement;
		while(who!= document.rootnode){
			if(who.className.indexOf('hidClass') !=-1)return;
			who= who.parentNode;
		}
		hideDivs('main-body');
	}
}

function hideDivs(sDiv)
{
	for ( var i=0, len=sDisplayIds.length; i<len; ++i )
	{
		if (document.getElementById(sDisplayIds[i]) == null)
		{
			continue;
		}
		var sId = document.getElementById(sDisplayIds[i]).style;
		if ( sDisplayIds[i] != sDiv && sId.display == '' )
		{
			sId.display='none';
		}
	}
	if (document.getElementById(sDiv) == null)
	{
		return;
	}	
	document.getElementById(sDiv).style.display='';
}

function bookmark(url, description)
{
	netscape=msg[5];
	opera_mess=msg[6];
	other_mess=msg[7];

	if (navigator.appName=='Microsoft Internet Explorer')
	{
		window.external.AddFavorite(url, description);
	}
	else if (navigator.appName=='Netscape')
	{
		if (window.sidebar) 
		{
			window.sidebar.addPanel(description, url, "");
		} 	
		else
		{
			alert(netscape);
		}
	}
	else if(window.opera)
	{
		alert(opera_mess);
	}
	else
	{
		alert(other_mess);
	}
}

var childWindowHandles = new Array();

function popUp2(URL, WIDTH, HEIGHT, SCROLL, LEFT, TOP, sId)
{
	day = new Date();
	id = day.getTime();
	eval("childWindowHandles["+childWindowHandles.length+"] = window.open(URL, '" + (sId!= '' ? sId : id) + "','scrollbars="+ SCROLL +",width="+ WIDTH +",height="+ HEIGHT +",left = "+ LEFT +",top = "+ TOP +", resizable = yes');");
}

function closeChildWindows() 
{
	for (var loop=0; loop<childWindowHandles.length; loop++) if (!childWindowHandles[loop].closed) childWindowHandles[loop].close();
}

/*###############################
	PROGRESS BAR
###############################*/

var progressEnd;
var progressInterval;
var progressAt;
var progressTimer;

function do_prog(item1,item2)
{
	progressEnd = item1;
	progressInterval = item2;
	progressAt = progressEnd;
	progress_update();
}

function progress_clear()
{
	for (var i = 1; i <= progressEnd; i++) document.getElementById('progress'+i).className = 'pbar1';
	progressAt = 0;
}

function progress_update()
{
	progressAt++;
	if (progressAt > progressEnd) progress_clear();
	else document.getElementById('progress'+progressAt).className = 'pbar2';
	progressTimer = setTimeout('progress_update()',progressInterval);
}

function progress_stop()
{
	clearTimeout(progressTimer);
	progress_clear();
}

/*###############################
	MENU MOUSEOVER
###############################*/

function linkon1(id1)
{
	document.getElementById(id1).className='menu5b';

}

function linkon2(id1)
{
	document.getElementById(id1).className='menu5a';

}


/*###############################
	COOKIES
###############################*/


function SetCookie(cookieName,cookieValue,nDays)
{
	var today = new Date();
	var expire = new Date();
 	if (nDays==null || nDays==0) nDays=1;
 	expire.setTime(today.getTime() + 3600000*24*nDays);
 	document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}



/*###############################
	HIDE MENUS
###############################*/

function SwitchMenu(obj,id2)
{
	var el = document.getElementById(obj);
	if(el.style.display == "none") {
		document.getElementById(id2).innerHTML='[-]';
		el.style.display = "";
		SetCookie(obj,"","-1");
	} else {
		document.getElementById(id2).innerHTML='[+]';
		el.style.display = "none";
		SetCookie(obj,1,0);
	}
}


function SwitchMenu2(obj,id2,id3,id4,id5,id6,id7,id8)
{
	var el = document.getElementById(obj);
	if(el.style.display == "none") {
		document.getElementById(id6).innerHTML=id7;
		document.getElementById(id2).src=id5;
		el.style.display = "";
		SetCookie(obj,"","-1");
		document.getElementById(id3).style.width='70%';
	} else {
		document.getElementById(id6).innerHTML=id8;
		document.getElementById(id2).src=id4;
		el.style.display = "none";
		SetCookie(obj,1,0);
		document.getElementById(id3).style.width='100%';
	}
}

function SwitchMenu3(obj,id2)
{
	var el = document.getElementById(obj);
	if(el.style.display == "none") 
	{
		document.getElementById(id2).innerHTML='[-]';
		el.style.display = "";
		document.cookie = obj + "=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
	} 
	else 
	{
		document.getElementById(id2).innerHTML='[+]';
		el.style.display = "none";
	  	document.cookie = obj + "=1; path=/";
	}
}

/*###############################
	GO TO LOCATION / FRAMES
###############################*/
function go_home(link)
{
	if (top.frames.length == 0) {
    		document.cookie = "newURL=" + escape(document.URL) + "; path=/;"
    		ver = parseInt(navigator.appVersion, 10);
    		if ( ((navigator.appName == "Netscape") && (ver >= 3)) ||
         		((navigator.appName == "Microsoft Internet Explorer") && (ver >= 4)) )
      			location.replace(link);
    		else
	      location = link;
    		};
}



/*###############################
	NO RIGHT CLICK
###############################*/
function clickIE()
	{
	if (document.all)
		{
		return false;
		}
	}

function clickNS(e)
	{
	if (document.layers||(document.getElementById&&!document.all))
		{
		if (e.which==2||e.which==3)
			{
			return false;
			}
		}
	}


function noCLICK()
{

	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
	} else {
	document.onmouseup=clickNS;document.oncontextmenu=clickIE;
	}
	document.oncontextmenu=new Function("return false")
}



function jumpTo(list)
{
	var IDS = document.getElementById(list);

	if (IDS.value != "") {
		window.location.href=IDS.value;
	}

	return false;
}






function image1(img,height,width)
{
	if (getCookie('FOX_EN')) { showInfo3(img,width,height); }
	return false;
}


function image2()
{
	if (getCookie('FOX_EN')) { nd(); }
	return false;
}


function image3(type)
{
	if (getCookie('FOX_EN')) {
		SetCookie("FOX_EN","","-1");
	} else {
		SetCookie("FOX_EN",1,0);
	}
}




/*###############################
	IMAGE FADER
###############################*/
function initImage(ids) {
  imageId = ids;
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}


function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;

  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

var clientInfo = navigator.userAgent.toLowerCase();
var isIE = ( clientInfo.indexOf("msie") != -1 );
var isWin = ( (clientInfo.indexOf("win")!=-1) || (clientInfo.indexOf("16bit") != -1) );

function createBBtag( openerTag , closerTag , areaId ) {
	if(isIE && isWin) {
		createBBtag_IE( openerTag , closerTag , areaId );
	}
	else {
		createBBtag_nav( openerTag , closerTag , areaId );
	}
	return;
}

function createBBtag_IE( openerTag , closerTag , areaId ) {
	var txtArea = document.getElementById( areaId );
	var aSelection = document.selection.createRange().text;
	var range = txtArea.createTextRange();

	if(aSelection) {
		document.selection.createRange().text = openerTag + aSelection + closerTag;
		txtArea.focus();
		range.move('textedit');
		range.select();
	}
	else {
		var oldStringLength = range.text.length + openerTag.length;
		txtArea.value += openerTag + closerTag;
		txtArea.focus();
		range.move('character',oldStringLength);
		range.collapse(false);
		range.select();
	}
	return;
}

function createBBtag_nav( openerTag , closerTag , areaId ) {
	var txtArea = document.getElementById( areaId );
	if (txtArea.selectionEnd && (txtArea.selectionEnd - txtArea.selectionStart > 0) ) {
		var preString = (txtArea.value).substring(0,txtArea.selectionStart);
		var newString = openerTag + (txtArea.value).substring(txtArea.selectionStart,txtArea.selectionEnd) + closerTag;
		var postString = (txtArea.value).substring(txtArea.selectionEnd);
		txtArea.value = preString + newString + postString;
		txtArea.focus();
	}
	else {
		var offset = txtArea.selectionStart;
		var preString = (txtArea.value).substring(0,offset);
		var newString = openerTag + closerTag;
		var postString = (txtArea.value).substring(offset);
		txtArea.value = preString + newString + postString;
		txtArea.selectionStart = offset + openerTag.length;
		txtArea.selectionEnd = offset + openerTag.length;
		txtArea.focus();
	}
	return;
}


/*###############################
	INSERT TEXT AT CURSOR
###############################*/
function insertAtCursor(myField, myValue, sType)
{
	if (typeof(tinyMCE) != 'undefined' && sType != 3)
	{
		var newValue = myValue.replace(":","");
		var mainValue = newValue.replace(":","");
		var sub = (sType == 1 || sType == 4) ? 'emo/' : '';
		var html = '<img src="' + sHome + 'file/smile/'+ sub + mainValue + '.gif" alt="" phpfox="image-protect" />';
		tinyMCE.execCommand('mceInsertContent', false, html);
		return;
	}
	else
	{
		if (document.selection)
		{
			myField.focus();
			if (sType == 1)
			{
				sel = opener.document.selection.createRange();
			}
			else
			{
				sel = document.selection.createRange();
			}
			sel.text = myValue;
		}
		else if (myField.selectionStart || myField.selectionStart == '0')
		{
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			myField.value = myField.value.substring(0, startPos)
			+ myValue
			+ myField.value.substring(endPos, myField.value.length);
			myField.focus();
		}
		else
		{
			myField.value += myValue;
		}
	}
}

bCheck = false;

function sel(idname)
{
    with(document.myform)
    {
		for(i=0;i<elements.length;i++)
		{
			thiselm = elements[i];
			if(bCheck)
			     thiselm.checked = false;
			else
			     thiselm.checked = true;
		}
	}
	bCheck = (bCheck ? false : true);
}

function checkEmpty(idname)
{
    var aSel = new Array();

    with(document.myform)
    {
		for(i=0;i<elements.length;i++)
		{
			thiselm = elements[i];
			if(thiselm.checked)
                aSel[i] = 1;
		}

		if(!aSel.length)
		{
		    alert(''+ msg[8] +'');
		    return false;
		}
		else
		  return true;
	}
}
function showInfo(name)
{

	html = '<img border="1" src="'+name+'" name="imagelib" alt="" width="75" height="75" />';
	return overlib(html, CAPTION, name)

}

function showInfo3(name,width,height)
{
	html = '<img border="1" src="'+name+'" alt="" width="'+width+'" height="'+height+'" />';
	return overlib(html)
}

function showInfo2(name)
{
	var newhtml = ''+name+'';
	return overlib(newhtml,WRAP,BGCOLOR,"#00004D",FGCOLOR,"#F6F6F6",TEXTSIZE,"10px",BORDER,2,CELLPAD,5)
}

function showInfo4(name,location,mood)
{
	var newhtml = '<img src="'+location+'" alt="" width="18" height="12" style="vertical-align:middle;" /> '+name+' '+mood+'';

	return overlib(newhtml, CAPTION, name)
}
function showInfo5(name)
{
	var newhtml = ''+name+'';
	return overlib(newhtml,WRAP,BGCOLOR,"#00004D",FGCOLOR,"#F6F6F6",TEXTSIZE,"10px",BORDER,2,CELLPAD,5);
}
function validateDigit(x,rangeMin,rangeMax)
{
    rangeMax =new Number(rangeMax);
    rangeMin =new Number(rangeMin);
	var y=document.getElementById(x).value;

	var num='';
	var myNum=new Number(0);
	for (i = 0; i < y.length; i++)
    {   
        var c = y.charAt(i);
        
        var numBuf=new Number(c);

        if(numBuf!='NaN')
        {
        	previousnum=num;
        	num=num+c;
        	t =new Number(num);
        	if(t<rangeMax && t>rangeMin)
        	{
        		myNum=new Number(num);
        	}
        	else
        	{
        		myNum=new Number(previousnum);
        	}
        	
        	
        }
    }
	
	if(myNum>rangeMin && myNum<rangeMax)
	{
		document.getElementById(x).value=myNum;
	}
	else
	{
		document.getElementById(x).value='';
	}
	
}

function countChars(doc,maxLength,validateTextWordsLength,alertText)
{
   
   var left = maxLength-doc.getElementById('elText').value.length;
   var text = doc.getElementById('elText').value;
   if(validateTextWordsLength)
   {
   		var outer = 0;
   		
   		for(i=0;i<doc.getElementById('elText').value.length;i++)
   		{
   		
   			reWhiteSpace = new RegExp(/^\s+$/);

		     // Check for white space
		     if (reWhiteSpace.test(text.charAt(i))) 
		     {
					outer=0;
		     }
		     
		     if(outer>=30)
		     {
		     	doc.getElementById('elText').value = doc.getElementById('elText').value.substring(0,i)
		       if(alertText!='')
		        alert(alertText);
		     }
		     
		     outer++;
   			
   		}
   }
   
   if(left<0)
   {
   	   doc.getElementById('elLabel').innerHTML =0 ;
   	   doc.getElementById('elText').value = doc.getElementById('elText').value.substring(0,maxLength);
   }
   else
   {
   	   doc.getElementById('elLabel').innerHTML =left ;
   }
}

function validateTextArea(doc,maxLength,alertText,docIdName)
{
   var left = maxLength-doc.getElementById(docIdName).value.length;
   var text = doc.getElementById(docIdName).value;
   
   		var outer = 0;
   		
   		for(i=0;i<doc.getElementById(docIdName).value.length;i++)
   		{
   		
   			reWhiteSpace = new RegExp(/^\s+$/);

		     // Check for white space
		     if (reWhiteSpace.test(text.charAt(i))) 
		     {
					outer=0;
		     }
		     
		     if(outer>=30)
		     {
		     	doc.getElementById(docIdName).value = doc.getElementById(docIdName).value.substring(0,i)
		       if(alertText!='')
		        alert(alertText);
		     }
		     
		     outer++;
   			
   		}
   
   
}

function getDaysForMonthYear(document,dayId,monthId,yearId)
{  
	var dayElementSelect = document.getElementById(dayId);
	var monthElementSelect = document.getElementById(monthId);
	var yearElementSelect = document.getElementById(yearId);

	if(dayElementSelect==null || monthElementSelect==null || yearElementSelect==null)
		return true;
	
	var year = new Number(yearElementSelect.value);
	var month = new Number(monthElementSelect.value);

	var today = new Date();
	// year not selected
	if(year == 0 && year != null) {
		year = today.getFullYear();
	}
	// month not selected
	if(month == 0 && month != null) {
		month = today.getMonth();
	}

	var temp_date = new Date(year, month, 0);
	// get number of days in month
	var days = temp_date.getDate();
	// delete all options
	if(dayElementSelect.options.length > 2) {
		for(var i = dayElementSelect.options.length; i > 0; i--) {
			dayElementSelect.remove(i);
		}
	}	
	// add new options
	for(var i = 1; i <= days; i++) {
    	dayElementSelect.options[i] = new Option(i, i, false, false);
	} 
	/* 
 	var days = dayElementSelect.options.length;
	
	if(month==4 || 
       month==6 || 
       month==9 || 
       month==11)
     {
     	   if(days<30)
     	   {
     	   	   for(i=days;dayElementSelect.options.length<30;i++)
     	   	   {
     	   	   	    dayElementSelect.options[i]=new Option(i+1, i+1, false, false);
     	   	   }
     	   }
     	   else if(days>30)
     	   {
     	   	   for(i=days-1;dayElementSelect.options.length>30;i--)
     	   	   {
     	   	   	    dayElementSelect.remove(i);
     	   	   }
     	   }
     	   
     	   //alert("IS 30");
           return true;
     }
	
	 if(month==2)
     {
	     	if ( ((year % 4 == 0) && !(year % 100 == 0))
				 || (year % 400 == 0) )
		    {
		    	   if(days<29)
		     	   {
		     	   	   for(i=days;dayElementSelect.options.length<29;i++)
		     	   	   {
		     	   	   	    dayElementSelect.options[i]=new Option(i+1, i+1, false, false);
		     	   	   }
		     	   }
		     	   else if(days>29)
		     	   {
		     	   	   for(i=days-1;dayElementSelect.options.length>29;i--)
		     	   	   {
		     	   	   	    dayElementSelect.remove(i);
		     	   	   }
		     	   }
				    	//alert("IS LEAP");
					    return  true;
			}
			else
			{
			   if(days<28)
	     	   {
	     	   	   for(i=days;dayElementSelect.options.length<28;i++)
	     	   	   {
	     	   	   	    dayElementSelect.options[i]=new Option(i+1, i+1, false, false);
	     	   	   }
	     	   }
	     	   else if(days>28)
	     	   {
	     	   	   for(i=days-1;dayElementSelect.options.length>28;i--)
	     	   	   {
	     	   	   	    dayElementSelect.remove(i);
	     	   	   }
	     	   }
			   //alert("IS 28");
			   return  true;
			}
     }

		   if(days<31)
     	   {
     	   	   for(i=days;dayElementSelect.options.length<31;i++)
     	   	   {
     	   	   	    dayElementSelect.options[i]=new Option(i+1, i+1, false, false);
     	   	   }
     	   }
     	   else if(days>31)
     	   {
     	   	   for(i=days-1;dayElementSelect.options.length>31;i--)
     	   	   {
     	   	   	    dayElementSelect.remove(i);
     	   	   }
     	   }
     //alert("IS 31");*/
	return true;
}


