// PKL JS CODE for order_form.inc.php

function pkl_add2Cart(){
		var Kit1Pc 						=	document.getElementById('1pcRadioBut');
		var Kit8Pc 						=	document.getElementById('8pcRadioBut');
		var Kit3Pc 						=	document.getElementById('hidden3pc');					
		var FunArt  						=	document.getElementById('fun-artHidden');
		var calcedPrice 	= trim(document.getElementById('DisplayPrice').value) ;
		var qty_index		=  document.getElementById("qty").options.selectedIndex;
		var qty					=  trim(document.getElementById("qty").options[qty_index].value) ;

		var product			=  trim(document.getElementById('cart-descr').value);
		var comment			=  trim(document.getElementById('CommentsRequests').value);
		var postVar			= '&price='+calcedPrice+'&qty='+qty+'&product='+product+'{br}{br}  '+comment;
		var postVar			= '&price='+calcedPrice+'&product='+product+'{br}{br}  '+comment;		
		var oneColor 		=	document.getElementById('1ColorRadioBut');
		var twoColor  		=	document.getElementById('2ColorRadioBut');
		// include the hidden fields
			var returnLink	=  trim(document.getElementById("return").value) ; ///continueShopping link
			//var units			=  trim(document.getElementById("units").value) ;
				
			
	 // wieght of item
	 		if( Kit1Pc != null && Kit1Pc.checked ) {
	 					var unitWt= document.getElementById("wt1pc").value;
	 				}
	 				
	 		if( Kit3Pc != null  /* not a radio button. Its a hidden input */ ) {
	 					var unitWt = document.getElementById("wt3pc").value;
	 				}
	 		
	 		if( Kit8Pc != null && Kit8Pc.checked ) {
	 					var unitWt = document.getElementById("wt8pc").value;
	 				}
	 		if( FunArt != null ) {
	 					var unitWt = document.getElementById("wtFunArt").value;
	 				}
	
		var postVar2	= '&units='+unitWt+'&return='+ returnLink ;
	
	
	
		if(document.getElementById("swatch_1")  ) {
			var swatch1_index		= document.getElementById("swatch_1").options.selectedIndex;
				  swatch1	= document.getElementById("swatch_1").options[swatch1_index].id ;
				  color_1	= document.getElementById("swatch_1").options[swatch1_index].text ; 
				}
		
		if(document.getElementById("swatch_2")  ) {
			var swatch2_index		= document.getElementById("swatch_2").options.selectedIndex;
				  swatch2		= document.getElementById("swatch_2").options[swatch2_index].id ;
				  color_2		= document.getElementById("swatch_2").options[swatch2_index].text ;
				}
		
		if(document.getElementById("specialEffects")  ) {
			var effects_index = document.getElementById("specialEffects").options.selectedIndex;
				  effect_id	   =document.getElementById("specialEffects").options[effects_index].id;
				  effect    = document.getElementById("specialEffects").options[effects_index].text;
				}
		
				if( twoColor && twoColor.checked ){				
						if( swatch1 == '' ){
										alert( "Please choose color 1." );
										return;
									}
						if( swatch2 == '' ){
										alert( "Please choose color 2." );
										return;
									}
				}// if( twoColor.checked )
				
				if(  oneColor && oneColor.checked ){				
						if( swatch1 == '' ){
										alert( "Please choose a color." );
										return;
									}
				}// if( twoColor.checked )
		
		location.href = "http://ww4.aitsafe.com/cf/add.cfm?userid=64275593"+postVar+postVar2 ;
		
}//function pkl_add2Cart()

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function orderform_ui(docRoot) {
		var startDescr				= document.getElementById('start-descr').value;
		var prodDescr				= document.getElementById('cart-descr').value;
		var trColor2 					= document.getElementById('chooseColor2');
		var trColor1 					= document.getElementById('chooseColor1');
		var trEffect					= document.getElementById('chooseEffect');
		var effectsRadio				= document.getElementById('effectsRadioBut');
		var selectOptions 			= document.getElementById('prod_options');
		var Kit1Pc 						=	document.getElementById('1pcRadioBut');
		var Kit3Pc 						=	document.getElementById('hidden3pc');
		var FunArt  					=	document.getElementById('fun-artHidden');
		var Kit8Pc  					=	document.getElementById('8pcRadioBut');
		
		if(document.getElementById('1ColorRadioBut')){
					var oneColor 				=	document.getElementById('1ColorRadioBut');  }
		if(document.getElementById('2ColorRadioBut')){
					var twoColor  				=	document.getElementById('2ColorRadioBut');  }
		var material					= 'none';
		var price_name				= 'none' ;
		var kit_column				= 'none';
		var swatch1					= '';  // clear swatch before checking to see what it is
		var swatch2					= ''; // clear swatch before checking to see what it is
		var addToCart				= false;
		
		
		if (document.getElementById('CommentsRequests') ){	
			var comments	= document.getElementById('CommentsRequests').value;
			if ( comments != '' ){	
						var custComment = '{b}Customer Comments:{/b}'+'{br}'+comments;
						}else{
						var custComment = '' ;
						}// if else
			}//if
		
		if(document.getElementById("swatch_1")) {
		   if( document.getElementById("swatch_1").options.selectedIndex ){
					var swatch1_index	= document.getElementById("swatch_1").options.selectedIndex;
					//alert(  swatch1_index  );
				}else{
					var swatch1_index	=  0  ;
					//alert( "else" + swatch1_index  );
				}
				  swatch1		= document.getElementById("swatch_1").options[swatch1_index].id ;
				  color_1		= document.getElementById("swatch_1").options[swatch1_index].text ;
				  color_src   = document.getElementById("swatch_1").options[swatch1_index].value ;
				  document.getElementById("swatch1").src = color_src ;
		   }
		if(document.getElementById("swatch_2")) {
			var swatch2_index		= document.getElementById("swatch_2").options.selectedIndex;
				  swatch2		= document.getElementById("swatch_2").options[swatch2_index].id ;
				  color_2		= document.getElementById("swatch_2").options[swatch2_index].text ;
				   color_src   = document.getElementById("swatch_2").options[swatch2_index].value ;
				  document.getElementById("swatch2").src = color_src ;
		   }
		if(document.getElementById("specialEffects")  ) {
			var effects_index = document.getElementById("specialEffects").options.selectedIndex;
				  effect_id	   =document.getElementById("specialEffects").options[effects_index].id;
				  effect    = document.getElementById("specialEffects").options[effects_index].text;
				 
				}
		
		// Turn off second Color if "One Color" Radio is selected
		if(oneColor && oneColor.checked  && oneColor.style.display != 'none' ) {
			trColor2.style.display = "none";
			trColor1.style.display = "";
			if(trEffect){  trEffect.style.display = "none"; }
			//colorImgUpdater( effectSelect , 'swatch1');
		}
		if(twoColor && twoColor.checked ) {
			trColor2.style.display = "";
			trColor1.style.display = "";
			if(trEffect){ trEffect.style.display = "none"; }
		}
		if(effectsRadio && effectsRadio.checked ) {
			trColor1.style.display  = "none";
			trColor2.style.display  = "none";
			if(trEffect){ trEffect.style.display = ""; }
			var effectSelect = document.getElementById( 'specialEffects');
			colorImgUpdater( effectSelect , 'effect-swatch');
		}
		
// ////////////////////////   3 pc  KIT  ////////////////////////////////////////////////
		if( Kit3Pc != null ) {
				var pc = "3 pc";
						if( oneColor.checked ){				
							swatch2_index = 0 ;
							material		=	"material1="+swatch1;
							kit_column = 	'ct.3pc_kit_1color';
							price_name	=  'Universal';//<--3pc_sporty
							var materials ="{b}1 color:{/b} ";
							var chosenMaterials =  materials+' '+color_1+'  ';	
						}
						
						if( twoColor.checked  ){	
							material		=	"material1="+swatch1+"&material2="+swatch2;
							kit_column = 	'ct.3pc_kit_2color';
							price_name	=  'Universal';//<--3pc_sporty
							var materials ="{b}2 colors:{/b} ";
							var chosenMaterials =  materials+' '+color_1+" and "+color_2+'  ';
						}
		}
// ////////////////////////   1 pc  KIT  ////////////////////////////////////////////////		
		 if( Kit1Pc != null && Kit1Pc.checked ) {
			var pc = "1 pc";
			
						if( oneColor.checked  ){	
							swatch2_index = 0 ;
							material		=	"material1="+swatch1;
							kit_column 	= 	'ct.1pc_kit_1color';
							price_name	=  '1pc_standard';
							var materials ="{b}1 color:{/b} ";
							var chosenMaterials =  materials+' '+color_1+'  ';	
						}
						if( twoColor.checked ){
							material		=	"material1="+swatch1+"&material2="+swatch2;
							kit_column 	= 	'ct.1pc_kit_2color';
							price_name	=  '1pc_standard';
							var materials ="{b}2 colors:{/b} ";
							var chosenMaterials =  materials+' '+color_1+" and "+color_2+'  ';
		                 }
		                if( effectsRadio && effectsRadio.checked) {
		                	swatch1_index = 0 ;
		                	swatch2_index = 0 ;
							material		=	"material1="+effect_id;
							kit_column 	= 	'ct.1pc_special_effect';// <---- in color types table
							price_name	=  '1pc_unlimited';//<---- unlimited colors / full color
							var materials ="{b}Special Effect:{/b} ";
							var chosenMaterials =  materials+' '+effect+'  ';	
		                }
		}
// ////////////////////////   8 pc  KIT  ////////////////////////////////////////////////
		if( Kit8Pc != null && Kit8Pc.checked ) {
				
				var pc = "8 pc";
						if( oneColor.checked ){				
							swatch2_index = 0 ;
							material		=	"material1="+swatch1;
							kit_column = 	'ct.8pc_kit_1color';
							price_name	=  '8pc_standard';
							var materials ="{b}1 color:{/b} ";
							var chosenMaterials =  materials+' '+color_1+'  ';	
						}
						
						if( twoColor.checked  ){	
							material		=	"material1="+swatch1+"&material2="+swatch2;
							kit_column = 	'ct.8pc_kit_2color';
							price_name	=  '8pc_standard';		
							var materials ="{b}2 colors:{/b} ";
							var chosenMaterials =  materials+' '+color_1+" and "+color_2+'  ';
						}
						
						if( effectsRadio && effectsRadio.checked) {
		                	swatch1_index = 0 ;
		                	swatch2_index = 0 ;
							material		=	"material1="+effect_id;
							kit_column 	= 	'ct.8pc_special_effect';// <---- in color types table
							price_name	=  '8pc_unlimited';//<---- unlimited colors / full color
							var materials ="{b}Special Effect:{/b} ";
							var chosenMaterials =  materials+' '+effect+'  ';	
		                }
						
						
		}
// ////////////////////////   Fun Art  KIT  ////////////////////////////////////////////////
		if( FunArt != null ) {
				var pc = "Fun Art";
			if(document.getElementById('1ColorRadioBut')){
									if( oneColor && oneColor.checked ){				
										swatch2_index = 0 ;
										material		=	"material1="+swatch1;
										kit_column = 	'ct.fun_graphic_1color';
										price_name	=  'Solo Designs (FUN)';//<--3pc_sporty
										var materials ="{b}1 color:{/b} ";
										var chosenMaterials =  materials+' '+color_1+'  ';	
									}// if
					}// if
					
			if(document.getElementById('2ColorRadioBut')){			
									if( twoColor   && twoColor.checked  ){	
										material		=	"material1="+swatch1+"&material2="+swatch2;
										kit_column = 	'ct.fun_graphic_2color';
										price_name	=  'Solo Designs (FUN)';//<--3pc_sporty
										var materials ="{b}2 colors:{/b} ";
										var chosenMaterials =  materials+' '+color_1+" and "+color_2+'  ';
									}//if
				}// if
		}		
		if(chosenMaterials){
				document.getElementById('cart-descr').value = '(gcg) {b}'+startDescr+'{/b}{br}'+'{b}Options:{/b} '+pc+' {br}'+chosenMaterials.replace(/[\(\)\.\-\s,]/g, " "); //+'{br}{br}  '+custComment;	
		}else{
				document.getElementById('cart-descr').value = '(gcg) {b}'+startDescr+'{/b}{br}'+'{b}Options:{/b} '+pc+' {br}'; //+'{br}{br}  '+custComment;	
		}
		
		if( material != 'none' ){
		
				var postValues 	= material+"&price_name="+price_name+"&kit="+kit_column ;
				//alert(postValues);
				var processFile   = docRoot+'/ajax/decalKitPrice.php';
				var div_id				= 'pkl-price-total';
				pkl_AjaxCall_POST(processFile, postValues, 'DisplayPrice', docRoot);
		}		

}//  function orderform_ui()

