var gbimgsrc;   // global used for image src selected.
var imgapparel;  // variable to be used for apparel to merge
var namecolor;   // color for apparel to merge
var AppLeft=0;
var AppTop=0;
var ImGallery="undefined";
var DuiX;
var DuiY;
var sizeH;
var sizeW;
var sizeH2;
var sizeW2;

var txt_color="black";  //variables to pass for the text input
var txt_font;
var txt_wg;
var txt_x;
var txt_y;
var txt_text;
var txt_size;


var uploadimg;
var upload_size="50";
var uploadx;
var uploady;

//ihanan if na save naba or wla before mo email....
var tag_ok_email = "0";






function send()
{
    var name    =	$('#d_name').val();
    var email   =	$('#d_email').val();
    var phone   =	$('#d_phone').val();
    //var color   =	$('#d_color').val();
    var text    =	$('#d_text').val();
    var image   =	$('#d_image').val();

    if( name.length == 0){
	alert('Please insert your name!');
	return false;
    }

    if( email.length == 0){
	alert('Please insert your email!');
	return false;
    }

    if( phone.length == 0){
	alert('Please insert your phone!');
	return false;
    }

    if ($('#remarks').attr('checked')) {
	var remarks   =	$('#d_remarks_value').val();
    }

    alert('Thank you!');
}

function reset()
{
    top.location = $(location).attr('href');
}






function viewdesigner(clicked_name) // this is working adding selected images from gallery
{
			 if (clicked_name == null ){
				
				ImGallery = "undefined";
			 
			 }
			 else
			 {
				 var image = clicked_name;
				 
				
			   if (sizeW > 1000 || sizeW < 5 || sizeH >1000 || sizeH < 5){
						   alert('  Invalid Range.\nEnter between 10-1000.');
			   }else{

						if (image != 'd_imgsize' || image != 'd_imgsize2' || image != 'resizewidth' || image != 'resizeheight'){
					   gbimgsrc = image;
						
					 
					  } else {
							   var im = 'images/' + gbimgsrc;
							   getImgSize(im);
						 
						 }
					   
					   ImGallery = gbimgsrc; 
						   

					   $("#imageselect").empty('<div><img id="im_Dui" src="images/' + gbimgsrc + '" height="' + sizeH +'" width="'+ sizeW +' "/><div>');
					   $("#imageselect").append('<div><img id="im_Dui" src="images/' + gbimgsrc + '" height="' + sizeH +'" width="'+ sizeW +' "/></div');

						document.getElementById('d_imgsize').value = $("#im_Dui").height();          // change the value of the inputbox
						document.getElementById('d_imgsize2').value = $("#im_Dui").width();

						newheight = $("#im_Dui").height()/10;
						newwidth = $("#im_Dui").width()/10;

						newheight = newheight+"px";
						newwidth = newwidth+"px";
						
						document.getElementById('resizeheight').style.left = newheight; // change the slider location
						document.getElementById('resizewidth').style.left = newwidth;
					 
					  
				 }
			 }
 }



function designersize()         // this is working image sizing
{
 
     sizeH  = $('#d_imgsize').val(); 
     sizeW  = $('#d_imgsize2').val(); 
   
       
     posLefth = sizeH/10 ;
     posLefth = posLefth+"px";
     posLeftw = sizeW/10 ;
     posLeftw = posLeftw+"px";

   if ( sizeW.length > 0){
      if (sizeW > 1000 || sizeW < 5 || sizeH > 1000 || sizeH < 5){
               alert('  Invalid Range.\nEnter between 10-1000.');
   }else{
          document.getElementById('resizeheight').style.left = posLefth;   // for slider position
          document.getElementById('resizewidth').style.left = posLeftw;
         
          viewdesigner(gbimgsrc);
        }
   }
}


function viewdesigner2()   // working on adding/viewing apparel!
{
  
    var image  = $('#d_image3').val();
    var color  = $('#d_apparelcolor').val();
    var colorrgb = 'rgb(255,255,255)';
    
    if (color == '#FFFFFF'){
    	colorrgb = 'rgb(255,255,255)';
    }
    if (color == '#000000'){
    	colorrgb = 'rgb(0,0,0)';
    }
    if (color == '#D3D3D3'){
    	colorrgb = 'rgb(205,192,176)';
    }
    if (color == '#87CEEB'){
    	colorrgb = 'rgb(30,144,225)';
    }
    if (color == '#b22222'){
    	colorrgb = 'rgb(153,51,51)';
    }
    if (color == '#104E8B'){
    	colorrgb = 'rgb(25,25,112)';
    }
    
    if (color == '#006400'){
    	colorrgb = 'rgb(0,100,0)';
    }
    if (color == '#008000'){
    	colorrgb = 'rgb(39,139,34)';
    }
    if (color == '#FFFF00'){
    	colorrgb = 'rgb(255,215,0)';
    }
    
    
    

    imgapparel = image; 

    if( image.length > 0){
        namecolor = color;    // initialize color for apparel to merge

        $("#imagedesigner").empty('<div style="background-color:'+ colorrgb +';"><img id="media" src="embroidery/images/' + image + '.png" width="400" /></div>');   
	$("#imagedesigner").append('<div style="background-color:'+ colorrgb +';"><img id="media" src="embroidery/images/' + image + '.png" width="400" /></div>');
      
    }
   
}



