/*form validation*/
String.prototype.isValidEmail=function(){
	re= /^([a-z0-9])+([._])?([a-z0-9])+@([a-z0-9\-])+\.([a-z0-9]){2,}$/i;
	return re.test(this);
}

String.prototype.isValidNumber=function(){
	return /^(\+)?\d+$/.test(this);
}
String.prototype.isValidPhone=function(){
	return /^[\+\d\s\-\(\)]+$/.test(this);
	//return this.match(/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/)==null?false:true;
}

String.prototype.isValidAlfaNumaric=function(){
	return /^\w+$/.test(this);
}

isValidForm=function(form,selector){
	var $field=$(form).find(selector);
	var error=[];
	var elem=[];
	var focusClass='smartFocus';
	var wrapClass=focusClass+'-wrap';
	var index=0;
	$field.each(function(i,o){
			$(o).val($.trim($(o).val()));
			if( $(o).val()=='' || $(o).filter(':not(:checkbox)').val()==o.defaultValue
							   || ($(o).is(':checkbox')&&!$(o).is(':checked'))
							   || ($(o).is('.email')&&!$(o).val().isValidEmail()) 
							   || ($(o).is('.numeric')&&!$(o).val().isValidNumber())
							   || ($(o).is('.phone')&&!$(o).val().isValidPhone())
							   || ($(o).is('.alphanumeric')&&!$(o).val().isValidAlfaNumaric())
							   //|| (o==form.confirm_email && form.email.value!=form.confirm_email.value) 
							   ){
				error[index]=true;
				elem[index]=o;
				index+=1;
				//$(o).removeClass(focusClass);
			}
			else{
				//error[i]=false;
				//$(o).removeClass(focusClass);
			}
	}).removeClass(focusClass).parent().removeClass(wrapClass);
	
	if(elem.length){
		$(elem).addClass(focusClass).eq(0).focus();
		$(elem).filter(':checkbox').parent().addClass(wrapClass);
		//alert(elem[0].name);
		return false;
		}
	else {
		return true;
		//alert('no error');
	}
}

$.fn.smartInput=function(){
		return this.each(function(i,o){
		 $(o).focus(function(){if(this.value==this.defaultValue) this.value='';})
			 .blur(function(){this.value=($.trim(this.value)=='')?this.defaultValue:$.trim(this.value);});
		 });
}


function basename(path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');  
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    return b;
}

loadDATA=function(ref,success){
	$.ajax({
		   type: $(ref).attr('method')||"GET", 
		   url: $(ref).attr('href')||$(ref).attr('action'), 
		   data: $(ref).attr('href')||$(ref).serialize(),
		   success: success
	});
}

$.fn.addYT=function(){
	
	return this.each(function(){
				var vid=$(this).attr('vid');
				var width=$(this).attr('width');
				var height=$(this).attr('height');
				var code='<object width="'+width+'" height="'+height+'"> \
				<param name="movie" value="http://www.youtube.com/v/'+vid+'?fs=1&amp;hl=en_US"></param> \
				<param name="wmode" value="transparent"></param> \
				<param name="allowFullScreen" value="true"></param> \
				<param name="allowscriptaccess" value="always"></param> \
				<embed src="http://www.youtube.com/v/'+vid+'?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="'+width+'" height="'+height+'"> \
				</embed> \
				</object>';
				var $wrap=$('<div/>',{css:{width:width+'px',
										   height:height+'px',
										   lineHeight:height+'px',
										   textAlign:'center',
										   overflow:'hidden'
										   },
									 'class':'yt',
									  html:code
									});
				$(this).replaceWith($wrap);
				//$(this).after(code);
		});
	
}