function colorImgUpdater(swatchSelect, img_id ) {
// selected color
var index 		= swatchSelect.options.selectedIndex;
var colorSrc 	= swatchSelect.options[index].value;
//alert( "swatch id="+img_id+"\n"+"SRC="+colorSrc );
var swatch    	= document.getElementById(img_id);
swatch.src 	= colorSrc;
}


//+++++++++++++++++++++++++++++++++++++++++++++
//      ZEMELRECK FUNCTIONS
//+++++++++++++++++++++++++++++++++++++++++++++ 
function pkl_AjaxCall_POST(processFile, postValues, div_id, docRoot) {
//alert('doc root into zemelrek ='+docRoot);

 	var XMLHttpRequestObject = false;
  	if (window.XMLHttpRequest) {
				XMLHttpRequestObject = new XMLHttpRequest();
  			} else if (window.ActiveXObject) {
				XMLHttpRequestObject = new 
				ActiveXObject("Microsoft.XMLHTTP");
  			}//if-else
  	if(XMLHttpRequestObject) {
			XMLHttpRequestObject.open("POST", processFile); 
    		XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  
			XMLHttpRequestObject.onreadystatechange = function() { 
								
	  							if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { 
	  							   //TEST
	  							   //document.getElementById(div_id).innerHTML ="";
		  							document.getElementById(div_id).value = trim(XMLHttpRequestObject.responseText);
		  							
	  							}else{

	  			//alert( docRoot+'/ajax/progressBarBlueShort.gif'     );
	  	//document.getElementById(div_id).value =  'Calculating...';

	  							}
						} //function
			XMLHttpRequestObject.send(postValues); 
  		}// if(XMLHttpRequestObject)
  }
  

