function removeAccent(str){
    var map={'À':'A','Á':'A','Â':'A','Ã':'A','Ä':'A','Å':'A','Æ':'AE','Ç':'C','È':'E','É':'E','Ê':'E','Ë':'E','Ì':'I','Í':'I','Î':'I','Ï':'I','Ð':'D','Ñ':'N','Ò':'O','Ó':'O','Ô':'O','Õ':'O','Ö':'O','Ø':'O','Ù':'U','Ú':'U','Û':'U','Ü':'U','Ý':'Y','ß':'s','à':'a','á':'a','â':'a','ã':'a','ä':'a','å':'a','æ':'ae','ç':'c','è':'e','é':'e','ê':'e','ë':'e','ì':'i','í':'i','î':'i','ï':'i','ñ':'n','ò':'o','ó':'o','ô':'o','õ':'o','ö':'o','ø':'o','ù':'u','ú':'u','û':'u','ü':'u','ý':'y','ÿ':'y','Ā':'A','ā':'a','Ă':'A','ă':'a','Ą':'A','ą':'a','Ć':'C','ć':'c','Ĉ':'C','ĉ':'c','Ċ':'C','ċ':'c','Č':'C','č':'c','Ď':'D','ď':'d','Đ':'D','đ':'d','Ē':'E','ē':'e','Ĕ':'E','ĕ':'e','Ė':'E','ė':'e','Ę':'E','ę':'e','Ě':'E','ě':'e','Ĝ':'G','ĝ':'g','Ğ':'G','ğ':'g','Ġ':'G','ġ':'g','Ģ':'G','ģ':'g','Ĥ':'H','ĥ':'h','Ħ':'H','ħ':'h','Ĩ':'I','ĩ':'i','Ī':'I','ī':'i','Ĭ':'I','ĭ':'i','Į':'I','į':'i','İ':'I','ı':'i','Ĳ':'IJ','ĳ':'ij','Ĵ':'J','ĵ':'j','Ķ':'K','ķ':'k','Ĺ':'L','ĺ':'l','Ļ':'L','ļ':'l','Ľ':'L','ľ':'l','Ŀ':'L','ŀ':'l','Ł':'L','ł':'l','Ń':'N','ń':'n','Ņ':'N','ņ':'n','Ň':'N','ň':'n','ŉ':'n','Ō':'O','ō':'o','Ŏ':'O','ŏ':'o','Ő':'O','ő':'o','Œ':'OE','œ':'oe','Ŕ':'R','ŕ':'r','Ŗ':'R','ŗ':'r','Ř':'R','ř':'r','Ś':'S','ś':'s','Ŝ':'S','ŝ':'s','Ş':'S','ş':'s','Š':'S','š':'s','Ţ':'T','ţ':'t','Ť':'T','ť':'t','Ŧ':'T','ŧ':'t','Ũ':'U','ũ':'u','Ū':'U','ū':'u','Ŭ':'U','ŭ':'u','Ů':'U','ů':'u','Ű':'U','ű':'u','Ų':'U','ų':'u','Ŵ':'W','ŵ':'w','Ŷ':'Y','ŷ':'y','Ÿ':'Y','Ź':'Z','ź':'z','Ż':'Z','ż':'z','Ž':'Z','ž':'z','ſ':'s','ƒ':'f','Ơ':'O','ơ':'o','Ư':'U','ư':'u','Ǎ':'A','ǎ':'a','Ǐ':'I','ǐ':'i','Ǒ':'O','ǒ':'o','Ǔ':'U','ǔ':'u','Ǖ':'U','ǖ':'u','Ǘ':'U','ǘ':'u','Ǚ':'U','ǚ':'u','Ǜ':'U','ǜ':'u','Ǻ':'A','ǻ':'a','Ǽ':'AE','ǽ':'ae','Ǿ':'O','ǿ':'o'};
    var res='';
     for (var i=0;i<str.length;i++){c=str.charAt(i);res+=map[c]||c;}return res; 
}


