// JavaScript Document

//var designId;

/*function emailPop (){
	if (!Get_Cookie("BrokenArrowWear.Com")){
	//if(get_cookie("BrokenArrowWear.Com") == "BrokenArrowWear.Com"){
	//Logic to update database with new guid and existing cookie value
	window.location = "http://www.brokenarrowwear.com/designer/shirt-builder.aspx?design_id="+designId;
	} else {

	$.blockUI({ message: $('#emailPop') });
	
	}
}*/


/*function colorPicker(fileName, getImageId){
	alert(fileName + getImageId);
	alert(designId);
	$.blockUI({ message: $('aName.aspx#colorPicker') });
	}*/

function ProdUploadOpen(){
	//alert("UPLOAD OPEN");
	document.getElementById("uploadFrame").setAttribute("src", "prodUpload.aspx?design_id=" + AddressDesignId());
	
	document.getElementById("builderSwf").setAttribute("class", "invisible");
	document.getElementById("builderSwf").setAttribute("className", "invisible");
	$.blockUI({ message: $('#prodUpload') });
	//alert("artUpload.aspx?design_id=" + AddressDesignId());
}
	
function ProdUploadClose(){
//alert("UPLOAD CLOSE");
document.getElementById("builderSwf").setAttribute("class", "");
document.getElementById("builderSwf").setAttribute("className", "");


$.unblockUI();

}

	
function colorPickerClose(){
$.unblockUI();
}
	
function AddressDesignId(){
	var designId = "";
	var searchParts = location.search.substring(1).split("&");
	for (var i = 0; i < searchParts.length; i++) {
	    var parts = searchParts[i].split("=");
	    if (parts[0] == "design_id") {
	         designId = parts[1];	         
	    }
	}
	return designId;
}
	
function Redirect(id){
    if (id.toString().match('undefined') != 'undefined'){
    designId = id;
    //window.location = "http://www.brokenarrowwear.com/designer/shirt-builder.aspx?design_id="+designId;

    	
    }
    //alert("redirect" + id);
}
		    
function SetFilenames(fileName, id){
	document.getElementById("hdnPreviews").value = fileName;
	SubmitColorData(id);
	//alert("setFilenames" + id);
	if (id.toString().match('undefined') != 'undefined'){
    //window.location = "http://www.brokenarrowwear.com/designer/shirt-builder.aspx?design_id="+id;

    	
    }
}		    

function  GetFilenames(){
	return document.getElementById("hdnPreviews").value.replace(/\"/g, "\'");	
}

function  GetTotalColorData(){
	return document.getElementById("totalColorData").value.replace(/#/g, "");
}

		    
var reqObj;
function SubmitColorData(designID)
{
   
  // window.location = "http://www.brokenarrowwear.com/builder-test/ColorHandler.ashx?colorData="+GetTotalColorData()+"&designID="+ designID + "&files=" + GetFilenames();
 
   if (window.XMLHttpRequest) {
        reqObj = new XMLHttpRequest; 
    }
    else {
        reqObj = new ActiveXObject("Microsoft.XMLHttpRequest"); 
    }
    reqObj.onreadystatechange = CheckRequest;
    reqObj.open("GET","http://www.brokenarrowwear.com/builder-test/ColorHandler.ashx?colorData="+GetTotalColorData()+"&designID="+ designID + "&files=" + GetFilenames(),true);    
    //reqObj.open("GET","http://www.brokenarrowwear.com/builder-test/ColorHandler.ashx?colorData=QAutumn Leaves.jpg:Florescent Yellow::0|&designID=undefined&files=<previews>  <preview id='0' name='Front'>    <image url='http://www.brokenarrowwear.com/TShirtHandlers/PDF/d1b1c575-1cd5-4ed2-800d-c4deeaa6d95b/QAutumn Leaves.jpg' fileName='QAutumn Leaves.jpg' type='Custom' colorName='Black' colorHex='-1' flip='FlipNone' x='198.5' y='217.5' width='201.55' height='155.4' scale='0.18021754909571402' angle='0'/>  </preview></previews>",true);
    reqObj.send(null);   
    
}

function CheckRequest()
{
    if (reqObj.readyState == 4)
    {
        //set progress if needed
    }
}
            
            
function filePosition(fileName, position){
	//alert(fileName + position);
}          
            
function colorPicker(fileName){
	SetFilename(fileName);
	//alert(fileName);
 	$.blockUI({ message: $('#colorPicker') });
 	//$.getElementById("builderSwf").block({ message: $('#colorPicker') });
	//$('#builderCol').block({ message: $('#colorPicker') });
	document.getElementById("builderSwf").setAttribute("class", "invisible");
	document.getElementById("builderSwf").setAttribute("className", "invisible");
 	

}

/*function redirectStatus(){
			var emailAddress = document.getElementById("txtEmailAddr").value;
			if (emailaddrcheck(emailAddress)){
			//document.getElementById("ct102").style.visibility = "visible";
		    $.unblockUI();
		    
		    //alert(emailAddress);
		    createCookie("BrokenArrowWear.com",emailAddress,365);
		    //save input value to cookie
		    window.location = "http://www.brokenarrowwear.com/designer/shirt-builder.aspx?design_id="+designId;
		    
		    } else {
		    var ct102 = document.getElementById("ct102");
		    }
		   }*/