/*Created on: 4/2/2007 10:43:44 AM 
Modified on: 4/23/2007
Description: This page contains the JavaScript functions used in other Lasso files in the current folder 
*/
   
/*function to show and hide Kibiz Products*/
  function ShowProducts() {
    document.KibizForm.action='KibizPurchase.lasso?&selectedpackage=1';
	document.KibizForm.submit();
  }
  
/*function to Redirect to PlaceOrder/CreditcardInfo page after checkout*/
  function Redirect_OrdConf(value) {
    var param='&Maintenance='+ value;
	//alert("KiRedirectPurchase.lasso?save=1"+param);
	document.KibizViewCart.action='KiRedirectPurchase.lasso?save=1'+param;
	document.KibizViewCart.submit();
  }
  

/*function to open the page in a printable format*/
  function Quoteprintable() {
   
    var param = '';
	var Module_Count = document.getElementById('Module_Count').value;
	//var Maintenance = document.getElementById('Maintenance').value;
	for( var i=1 ; i<=parseInt(Module_Count) ; i++){

	if(document.getElementById('users_'+i)!=null && typeof(document.getElementById('users_'+i))!="undefined"){
	if(document.getElementById('users_'+i).value > 0){
	param = param + '&users_'+i+'='+document.getElementById('users_'+i).value;
	
	
	if(document.getElementById('kimoduleid_'+i)!=null && typeof(document.getElementById('kimoduleid_'+i))!="undefined"){
	param = param + '&kimoduleid_'+i+'='+document.getElementById('kimoduleid_'+i).value;
	}
	
	if(document.getElementById('kimodulename_'+i)!=null && typeof(document.getElementById('kimodulename_'+i))!="undefined"){
	param = param + '&kimodulename_'+i+'='+document.getElementById('kimodulename_'+i).value;
	}
	
	if(document.getElementById('UnitType_'+i)!=null && typeof(document.getElementById('UnitType_'+i))!="undefined"){
	param = param + '&UnitType_'+i+'='+document.getElementById('UnitType_'+i).value;
	}
	
	if(document.getElementById('UnitTypeText_'+i)!=null && typeof(document.getElementById('UnitTypeText_'+i))!="undefined"){
	param = param + '&UnitTypeText_'+i+'='+document.getElementById('UnitTypeText_'+i).value;
	}
	
	if(document.getElementById('Amount_'+i)!=null && typeof(document.getElementById('Amount_'+i))!="undefined"){
	param = param + '&Amount_'+i+'='+document.getElementById('Amount_'+i).value;
	}
	
	if(document.getElementById('Type_'+i)!=null && typeof(document.getElementById('Type_'+i))!="undefined"){
	param = param + '&Type_'+i+'='+document.getElementById('Type_'+i).value;
	}
	
	if(document.getElementById('defaultqty_'+i)!=null && typeof(document.getElementById('defaultqty_'+i))!="undefined"){
	param = param + '&defaultqty_'+i+'='+document.getElementById('defaultqty_'+i).value;
	}
	
	if(document.getElementById('TotalAmount3_'+i)!=null && typeof(document.getElementById('TotalAmount3_'+i))!="undefined"){
	param = param + '&TotalAmount3_'+i+'='+document.getElementById('TotalAmount3_'+i).value;
	}
    
    if(document.getElementById('TotalAmount2_'+i)!=null && typeof(document.getElementById('TotalAmount2_'+i))!="undefined"){
	param = param + '&TotalAmount2_'+i+'='+document.getElementById('TotalAmount2_'+i).value;
	}
    
	if(document.getElementById('TotalAmount_'+i)!=null && typeof(document.getElementById('TotalAmount_'+i))!="undefined"){
	param = param + '&TotalAmount_'+i+'='+document.getElementById('TotalAmount_'+i).value;
	}
	
	
	if(document.getElementById('Index_'+i)!=null && typeof(document.getElementById('Index_'+i))!="undefined"){
	param = param + '&Index_'+i+'='+document.getElementById('Index_'+i).value;
	}
	}}
	
}
 	var ses = '-Session='+document.getElementById('Session').value;
	param = ses + '&SubmitOrder='+document.getElementById('SubmitOrder').value
	+ '&RedirectFrom='+document.getElementById('RedirectFrom').value
	+ '&Edit='+document.getElementById('Edit').value
	+ '&editorder='+document.getElementById('editorder').value
	+ '&Module_Count='+document.getElementById('Module_Count').value 
	+ param+'&print=1'+'&Maintenance='+document.getElementById('Maintenance').value;
	//alert(param);
	AjaxView('KiPurchaseValidation.lasso',param);
	
	
  }
   
