/*Author: Gauri Ramakrishnan
		  Sprint, VB-CMS
		  gauri.ramakrishann@sprint.com
*/		
//Global variables 
var myDialog=null;
var content="";
var choices="";

//Function to submit a form
function submitForm(name)
{
  document.forms[name].submit();
}

//Initialize the dialog widget that will display the pop-up dialog message
function initDialog(){
	/*The css style fix for bug # 272848 will go here. */
	myDialog=new widgets.dialog({id:'podDialogId',className:'podDialogClass',backingClass:'podBackgroundClass',css:'position:absolute; z-index:200;'},true,true);
}  

// Function to hide the dialog widget when invoked
function hideDialog(){
	myDialog.hide(); 
}    

//Function to display the dialog popup 
function showDialogVM(this_event,target_obj){
    if(!myDialog){
		//Initialize the dialog if it is not initialized
        initDialog()
    }
	var cartItemIdHref=target_obj.href;
	var fm="";
	//get the current form elements 
	//first check which container element is used(eitehr tr(phone upgrade lisitng page or div(phone detail page)
	if(!target_obj.$anc('tr')){
		//Retrive the form name for upgrade and upgrade detail layer
     	fm = target_obj.$anc('div').$t('form')[0];
	} else {	
		//Retrive the form name for upgrade list page
	 	fm = target_obj.$anc('tr').$t('form')[0];
    }
	var formName = fm.name;
	var content = fm.$c('interceptText')[0].getHTML();
	choices ='<a href="javascript:hideDialog();"><img src="/assets/images/common/buttons/bt_gr_cancel_v1_en.gif" alt="Cancel Btn" class="space" /></a><a href="javascript:submitForm(\''+formName+'\');"><img src="/assets/images/common/buttons/bt_yl_continue_v1_en.gif" alt="Continue btn" /></a>';
	var template = '<div class="podShell"><div class="topPod"></div><div class="podRepeat">' + content + '<div class="btns">' + choices + '</div></div><div class="podBtm"></div></div>';	
	myDialog.setContent(template);  
	myDialog.center();    
	myDialog.show(); 
} 

//Create events based on the css property defined in the html
var vmbeh=[
//Commented the following code because we are not using the click event/behavior
//	new Behavior({
//	css:'a.visualvm',
//	events:{'visualvmClick':[false,true,true]}
//}),
	new Behavior({
	css:'form.deviceIntercept',
	events:{'visualvmSubmit':[false,true,true]}
	//Trouble shotting purpose only
	//exec:[function(){alert(1)}]
})];

//Add the events and add to DOM Load
//Events.add('visualvmClick','click',showDialogVM);
Events.add('visualvmSubmit','submit',showDialogVM);
Behaviors.addToDOMLoad(vmbeh);

