
function divShowHide(s) {
    if (document.getElementById(s).style.display == 'block') {
        document.getElementById(s).style.display = 'none';
    } else {
        document.getElementById(s).style.display = 'block';
    }
};

function divShow(s) {
   document.getElementById(s).style.display = 'block';
};

function divHide(s) {
    document.getElementById(s).style.display = 'none';
};

function submenuShowHide(s) {
    if (document.getElementById(s).style.display == 'block') {
        document.getElementById(s).style.display = 'none';
    } else {
        document.getElementById(s).style.display = 'block';
    };

    imgSrc = document.getElementById(s + '_expand').src;
    if (imgSrc.indexOf('plus') != -1) {
      imgSrc = imgSrc.replace('plus',"minus");
    } else {
     imgSrc = imgSrc.replace('minus',"plus");
    };
    document.getElementById(s + '_expand').src = imgSrc;
};



function changeImgTo(img, src) {
        img.src = src;
};

function changeClass(obj, firstClass, secondClass) {

    if (document.getElementById(obj)) {
        obj = document.getElementById(obj);
        if (obj.getAttribute("class") == firstClass) {
            obj.setAttribute("class", secondClass);
        } else {
            obj.setAttribute("class", firstClass);
        }
    } else {
        if (obj.getAttribute("class") == firstClass) {
            obj.setAttribute("class", secondClass);
        } else {
            obj.setAttribute("class", firstClass);
        }
    }
    
};

function setClassTo(obj, classValue) {
    document.getElementById(obj).className = classValue;
};

function closeLocations() {
    wrapper = document.getElementById('locationsWrapper');
    var child = wrapper.firstChild;
    while (child) {
        if (child.nodeType == 1) {child.style.display = 'none';};
        child = child.nextSibling;
    };       
    for (i = 0; i < document.links.length; i++) {
        if (document.links[i].getAttribute("class") == 'a_blue_locations') {
            document.links[i].setAttribute("class", 'a_grey_locations');
        }
    }
};

function clearField(field, phrase) {
    if (field.value == phrase) {
        field.value = "";
    }
};

function fillupFields(divId, phrase) {
    if (document.getElementById(divId) && document.getElementById(divId).value == "" && document.getElementById(divId).focused != true) {
        document.getElementById(divId).style.color = '#8C8C8C';
        document.getElementById(divId).style.fontStyle = 'italic';
        document.getElementById(divId).value = phrase;
    }

};

function resizeContentDiv() {
    document.getElementById('contentDiv').style.height = document.documentElement.clientHeight - 180 + "px";
};

function changePaddingTop() {
    if (parseInt(document.documentElement.clientWidth) < 1607) {
        document.getElementById('navigationLinksDiv').style.paddingTop = 0 + "px";
    } else {
        document.getElementById('navigationLinksDiv').style.paddingTop = 30 + "px";
    }
};

function startUpDefault() {
    changePaddingTop();
    resizeContentDiv();
};

function calculateShipmentByMeasurements(points) {
    if  (points == "inches") {
    
        boxWidth = parseInt(document.getElementById('widthInputInches').value);
        boxLength = parseInt(document.getElementById('lengthInputInches').value);
        boxHeight = parseInt(document.getElementById('heightInputInches').value);
        resultVolume = boxWidth*boxLength*boxHeight/366;

        if (resultVolume) {
            document.getElementById('costInputInches').value = resultVolume;
        }
    }
    
    else if (points == "cm") {   
        boxWidth = parseInt(document.getElementById('widthInputCm').value);
        boxLength = parseInt(document.getElementById('lengthInputCm').value);
        boxHeight = parseInt(document.getElementById('heightInputCm').value);
        resultVolume = boxWidth * boxLength * boxHeight/6000;

        if (resultVolume) {
            document.getElementById('costInputCm').value = resultVolume;
        }
    }    
};