function validarEjercio1(){

    var correct=['radiacion', 'conduccion', 'conveccion','conduccion', 'conduccion', 'radiacion','radiacion', 'conveccion'];
    var $i=0;
    var errorsForm=0; 

 $("#form1 input[type=text]").each(function() {
      val = removeAccent(this.value.toLowerCase());

      if (val == correct[$i]){
         this.style.backgroundColor = "#C5EBC5";
      }
      else{
         this.style.backgroundColor = "#F2B5AE";
         this.value= '';
         errorsForm ++;
      }
      $i++;
 });

 if(errorsForm>0) {
     sg.sound('error');
 }
 else{
     sg.sound('success-low');
 } 

}

// imgPopUP  Carlos
function imgPopUp(idImg){
    var imgTag= $('#'+idImg);
    var popUpImg =  $('#popUpImg');
    var imgContainer = $('#imgContainer');
    var width, height, aspectRatio;
    var stageWidth= $('#stage').width();
    var stageHeight= $('#stage').height();
    var PADDING_POPUP = 20;
    var PADDING_IMG = 40;

    imgContainer.attr("src",imgTag.attr('srcBig')).load(function(){
        width = this.width;
        height = this.height;
        aspectRatio = width/height;

        if(width >= height){ 
            // console.log('escalado a width');

            if ((width + PADDING_POPUP + PADDING_IMG) > stageWidth){

                //console.log('Wont Fit');
                var newImgWidth = stageWidth - (PADDING_POPUP+PADDING_IMG);
                var newImgHeight= (newImgWidth/aspectRatio);
                var newPopUpWidth= stageWidth - PADDING_POPUP;
                var newPopUpHeight= (newPopUpWidth/aspectRatio);

                var popPosLeft = (stageWidth - newPopUpWidth)/2;
                var popPosTop = (stageHeight - newPopUpHeight)/2;

                imgContainer.width(newImgWidth);
                imgContainer.height(newImgHeight);

                popUpImg.width(newPopUpWidth);
                popUpImg.height(newPopUpHeight);
                popUpImg.css({ "left": popPosLeft, "top": popPosTop});
            }
            else {
                //console.log('Fit');
                var newPopUpWidth= width + PADDING_POPUP + PADDING_IMG ;
                var newPopUpHeight= newPopUpWidth/aspectRatio;
                // console.log('nw'+newPopUpWidth);
                // console.log('nh'+newPopUpHeight);

                var popPosLeft = (stageWidth - newPopUpWidth)/2;
                var popPosTop = (stageHeight - newPopUpHeight)/2;

                //console.log(stageWidth);
                //console.log("sp "+(stageWidth-newPopUpWidth));

                popUpImg.width(newPopUpWidth);
                popUpImg.height(newPopUpHeight);
                popUpImg.css({ "left": popPosLeft, "top": popPosTop});
            }
        }
        else{ 
            // console.log('escalado a height');
            if ((height + PADDING_POPUP + PADDING_IMG) > stageHeight){

                var newImgHeight = stageHeight - (PADDING_POPUP+PADDING_IMG);
                var newImgWidth= (newImgHeight/aspectRatio);
                var newPopUpHeight= stageHeight - PADDING_POPUP;
                var newPopUpWidth= (newPopUpHeight/aspectRatio);

                var popPosTop = (stageHeight - newPopUpHeight)/2;
                var popPosLeft = (stageWidth - newPopUpWidth)/2;

                imgContainer.width(newImgWidth);
                imgContainer.height(newImgHeight);

                popUpImg.width(newPopUpWidth);
                popUpImg.height(newPopUpHeight);
                popUpImg.css({ "left": popPosLeft, "top": popPosTop});
            }
            else {
                var newPopUpHeight= height + PADDING_POPUP + PADDING_IMG ;
                var newPopUpWidth= newPopUpHeight/aspectRatio;

                var popPosTop = (stageHeight - newPopUpHeight)/2;
                var popPosLeft = (stageWidth - newPopUpWidth)/2;

                // console.log(stageWidth);
                // console.log("sp "+(stageWidth-newPopUpWidth));

                popUpImg.height(newPopUpHeight);
                popUpImg.width(newPopUpWidth);
                popUpImg.css({ "left": popPosLeft, "top": popPosTop});
                //imgContainer.attr({"width": newImgWidth , "height": (newImgWidth/aspectRatio)});
            }
        }
    });

    popUpImg.fadeIn();

} // Fin function imgPopUp Carlos U
