
// Custom jQuery functions
$.fn.exists = function(){return this.length>0;}
//
var tabTimer;
var EmailPat = /^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
var PhonePat = /^\D*\d{3}\D*\d{3}\D*\d{4}\D*$/;
var ZipPat = /^\d{5}([\-]\d{4})?$/;
var subnavrunning = false;

function showhidesubnav(id){
	if(subnavrunning==false){
		subnavrunning = true;
		$('#iss_main_subnav div[id!='+id+'][class!=padding]').hide();
		$('#iss_main_subnav div[id='+id+'][class!=padding]').fadeIn("fast",function(){subnavrunning=false;});
	}
}
function switchtab(id){
	stopTabTimer();
	//$('#hometabber tr.tabs td[id!='+id+']').removeClass('selected').addClass('unselected');
	$('#hometabber tr.tabs td').removeClass('selected').addClass('unselected');
	$('#hometabber tr.tabs td[id='+id+']').removeClass('unselected').addClass('selected');
	//$('#hometabber tr td.content div[id!=content'+id+']').hide();
	$('#hometabber tr td.content div').hide();
	$('#hometabber tr td.content div[id=content'+id+']').show();
}

function rotatetabs(){
	curr = $('#hometabber tr.tabs td[class=selected]');
	next = curr.next().attr('id');
	if(next == undefined){next="tab1";}
	switchtab(next);
	startTabTimer();
}

function startTabTimer(){
	clearTimeout(tabTimer);
	tabTimer = setTimeout("rotatetabs()",4000);
}
function stopTabTimer(){
	clearTimeout(tabTimer);
}

function isValidZipCode(value) {
   return value.match(ZipPat);
}
function isValidEmail(value){
	return value.match(EmailPat);
}
function isValidPhone(value){
	return value.match(PhonePat);
}

function reloadCart(){
	$.ajax({
		url: '/AJAX/cartpreview.cfm',
		cache: false,
		async: true,
		success: function(html){
			$('#cartajax').html(html);
		}
	});
}

function showCart(){
	t = $('#carttip').offset().top+29;
	l = ($('#carttip').offset().left-(380+98));
	//alert(t+" / "+r);
	$('#cartajax').html('<div style="width:350px;height:75px;background-color:white;padding:2px;color:black;text-align:left;"><br><img src="/siteart/progress.gif" style="float:left;"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>Cargando el carrito...Por favor espere.</em></div>').css("top",t+"px").css("left",l+"px").slideDown('fast');
	$.ajax({
		url: '/AJAX/cartpreview.cfm',
		cache: false,
		async: true,
		success: function(html){
			$('#cartajax').html(html);
		}
	});
}

function hideCart(){
	$('#cartajax').slideUp('fast');
}

function loadDialog(ttl, html) {
	$('#UIModalContent').dialog('destroy').html(html).dialog({
		title: ttl, modal: true, width: 450, height:300, resizable: false,
		buttons:{"Close": function() { $(this).dialog("close"); }},
		open: function(event, ui) {
			$(this).parent().css("left",($(window).width()-$(this).width())/2+"px");
			$(this).parent().css("top",($(window).height()-$(this).height())/2-50+"px");
			$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
		},
		dragStop: function(event, ui){
			$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
		}
	});
}

function loadBlockDialog(ttl, html) {
	$('#UIModalContent').dialog('destroy').html(html).dialog({
		title: ttl, modal: true, width: 450, height:300, resizable: false, closeOnEscape: false,
		open: function(event, ui) {
			$(this).parent().children().children('.ui-dialog-titlebar-close').hide(); 
			$(this).parent().css("left",($(window).width()-$(this).width())/2+"px");
			$(this).parent().css("top",($(window).height()-$(this).height())/2-50+"px");
			$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
		},
		dragStop: function(event, ui){
			$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
		}
	});
}

function ajax(argurl, div, functionName) {
	$.ajax({
		url:argurl,
		cache:false,
		success: function(data){
			$('#'+div).html(data);
			if (functionName) {
				eval(functionName+"(data)");	
			}
		}
	})
}

function initISSjs(){
	$('#hometabber tr.tabs td').each(function(idx,ele){
		$(this).click(function(){
			switchtab(ele.id);
		});
	});
	$('#hometabber tr td.content').mouseover(function(){
		stopTabTimer();
	});
	$('#hometabber').mouseout(function(){
		startTabTimer();
	});
	showhidesubnav('main_menu_blank');
	switchtab('tab1');
	startTabTimer();
}

function getCheckedValue(myOption) {
	myValue = $("input[name='"+myOption+"']:checked").val();
	if (myValue == undefined) {
		return "";	
	} else {
		return myValue;
	}
}

function block_rightclick() {
	$("img").bind("contextmenu",function(e){
		return false;
	});
}