function mousePageXY(e)
{
  var x = 0, y = 0;

  if (!e) e = window.event;

  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) -  document.documentElement.clientLeft;
    y = e.clientY +  (document.documentElement.scrollTop || document.body.scrollTop) -  document.documentElement.clientTop;
  };

  return {"x":x, "y":y};
};
var mail_validator=function(mails){
	try {
		var mail = "";
		mail=mails;
		mail=mail.replace(/^\s+|\s+$/g, '');
		if (mails != "") {
			if (!(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(mail)) {
				return false;
			}else {
				return true;
			}
		}else {
			return false;
		}
	}catch(e){
		/*alert(e);*/
	}
};
$.fn.sendFriend=function(){
	
	var _this=this;
	var email="";
	var position={};

		$(this).bind('submit', function(e){
			email=$("input#tellFriendInput").val();
			if (!mail_validator(email)) {
				alert("Invalid E-Mail addres");
			}else {
				position=$(_this).position;
				$("div.loader").css({'top': position.top, "left": position.left, "cursor": "pointer"}).bind('click', function(){
					$(this).fadeOut(150)
				}).fadeIn(250,function(){
					$.ajax({
						type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
						data: {ajax: 'tellFriend',email: email},
						success: function(data){$("div.loader").fadeOut(150);}
					});
				});				
			}
		});
	
	return this;
};
$.fn.subscribe=function(){
	var _this=this;
	var email="";
	var position={};
	
		$(this).bind('submit',function(e){
			email=$("input#subscribeInput").val();
			if (!mail_validator(email)) {
				alert("Invalid E-Mail addres");
			}else {
				position=$(_this).position;
				$("div.loader").css({'top': position.top, "left": position.left, "cursor": "pointer"}).bind('click', function(){
					$(this).fadeOut(150)
				}).fadeIn(250,function(){
					$.ajax({
						type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
						data: {ajax: 'subscribe',email: email},
						success: function(data){$("div.loader").fadeOut(150);}
					});
				});
			}
		});
	return this;
};

$.fn.feadBack=function(){
	
	$(this).bind("submit", function(){
		if(mail_validator($("input#emailInput").val())){
			var p=$(this).position;
			
			$("div.loader").css({"left": p.left, "top": p.top}).fadeIn(100);
			$.ajax({
						type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
						data: {ajax: 'submitform',email: $("input#emailInput").val(), name: $("input#nameInput").val(), text: $("textarea.textareaMessageField").val()},
						success: function(data){$("div.loader").fadeOut(150);}
			});
		}
		
		return false;
	});
};

function changeImg(img, destSrc, origSrc) {
    if (img.src.indexOf(destSrc)!=-1) {
        img.src = img.src.replace(destSrc, origSrc);
    } else {
    img.src = img.src.replace(origSrc, destSrc);
    }
};

$.fn.changeImg=function(){
	
		$(this).live("mouseover",function(){
			var destSrc="";
			var img="";
			var origSrc="";
			destSrc=$(this).children("a").attr('rel');
			img=$(this).children("a").children("img").attr('src');
			origSrc=destSrc.replace("Inactive","");
			img= img.replace(destSrc, origSrc);
			$(this).children("a").attr('rel',origSrc);
			$(this).children("a").children("img").attr('src',img);		
		});
		$(this).live("mouseout",function(){
			var destSrc="";
			var img="";
			var origSrc="";
			destSrc=$(this).children("a").attr('rel');
			img=$(this).children("a").children("img").attr('src');
			origSrc="Inactive"+origSrc;
			img= img.replace(destSrc, "Inactive"+destSrc);		
			$(this).children("a").attr('rel',"Inactive"+destSrc);
			$(this).children("a").children("img").attr('src',img);	
		});
};


$.fn.viewFaqRespose=function(){
$(this).live("click", function(){var QuestId="";QuestId=$(this).attr('id');$("#re"+QuestId).slideToggle(150);$('div.faqAnswer').not("#re"+QuestId).slideUp(150);});
}
/*
var mail_validator=function(mails){
	try {
		var mail = "";
		mail=mails;
		mail=mail.replace(/^\s+|\s+$/g, '');
		if (mails != "") {
			if (!(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(mail)) {
				return false;
			}else {
				return true;
			}
		}else {
			return false;
		}
	}catch(e){}
};
*/
$.fn.validateRegForm=function(){
	var returns=false;
	$(this).live("submit", function(){
		if($(this).children("input#fname").val()!=""){$(this).children("input#fname").attr({"class":"textXLarge"});returns=true;
			if ($(this).children("input#sname").val() != ""){$(this).children("input#sname").attr({"class":"textXLarge"});returns=true;
				if (mail_validator($(this).children("input#email").val())) {$(this).children("input#email").attr({"class":"textXLarge"});returns=true;
					if (($(this).children("input#password").val() != "")&&($(this).children("input#password").val()==$(this).children("input#repassword").val())) {
						$(this).children("input#password, input#repassword").attr({"class":"textXLarge"});returns=true;
						if($(this).children("input#phone").val() != ""){$(this).children("input#phone").attr({"class":"textXLarge"});returns=true;
							if ($(this).children("input#address").val() != "") {$(this).children("input#address").attr({"class": "textXLarge"});returns=true;
								if ($(this).children("input#city").val() != "") {$(this).children("input#city").attr({"class": "textXLarge"});returns=true;
									if ($("input#state").val() != "") {$("input#state").attr({"class": "textSmall"});returns=true;										
										if ($("input#country").val() != "") {$("input#country").attr({"class": "textMedium"});returns = true;
											if ($("input#zip").val() != "") {$("input#zip").attr({"class": "textXSmall"});returns = true;
											}else{$("input#zip").attr({"class": "textXSmallEr"});returns = false;}
										}else{$("input#country").attr({"class": "textMediumEr"});returns = false;}										
									}else{$("input#state").attr({"class": "textSmallEr"});returns=false;}
								}else{$(this).children("input#city").attr({"class": "textXLargeEr"});returns=false;}								
							}else{$(this).children("input#address").attr({"class":"textXLargeEr"});returns=false;}
						}else{$(this).children("input#phone").attr({"class":"textXLargeEr"});returns=false;}
					}else{$(this).children("input#password, input#repassword").attr({"class":"textXLargeEr"});returns=false;}
				}else{$(this).children("input#email").attr({"class":"textXLargeEr"});returns=false;}
			}else{$(this).children("input#sname").attr({"class":"textXLargeEr"});returns=false;}
		}else{$(this).children("input#fname").attr({"class":"textXLargeEr"});returns=false;}
		
		if(returns==false){return false;}
		else{$(this).submit();}
	});
};

$.fn.ShowEdit=function(){
	$(this).live("click",function(){
		$("div#info_acc").slideUp(250, function(){
			$("div#edit_form").slideDown(250);
		});
		return false;
	});
	return this;
};

$.fn.saveAccInfo=function(){
	$(this).live("submit", function(){
		$("div.loader").fadeIn(150);
		$.ajax({
			type: 'POST',action: "",dataType: 'html',async: false,timeout: 15000,
			data: {ajax: 'save_change_accinfo',
				   ufname: $("input#ufname").val(),
				   usname: $("input#usname").val(),
				   uphone: $("input#uphone").val(),
				   uaddr: $("input#uaddr").val(),
				   ucity: $("input#ucity").val(),
				   ustate: $("input#ustate").val(),
				   ucountry: $("input#ucountry").val()
				  },
			success: function(data){
				$("div#info_acc").children("div.flLeft:last").html(data);
				$("div.loader").fadeOut(150);
				$("div#edit_form").slideUp(250, function(){
					$("div#info_acc").slideDown(250, function(){});
				});
			}
		});
		return false;
	});
	return this;
};

$.fn.checker=function(options){
	var defaults={formID:"#all_mess"};
	var set=$.extend(defaults,options||{});
	$(this).live("click", function(){
		if($(this).is(":checked")){$(set.formID+" input[type=checkbox]").attr({"checked": "checked"});}
		else{$(set.formID+" input[type=checkbox]").removeAttr("checked");}
	});
};

$.fn.setTab=function(host,tabs){
	/*$(this).children("img:first").attr({
		"src": host + "img/siteElements/content/myAccount/activeMenuTabLeft.jpg"
	});*/
	
	$(this).children("div.flLeft").each(function(){
		var tabHref=$(this).children("div").children("a").attr("href");
		
		//if(window.location.href==tabHref){
		if((tabs).test(tabHref)){
			$(this).children("img:first").attr({
				"src": host + "img/siteElements/content/myAccount/activeMenuTabLeft.jpg"
			});
			$(this).children("img:last").attr({
				"src": host + "img/siteElements/content/myAccount/activeMenuTabRight.jpg"
			});
			$(this).children("div").attr({"class": "activeMenuTabLink"});
			$(this).children("div").children("a").attr({"class": "aActiveMenuTabLink"});
		}else{
			$(this).children("img:first").attr({
				"src": host + "img/siteElements/content/myAccount/menuTabLeft.jpg"
			});
			$(this).children("img:last").attr({
				"src": host + "img/siteElements/content/myAccount/menuTabRight.jpg"
			});
			$(this).children("div").attr({"class": "menuTabLink"});
			$(this).children("div").children("a").attr({"class": "aMenuTabLink"});
		}
	});
};

$.fn.delSelMes=function(options){
	var defaults={formID:"#all_mess"};
	var set=$.extend(defaults,options||{});
	$(this).live("click", function(){
		if ($(set.formID + " input[type=checkbox]:checked").length > 1) {
			$(set.formID).submit();
		}
		
	});
};

$.fn.viewCard=function(options){
	var defaults={"formID":"#all_mess",
				  "blockID": "#addfounds"
				 };
	
	var set=$.extend(defaults,options||{});
	var htm_pay_form=$(set.blockID+" div.pay_form").html();
	$(this).live("click", function(){
		$(set.blockID).slideDown(200, function(){
			
			$(set.blockID+" .closer").live("click", function(){
				$(set.blockID).slideUp(200);
				$(set.blockID+" div.pay_form").html(htm_pay_form);
			});
			$(set.blockID+" form").live("submit", function(){
				$("div.loader").fadeIn(150);
				$.ajax({
					type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
					data: {ajax: 'add_found',
				   			ufname: $("input#fname").val(),
				   			usname: $("input#sname").val(),
				   			umail: $("input#email").val(),
							amount: $("input#amount").val(),
				   			cn: $("input#cn").val(),
				   			cexp: $("input#emm").val()+$("input#eyy").val(),
				   			ccv: $("input#ccv").val()
				  		},
					success: function(data){						
						$("div.loader").fadeOut(150);
						$(set.blockID+" div.pay_form").text(data);
						setTimeout(function(){
							window.location.reload();
						},5000);
					}
				});
				return false;
			});
		});
	});
	return this;
};

$.payBalance=function(paybtn, options){
	$.ajax({
		type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
		data: {ajax: 'paytobalance',cardID : options.cardID, sum: options.sum},
		success: function(data){						
				$(paybtn).parent("div").fadeOut(250);
		}
	});
	return false;
};

$.payBalanceAll=function(paybtn, options){
	var loc=window.location;
	$.ajax({
		type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
		data: {ajax: 'paytobalance',cardID : options.cardID, sum: options.sum},
		success: function(data){						
				$(paybtn).parent("div").fadeOut(250, function(){window.location.href=loc.href;});
		}
	});
	return false;
};

$.fn.payParcel=function(options){
	var defaults={"formID":"#payparcel",
				  "blockID": "#payparcel"
				 };
	
	var set=$.extend(defaults,options||{});
	var htm_pay_form=$(set.blockID+" div.pay_form").html();
	var _this=this;
	$(this).live("click", function(){
		$(set.blockID).slideDown(200, function(){
			
			$(set.blockID+" .closer").live("click", function(){
				$(set.blockID).slideUp(200);
				$(set.blockID+" div.pay_form").html(htm_pay_form);
			});
			$(set.blockID+" form").live("submit", function(){
				$("div.loader").fadeIn(150);
				$.ajax({
					type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
					data: {ajax: 'paytocc',
				   			ufname: $("input#fname").val(),
				   			usname: $("input#sname").val(),
				   			umail: $("input#email").val(),
							amount: $("input#amount").val(),
				   			cn: $("input#cn").val(),
				   			cexp: $("input#emm").val()+$("input#eyy").val(),
				   			ccv: $("input#ccv").val(),
							cid: $("input#cid").val()
				  		},
					success: function(data){	
					if (data != "") {
						$("div.loader").fadeOut(150);
						$(set.blockID + " div.pay_form").text(data);
						$(_this).parent('div').fadeOut(250);
						setTimeout(function(){
							$(set.blockID).fadeOut(200, function(){
								$(this).remove();
							});
						}, 10000);
					}else{
						$(set.blockID).fadeOut(200);
						$(set.blockID+" div.pay_form").html(htm_pay_form);
					}
						
					}
				});
				return false;
			});
		});
	});
	return this;
};

$.payParcel=function(options){
	var loc=window.location;
	var defaults={"formID":"#payparcel",
				  "blockID": "#payparcel",
				  "cid" : "0",
				  "amount": "0"
				 };
	
	var set=$.extend(defaults,options||{});
	var htm_pay_form=$(set.blockID+" div.pay_form").html();
	var _this=this;

		$(set.blockID).slideDown(200, function(){
			$("input#amount").val(set.amount);$("input#cid").val(set.cid);
			$(set.blockID+" .closer").live("click", function(){
				$(set.blockID).slideUp(200);
				$(set.blockID+" div.pay_form").html(htm_pay_form);
			});
			$(set.blockID+" form").live("submit", function(){
				$("div.loader").fadeIn(150);
				$.ajax({
					type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
					data: {ajax: 'paytocc',
				   			ufname: $("input#fname").val(),
				   			usname: $("input#sname").val(),
				   			umail: $("input#email").val(),
							amount: set.amount,
				   			cn: $("input#cn").val(),
				   			cexp: $("input#emm").val()+$("input#eyy").val(),
				   			ccv: $("input#ccv").val(),
							cid: set.cid
				  		},
					success: function(data){	
					if (data != "") {
						$("div.loader").fadeOut(150);
						$(set.blockID + " div.pay_form").text(data);
						$(_this).parent('div').fadeOut(250);
						setTimeout(function(){
							$(set.blockID).fadeOut(200, function(){
								$(_this).remove();
								window.location.href=loc.href;
							});
						}, 10000);
					}else{
						$(set.blockID).fadeOut(200);
						$(set.blockID+" div.pay_form").html(htm_pay_form);
					}
						
					}
				});
				return false;
			});
		});

	return this;
};

function google_initialize() {
    //  var content = $('#content');
      // Setting the text in the div.
     // content.html() = '<div id="text">Hola, me alegro mucho de verte.<\/div><div id="translation"/>';
    
      // Grabbing the text to translate
      var text = $("#transcontent").val();
    
      // Translate from Spanish to English, and have the callback of the request
      // put the resulting translation in the "translation" div.
      // Note: by putting in an empty string for the source language ('es') then the translation
      // will auto-detect the source language.
      google.language.translate(text, $("#fromtnas").val(), $("#totnas").val(), function(result) {
        var translated = $("#transres");
        if (result.translation) {
          translated.val(result.translation);
        }
      });
    }

$.fn.translater=function(){
	$(this).live("submit", function(){
		google_initialize();
		return false;
	});
}

$.fn.tou=function(){
	$(this).live("click", function(){
		if($("#toucheck").is(":checked")){
			$("#addpc").fadeIn(150);
			$("form#addparcel").submit(function(){return true;});
		}else{
			$("#addpc").fadeOut(150);
			$("form#addparcel").submit(function(){return false;});
		}
	});
}

$.fn.sapc=function(){
	$(this).submit(function(){
		if($("#toucheck").is(":checked")){
			$("#addpc").fadeIn(150);
			return true;
		}else{
			$("#addpc").fadeOut(150);
			return false;
		}
	});
}

$.fn.feedbackfrm=function(){
	$(this).children("fieldset").children("label.radio_yesno").children("input[name=accurate]").change(function(){
		var tnh=this;
		$(this).parent("label.radio_yesno").parent("fieldset").children("label.radio_yesno").fadeOut(150, function(){
			$(tnh).parent("label.radio_yesno").parent("fieldset").children('label.tnh').fadeIn(100);
			
		});
		
			if($(tnh).val()==0){
				$(this).parent("label.radio_yesno").parent("fieldset").parent("form").children('div.feed').fadeIn(150);
				$(this).parent("label.radio_yesno").parent("fieldset").parent("form").submit(function(){
					$.ajax({
					type: 'POST',action: "",dataType: 'text',async: false,timeout: 15000,
					data: {ajax: 'feedfaq',
				   			id: $(this).children('div.feed').children('input.faqid').val(),
				   			feed: $(this).children('div.feed').children('textarea.questfaqfeed').val()
							
				  		},
					success: function(data){	
					$(tnh).parent("label.radio_yesno").parent("fieldset").parent("form").children('div.feed').fadeOut(150);
					}
				});
					return false;
				});
			}
	});
}


