

$(function(){
	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	
	// png fix for ie in the client side, if use browscap.ini on the server side please comment this
	/*
	var cssSrc = '/css/images.non.ie.css';
	if ($.browser.msie &&( parseFloat($.browser.version)<8)) {
		cssSrc = '/css/images.ie.6.css';
	} 
	$('<link>').appendTo('head').attr({rel: 'stylesheet',type: 'text/css',href: cssSrc});
	// end png fix css	
		*/
	a = $(window).height();
	c = $('body').height();
	if (c<a) {
		$('#footer').css( {'position':'absolute','bottom':'0'});
		$('#headerinside').css('width','948px');
		$('#menu').css('padding-right','16px');
	}
	
		
		$('.popupwin').click(function() {
			
			 var left   = (screen.width  - 550)/2;
			 var top    = (screen.height - 550)/2;
			url = $(this).attr('href');
			width = 550;
			hght = 550;
			if (url=='/learn-vip.html') {
				width = 520;
				hght = 410;
			}
			//newwin = window.open(url, 'popupwin', 'width='+width+', height='+hght+',top='+top+' ,scrollbars=1, left='+left); 
			// if (window.focus) {newwin.focus()} 
			window.open(url, 'popupwin', 'width='+width+', height='+hght+',top='+top+' ,scrollbars=1, left='+left); 
			return false;
		});
	
	viplink();

	
});
function viplink() {
	$('.vipEscort').each(function() {
		$(this).find('a').css({'color':'#ffc600','font-size':'11px','font-family':'arial','font-weight':'bold'});
		$(this).hover(
				  function () {
					$(this).find('a').css({'text-decoration':'underline' });
					$(this).find('img').css({'border-color':'#ffc600' });
				  }, 
				  function () {
					$(this).find('a').css({'text-decoration':'none' });
					$(this).find('img').css({'border-color':'#fff' });
				  }
				); 
	});
}
function phoneformatES(obj) {
	str = obj.value;
	
	str = str.replace(/[^\d]/g,"");
	var newval=ccc='';
	var strlength = carpos = str.length;
	for (i=0;i<strlength;i++) {
		//alert(strlength);
		ccc=ccc_f='';
		if (strlength<=10) {
			/*if (i == 2) {
				newval = '('+newval+str.substr(i,1)+')';
			} else*/ if (i == 3) {
				newval =  '('+newval+')-'+str.substr(i,1);
			} else if (i == 6) {
				newval =  newval+'-'+str.substr(i,1);
			} else {
				newval =  newval+str.substr(i,1);
			}
		} else {
			if (strlength == 11) {
				if (i == 0) {
					newval = newval+str.substr(i,1)+'-(';
				} else if (i == 3) {
					newval =  newval+str.substr(i,1)+')-';
				} else if (i == 6) {
					newval =  newval+str.substr(i,1)+'-';
				}  else {
					newval =  newval+str.substr(i,1);
				}
			} else if (strlength == 12) {
				if (i == 1) {
					newval = newval+str.substr(i,1)+'-(';
				} else if (i == 4) {
					newval =  newval+str.substr(i,1)+')-';
				} else if (i == 7) {
					newval =  newval+str.substr(i,1)+'-';
				}  else {
					newval =  newval+str.substr(i,1);
				}
			} else if (strlength == 13){
				if (i == 2) {
					newval = newval+str.substr(i,1)+'-(';
				} else if (i == 5) {
					newval =  newval+str.substr(i,1)+')-';
				} else if (i == 8) {
					newval =  newval+str.substr(i,1)+'-';
				}  else {
					newval =  newval+str.substr(i,1);
				}
			}
		}
	}
	obj.value= newval;
	
	
}
function strip_tags (str, allowed_tags) {

    var key = '', allowed = false;
    var matches = [];
    var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = '';

    var replacer = function (search, replace, str) {
        return str.split(search).join(replace);
    };

    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
    }

    str += '';

    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);

    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }

        // Save HTML tag
        html = matches[key].toString();

        // Is tag not in allowed list? Remove from str!
        allowed = false;

        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;

            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}

            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }

        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }

    return str;
}