/*Function to auto tab on key up*/
  function autotab(original,destination){
  	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
  	destination.focus()
  }
 
/*Function to save the Quote from the Purchase page*/
  function _SaveQuote() {
    var ses = document.getElementById('ses_id').value;
	document.KibizForm.action='KiPurchaseValidation.lasso?-Session='+ ses +'&QuoteFromPurchase=1';
	document.KibizForm.submit();
  }

/*Function to save the Quote from the Purchase page*/
  function _OrderQuote() {
    var param = getQuote();
	param = param +'&QuoteFromPurchase=1&Maintenance='+document.getElementById('Maintenance').value;	
	AjaxQuote('KiPurchaseValidation.lasso',param);
  }

/*Function to Recall the Quote from the Purchase page*/
  function _RecallQuote(UserID) {
    //var param = getQuote();
	var param = '&UserId='+UserID+'&OrderHistory=1&RedirectFrom='+document.getElementById('RedirectFrom').value+'&Maintenance='+document.getElementById('Maintenance').value;
	var ses = document.getElementById('Session').value;	 
	var url = 'KiRecallQuote.Lasso?-Session='+ses;
	//alert(url);	
	//AjaxCall(url,'prc1_'+loop_count,loop_count);
	AjaxQuote(url,param);
  }  
  
/*Function to submit the order from the Purchase page*/
  function _submitOrder() {
    var param = getQuote();
	param = param +'&SubmitOrder=1&Maintenance='+document.getElementById('Maintenance').value;
	//alert(param);	
    AjaxQuote('KiPurchaseValidation.lasso',param);
  }
  
/*Function to submit the order from the Purchase page*/
  function _submitChanges() {
    var param = getQuote();
	//alert(param);
	param = param +'&editorder='+document.getElementById('editorder').value+'&Edit='+document.getElementById('Edit').value+'&Maintenance='+document.getElementById('Maintenance').value;	
    //alert(document.getElementById('platform').value);
	//alert(param);
	AjaxQuote('KiPurchaseValidation.lasso',param);
	//var windowURL = document.KibizForm.action;
  }