function preview_textdesigner()         // working adding text , font size and font color
{
    var color   = $('#d_fcolor').val();
    var text    = $('#d_text').val();
    var width   = $('#d_textsize1').val();
    var style   = $('#d_style').val();
    var face    = $('#d_face').val();
    
         
    if( text.length > 0){
             if ( style == 'oblique'){
            	var weight = 'bolder'; 
               style = 'italic'; 
         }
	   if ( style == 'bolder'){
           
               var weight = 'bolder'; 
         }
            text = text.replace('\r', "<br/>");
         
               txt_color = color;
               txt_font = face;
               //need to delete the _ from the font, there is a _ because the ttf file should not have a black space, need when creating an image
            if (face == 'arial'){ 
    			face = 'arial';
    			var face2 = 'arial';
    			var weight = 'normal'; 
               		style = 'normal'; 
    			
    		}
            
            	if (face == 'arial_black'){ 
    			face = 'arial black';
    			var face2 = 'arial black';
    			var weight = 'normal'; 
               		style = 'normal'; 
    			
    		}
    		
    		
    		
            	if (face == 'algerian'){ 
    			face = 'algerian';
    			var face2 = 'algerian';
    			var weight = 'normal'; 
               		style = 'normal'; 
    			
    		}
    		
    		if (face == 'brush_script_mt'){ 
    			face = 'brush script mt';
    			var face2 = 'brush script mt';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		if (face == 'britannic_bold'){ 
    			face = 'britannic bold';
    			var face2 = 'britannic bold';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		if (face == 'century_gothic'){ 
    			face = 'century gothic';
    			var face2 = 'century gothic';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		if (face == 'colonna_mt'){ 
    			face = 'colonna mt';
    			var face2 = 'colonna mt';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		if (face == 'comic_sans_ms'){ 
    			face = 'comic sans ms';
    			var face2 = 'comic sans ms';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		
    		
    		if (face == 'courier'){ 
    			face = 'courier';
    			var face2 = 'courier';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		
    		if (face == 'courier_new'){ 
    			face = 'courier new';
    			var face2 = 'courier new';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		
    		
    		if (face == 'impact'){ 
    			face = 'impact';
    			var face2 = 'impact';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		
    		
    		if (face == 'lucida_console'){ 
    			face = 'lucida console';
    			var face2 = 'lucida console';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		if (face == 'matura_mt_script_capitals'){ 
    			face = 'matura mt script capitals';
    			var face2 = 'matura mt script capitals';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		if (face == 'tempus_sans_itc'){ 
    			face = 'tempus sans itc';
    			var face2 = 'tempus sans itc';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		
    		if (face == 'tahoma'){ 
    			face = 'tahoma';
    			var face2 = 'tahoma';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		
    		
    		if (face == 'times_new_roman'){ 
    			face = 'times new roman';
    			var face2 = 'times new roman';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		
    		if (face == 'verdana'){ 
    			face = 'verdana';
    			var face2 = 'verdana';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
    		
    		if (face == 'wide_latin'){ 
    			face ='wide latin';
    			var face2 ='wide latin';
    			var weight = 'normal'; 
               		style = 'normal';
    		}
			
			
			
			//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
			if (face == 'arial_bold'){ 
				
				var face2 = 'arial';
				var weight = 'bolder'; 
               			style = 'normal';    		
			}
			if (face == 'arial_bold_italic'){ 
				
				var face2 = 'arial'; 
				var weight = 'bolder'; 
               			style = 'italic';      		
			}
			if (face == 'arial_italic'){ 
				
				var face2 = 'arial';
				var weight = 'normal'; 
               			style = 'italic';     		
			}

			if (face == 'century_gothic_bold'){ 
				
				face2 = 'century gothic';
				var weight = 'bolder'; 
               			style = 'normal';       		
			}
			if (face == 'century_gothic_bold_italic'){ 
				face2 = 'century gothic';
				var weight = 'bolder'; 
               			style = 'italic';       		
			}
			if (face == 'century_gothic_italic'){ 
				face2 = 'century gothic';
				var weight = 'normal'; 
               			style = 'italic';     		
			}


			if (face == 'comic_sans_ms_bold'){ 
				face2 = 'comic sans ms';
				var weight = 'bolder'; 
               			style = 'normal';    		
			}
			if (face == 'courier_bold'){ 
				face2 = 'courier'; 
				var weight = 'bolder'; 
               			style = 'normal';   		
			}
			if (face == 'courier_italic'){ 
				face2 = 'courier'; 
				var weight = 'normal'; 
               			style = 'italic';  		
			}

			if (face == 'courier_bold_italic'){ 
				face2 ='courier'; 
				var weight = 'bolder'; 	
				style = 'italic';
			}
			if (face == 'tahoma_bold'){ 
				face2 = 'tahoma';  
				var weight = 'bolder'; 
               			style = 'normal'; 
			}
			if (face == 'times_new_roman_bold'){ 
				face2 = 'times new roman'; 
				var weight = 'bolder'; 
               			style = 'normal'; 	
			}
			if (face == 'times_new_roman_italic'){ 
				face2 = 'times new roman';
				var weight = 'normal'; 
               			style = 'italic'; 
			}
			if (face == 'times_new_roman_bold_italic'){ 
				face2 = 'times new roman';
				var weight = 'bolder'; 	
				style = 'italic';
			}


               
               
               
               txt_wg = style;
               txt_text = text;
               txt_size = width+"px";
            
            
            
            
            
            var colorrgb = 'rgb(255,255,255)';
    
   if (color == 'white'){
    	colorrgb = 'rgb(255,255,255)';
    }
    if (color == 'black'){
    	colorrgb = 'rgb(0,0,0)';
    }
    if (color == 'gray'){
    	colorrgb = 'rgb(205,192,176)';
    }
    if (color == 'blue'){
    	colorrgb = 'rgb(30,144,225)';
    }
    if (color == 'red'){
    	colorrgb = 'rgb(153,51,51)';
    }
    if (color == 'darkblue'){
    	colorrgb = 'rgb(25,25,112)';
    }
    
    if (color == 'darkgreen'){
    	colorrgb = 'rgb(0,100,0)';
    }
    if (color == 'green'){
    	colorrgb = 'rgb(39,139,34)';
    }
    if (color == 'yellow'){
    	colorrgb = 'rgb(255,215,0)';
    }
	
	
	$("#text").empty('<p style="font-weight:' + weight + '; font-style:'+ style +'; font-family:'+ face2 +'; font-size:'+ txt_size +'; font-color:' + colorrgb +'; top:0px; left:0px; padding: 0px; margin: 0px; position:relative; padding:0px; margin:0px;">'+ text +'</p>');

	$("#text").append('<p style="font-weight:' + weight + '; font-style:'+ style +'; font-family:'+ face2 +'; font-size:'+ txt_size +'; color:' + colorrgb +'; top:0px; left:0px; padding: 0px; margin: 0px; position:relative; padding:0px; margin:0px;">'+ text +'</p>');
	
 	var minus = width * .27;
	//txt_size = parseInt(width) - parseInt(12);
	txt_size = parseInt(width) - minus;
    }

   
}

function previewDesign(Xpo){
  // Window3.close();
   var Result = imgapparel;    //Stores the Selected Apparel/Materialfor merging
   var ColorApp;
   
   
             
                 if (namecolor == '#FFFFFF'){
                       
                     ColorApp = 'white';           //assign color name
                    
                  }
                 if (namecolor == '#000000'){
                     ColorApp = 'black';
                     
                  }
                 if (namecolor == '#87CEEB'){
                     ColorApp = 'blue';
                      
                  }
                 if (namecolor == '#104E8B'){
                     ColorApp = 'navyblue';
                      
                  }
                 if (namecolor == '#b22222'){
                     ColorApp = 'red';
                    
                  }
                 if (namecolor == '#D3D3D3'){
                     ColorApp = 'grey';
                     
                  }
                 if (namecolor == '#008000'){
                     ColorApp = 'green';
                     
                  }
                 if (namecolor == '#006400'){
                     ColorApp = 'darkgreen';
                     
                  }
                 if (namecolor == '#FFFF00'){
                     ColorApp = 'yellow';
                     
                  }
                
	tag_ok_email = '1';
  // location.href="./embroidery/viewdesign.php?Result=" + Result "color="+ ColorApp; recalls page.... is this equivalent to a GET?
// popupWindow = window.open('url','windowName','options')
     popupWindow = window.open("./embroidery/viewdesign.php?Result=" + Result + "&ColorApp=" + ColorApp + "&AppLeft="+ AppLeft+"&AppTop=" +AppTop + "&ImGallery=" + ImGallery + "&DuiX=" + DuiX + "&DuiY=" + DuiY +"&sizeW="+sizeW+"&sizeH="+sizeH+"&txt_text="+txt_text+"&Txtfont="+txt_font+"&txt_x="+txt_x+"&txt_y="+txt_y+"&txtcolor="+txt_color+"&txtsize="+txt_size+"&uploadimg="+uploadimg+"&uploady="+uploady+"&uploadx="+uploadx+"&upload_size="+upload_size,"Window3", "width=520,height=610,scrollbars=yes" ) 
   //success
   
  
}

function GetPosX() {                       // GET  APPAREL LOCATION

  var Posleft = parseInt($("#imagedesigner").css("left"));
  var Postop = parseInt($("#imagedesigner").css("top"));

  AppLeft = parseInt(Posleft);
  AppTop = parseInt(Postop);
  
}

function GetDui() {                        //get  DUI Position

  var x = parseInt($("#imageselect").css("left"));
  var y = parseInt($("#imageselect").css("top"));
    DuiX = x;
    DuiY = y;
}


function GetTxtpos() {                     // GEXT Text Position
  var txx = parseInt($("#text").css("left"));
  var tyy = parseInt($("#text").css("top"));
  var size = parseInt($('#d_textsize1').val());
      txt_x = txx;
     txt_y = tyy + size;
   
}


function GetUplaodpos() {                     // GEXT Upload Position
  uploadx = parseInt($("#image2").css("left"));
  uploady = parseInt($("#image2").css("top"));
  
}



function chkRatio() {                      // For checking Aspect Ration.

 var chk = document.getElementById('check_ratio').checked;

            if (chk == "true") 
	{
		return 'true';
		
	} else { 	
		return 'false';
	}
}


function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
sizeH2 = newImg.height;
sizeW2 = newImg.width;
$('#d_imgsize2').val(sizeW2); 
$('#d_imgsize').val(sizeH2);

}


function startUpload(){          //WORKING Upload Custom Image
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}

function stopUpload(success){
      var result = '';
      if (success == 0){
        result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
      }
      else {
        
       result = '<span class="msg">Image successfully uploaded.<\/span><br/><br/>'; 
      
      
	
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '<label><input name="myfile" type="file" size="20" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      
	  //get the size
	 var newImg = new Image();
	 newImg.src = success;
	 sizeW2 = newImg.width;
	 $('#d_width').val(sizeW2);
	

		
	  
	  upload_size = $('#d_width').val(sizeW2); 
	 
	 
	  uploadimg = success;
	  
	  document.getElementById('f1_upload_form').style.visibility = 'visible'; 
      	 document.getElementById('image2').innerHTML = '<img src="'+success+'" width="'+upload_size+'" />';     //show in canvas
      return true;   
}



function changeUploadsize()
{
	upload_size = $('#d_width').val(); 
		
	//posLeftw = upload_size/10;
 	//posLeftw = posLeftw+"px";
	//document.getElementById('rwidth').style.left = posLefth;
	
 	$("#image2").empty('<img src="'+uploadimg+'" width=" '+upload_size+' " height=" '+upload_size+' "/>');
 	$("#image2").append('<img src="'+uploadimg+'" width=" '+upload_size+'" height=" '+upload_size+' " />');
 	
       
     
}

function quickview(imageselect){

                  document.getElementById('imageselect').style.visibility = 'hidden'; 

}



function checkinputboxes(){
	
	name = $('#d_name').val(); 
	phone = $('#d_phone').val(); 
	msg = $('#d_remarks_value').val(); 
	email = $('#d_email').val(); 
	qty = $('#d_quantity').val(); 

	
if (name==null || name=="")
  {
  alert("Please indicate your Name...");

  }

else if (phone==null || phone=="")
  {
  alert("Please indicate your Contact Number...");

  }

else if (qty==null || qty=="")
  {
  alert("Please indicate the quantity...");
  
  }
  
else if (msg==null || msg=="")
  {
  alert("Please indicate your remarks...");
  
  }
else if (email==null || email=="")
  {
  alert("Please indicate your email.");
 
  }
 else if (tag_ok_email != '1')
  {
  alert("Please save the design first...");
 
  }
else{
	window.open("./embroidery/send_email.php?name=" + name + "&phone=" +phone+ "&msg=" +msg+ "&email=" +email+ "&qty=" +qty);
}

}