/*function to retrieve all the current quote informations*/
  function getQuote() {
    var param = '';
	var Module_Count = document.getElementById('Module_Count').value;
	//alert('Module_Count'+Module_Count);
	for( var i=1 ; i<=parseInt(Module_Count) ; i++){
	
	
	
	if(document.getElementById('users_'+i)!=null && typeof(document.getElementById('users_'+i))!="undefined"){
	//alert(document.getElementById('users_'+i).id);
	//alert(document.getElementById('users_'+i).value);
	
	if(document.getElementById('users_'+i).value > 0){
	param = param + '&users_'+i+'='+document.getElementById('users_'+i).value;
	
	
	if(document.getElementById('kimoduleid_'+i)!=null && typeof(document.getElementById('kimoduleid_'+i))!="undefined"){
	param = param + '&kimoduleid_'+i+'='+document.getElementById('kimoduleid_'+i).value;
	}
	
	if(document.getElementById('kimodulename_'+i)!=null && typeof(document.getElementById('kimodulename_'+i))!="undefined"){
	param = param + '&kimodulename_'+i+'='+document.getElementById('kimodulename_'+i).value;
	}
	
	if(document.getElementById('UnitType_'+i)!=null && typeof(document.getElementById('UnitType_'+i))!="undefined"){
	param = param + '&UnitType_'+i+'='+document.getElementById('UnitType_'+i).value;
	}
	
	if(document.getElementById('UnitTypeText_'+i)!=null && typeof(document.getElementById('UnitTypeText_'+i))!="undefined"){
	param = param + '&UnitTypeText_'+i+'='+document.getElementById('UnitTypeText_'+i).value;
	}
	
	if(document.getElementById('Amount_'+i)!=null && typeof(document.getElementById('Amount_'+i))!="undefined"){
	param = param + '&Amount_'+i+'='+document.getElementById('Amount_'+i).value;
	}
	
	if(document.getElementById('Type_'+i)!=null && typeof(document.getElementById('Type_'+i))!="undefined"){
	param = param + '&Type_'+i+'='+document.getElementById('Type_'+i).value;
	}
	
	if(document.getElementById('defaultqty_'+i)!=null && typeof(document.getElementById('defaultqty_'+i))!="undefined"){
	param = param + '&defaultqty_'+i+'='+document.getElementById('defaultqty_'+i).value;
	}
	
	if(document.getElementById('TotalAmount_'+i)!=null && typeof(document.getElementById('TotalAmount_'+i))!="undefined"){
	param = param + '&TotalAmount_'+i+'='+document.getElementById('TotalAmount_'+i).value;
	}
	
	if(document.getElementById('TotalAmount2_'+i)!=null && typeof(document.getElementById('TotalAmount2_'+i))!="undefined"){
	param = param + '&TotalAmount2_'+i+'='+document.getElementById('TotalAmount2_'+i).value;
	}
	
	if(document.getElementById('TotalAmount3_'+i)!=null && typeof(document.getElementById('TotalAmount3_'+i))!="undefined"){
	param = param + '&TotalAmount3_'+i+'='+document.getElementById('TotalAmount3_'+i).value;
	}
	
	if(document.getElementById('Index_'+i)!=null && typeof(document.getElementById('Index_'+i))!="undefined"){
	param = param + '&Index_'+i+'='+document.getElementById('Index_'+i).value;
	}
	}
 }
}
 	var ses = '?-Session='+document.getElementById('Session').value;
	param = ses + '&SubmitOrder='+document.getElementById('SubmitOrder').value
	+ '&RedirectFrom='+document.getElementById('RedirectFrom').value
	+ '&Edit='+document.getElementById('Edit').value
	+ '&editorder='+document.getElementById('editorder').value
	+ '&Module_Count='+document.getElementById('Module_Count').value 
	+ '&Platform='+document.getElementById('Selectedplatform').value
	+ param;
	return param;
}

/*set unique platform for a quote in KiPurchase page*/
function setPlatform(value) {
document.getElementById('Selectedplatform').value = value;
}

/*set unique Maintenacetype for a quote in KiPurchase page*/
function setMaintenace(value) {
document.getElementById('Maintenance').value = value;
var Ses = document.getElementById('ses').value;
var count = document.getElementById('loop').value;
//alert(count);
  for (i=1;i<=count;i++)
  {
    if(value == 'Subscription'){
	document.getElementById('ActualPrice_'+i).value = document.getElementById('TotalPrice2_'+i).value;
    }
    else{
	document.getElementById('ActualPrice_'+i).value = document.getElementById('TotalPrice3_'+i).value;
    }
  }
var param='&Maintenance='+value;
document.KibizViewCart.action='KiRedirectPurchase.lasso?'+param;
document.KibizViewCart.submit();
//AjaxQuote('KiRedirectPurchase.lasso',param); 
}

/*function to Redirect to PlaceOrder/CreditcardInfo page after checkout*/
  function Redirect_OrdConf1(value) {
    var param='&editorder=1&Maintenance='+ value;
	//alert(param);
  	document.KibizViewCart.action='KiRedirectPurchase.lasso?'+param;
	document.KibizViewCart.submit();
  }

/*function to retrieve all the current quote informations*/
  function getQuote1() {
    var param = '';
 	var ses = '-Session='+document.getElementById('Session').value;
	param = ses + '&Edit='+document.getElementById('Edit').value+'&Platform='+ document.getElementById('Selectedplatform').value;
	return param;
}
