 	/*
	 *
	 * Copyright	: 	Confidential and Proprietary. 
	 *					Copyright CMP Media, 2007
	 *									
	 * File name	:	common.js 
	 *
	 * Description	:	This js contains a common method to disable the submit 
	 *                  button when clicked once in subscription pages
	 * 					
	 * Author		:	Cognizant
	 *
	 * Date			:	May 02, 2007
	 *
	 * Modification History		
	 *
	 * Revision No.	   Author		   Date				 Comments
	 *     1.0		   Cognizant	   May 02,2007       Initial version
	 *	   1.1		   Cognizant	   July 17,2007      1.Fix - script error 
	 *													   in survey page    
	 *     1.2		   Cognizant	   Dec 27,2007		 1. NT Enhancement     
	 *	   1.3		   Cognizant	   Jan 10 ,2008		 1.Configure Confirmation Quit message                        
	 *	   1.4		   Cognizant	   Feb 21, 2008		 1. Add Session timeout message
	 *	   1.5		   Cognizant	   Jun 04, 2009		 1.Live Event Enhancement
	 *	   1.6		   Cognizant	   Sep 17, 2009		 1. Add to calendar in oe offers	
	 *	   1.7		   Cognizant	   Nov 19, 2009		 1.SSO Auto login
	 *	   1.8		   Cognizant	   Dec 17, 2009		 1.issue - javascript error
	 *	   	1.9		   	Cognizant		Mar 04, 2010	1.Dynamic other text box enhancement
	 */

 function doSubmit() 
{ 
   SubmitFlag = true; 
   document.forms[0].submitbtm.disabled=true;
   return true; 
}  
// version 1.1 comment 1 - start
function doSubmitForSubscriptionStatus()
{
   SubmitFlag = true; 
   document.forms[1].submitbtm.disabled=true;
   return true; 
}
//version 1.1 comment 1 - end
function preCheck(){
document.forms[0].opt_in_external.checked=true;
}


function doSubmitClick() 
{ 
   SubmitFlag = true;
   return true; 
}  

// function to avoid incomplete pop-up

function doSubmitPhase2() 
{ 
   SubmitFlag = true; 
   var l_localJsCASUserName=null;
   var l_localEmailValue = "";
   var l_localPassword = null;
   var l_localPasswordValue="";
   var l_localSSOEnabled = null;
   var passwordFieldCheck = document.getElementById("passwordField");
      
   if(document.forms[0].js_cas_user_name!=null){
		l_localJsCASUserName = document.forms[0].js_cas_user_name;
	}
	if(document.getElementById("email")!=null){
		l_localEmailValue = document.getElementById("email").value;
	}
	if(document.getElementById("password")!=null){
		l_localPassword = document.getElementById("password");
	}
	if(document.getElementById("ssoenabled")!=null){
		l_localSSOEnabled = document.getElementById("ssoenabled");
	}

	if(l_localJsCASUserName!=null && l_localEmailValue!="" && (l_localJsCASUserName.value!=l_localEmailValue || l_localJsCASUserName.value=="") && l_localSSOEnabled!=null && l_localSSOEnabled.value!="" && l_localSSOEnabled.value!="false" ){
			if(l_localPassword!=null){
			l_localPasswordValue=l_localPassword.value;
			}
			if(l_localPasswordValue==""){
				CheckEmailByAJAXFB();
				var l_temp = document.getElementById("passwordField");
				if(l_temp!=null)
				{
					l_temp.style.backgroundColor='yellow';
					if(passwordFieldCheck!=null && (passwordFieldCheck.style.display=="inline")==1){
						l_localPassword.focus();
					}
					
				}
				return false;
			}
	}
	//Version 1.8 Comment 1 Start
	var l_temp = document.getElementById("passwordField");
	if(l_temp!=null)
		l_temp.style.backgroundColor='';	 
   //Version 1.8 Comment 1 End
   b1 = document.getElementById("b1");
   if(b1!=null)
	   document.forms[0].b1.disabled=true;
   return true; 
}  

function doSubmitPhase2LGOffer() 
{ 
   SubmitFlag = true; 
   return true; 
}  

// function to display incomplete pop-up

var complete="false";
var SubmitFlag="false";
var completeoffer="false";
//version 1.6 comment 1 starts
var addtocalendar="false";
//version 1.3 command - 1 starts
function ConfirmQuit(pubcode,confirmQuitMsg)
{ 
    var l_bFlag;

	if(addtocalendar==true){
		return;
	}
    if (SubmitFlag == true || complete == true || (completeoffer != null && completeoffer == true)) 
    {
        SubmitFlag="false";  
        complete ="false";
        return; 
    }
    else if(confirmQuitMsg!= "" || confirmQuitMsg!=null)
    {
    if(addtocalendar==true){
    	addtocalendar=false;
		return;
    }
    	return confirmQuitMsg;
//version 1.6 comment 1 ends	
	}else{
		if(pubcode == 'IK')
			return "Information Week is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $199 per year).";                         
		else if(pubcode == 'BY')
			return "Bank Systems & Technology is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $65 per year).";
		else if(pubcode == 'RS')
			return "CRN is free to qualified solution providers, but you must complete the entire form. If you are selected, you will receive a FREE subscription (others pay $220 per year).";
		else if(pubcode == 'SD')
			return "Dr Dobb's is FREE to qualified IT professionals,  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $49 per year).";
		else if(pubcode == 'CD_TEMP')
			return "CRN and VARBusiness are free to qualified solution providers, but you must complete the entire form. If you are selected, you will receive a FREE subscription (the regular price is $220 for CRN and $120 for VARBusiness).";
		else if(pubcode == 'ET')
			return "EE Times is FREE to qualified engineers and creators of technology. But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $280 per year).";
		else if(pubcode == 'ES')
			return "Embedded Systems Design is FREE to qualilfied key designers responsible for defining systems, selecting the critical hardware and software components, building the systems, and integrating the hardware and firmware designs --- but you must complete the entire form. If you are selected,you will receive a FREE subscription (others pay $55 per year)";
		else if(pubcode == 'GS')
			return "Global Services is FREE to qualified IT professionals, but you must complete the entire form.\n If you are selected, you will receive a FREE subscription (others pay $95.00 per year).";
		else if(pubcode == 'IT')
			return "Insurance & Technology is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $65 per year)." ;   
		else if(pubcode == 'DB')
			return "Intelligent Enterprise is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $95 per year).";
		else if(pubcode == 'NC')
			return "Network Computing is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $95 per year).";
		else if(pubcode == 'OP')
			return "Optimize is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $195 per year).";
		else if(pubcode == 'VB')
			return "VARBusiness is free to qualified solution providers, but you must complete the entire form. If you are selected, you will receive a FREE subscription (others pay $120 per year).";
		else if(pubcode == 'WS')
			return "Wall Street & Technology is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $85 per year)."       
		//version 1.2 - command  - 1 - starts
		else if(pubcode == 'NT')
			return "TechNet is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $85 per year)."       
		//version 1.2 - command  - 1 - ends
	}
}
//version 1.3 command - 1 ends

// Function to give auto tab for fax number and phone number
function autoTab(input,len, e)
{
	var keyCode = (isNaN) ? e.which : e.keyCode; 
	var filter = (isNaN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode))
	{
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele)
	{
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}
	function getIndex(input)
	{
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;
}

// Function to get the radio value
function getRadioValue(object)
{
    var radioValue         
    if(object.length == undefined){
         radioValue = object.value
    }
    else{
	for (var i=0; i < object.length; i++)
	{          
	  if (object[i].checked)
	  {
				radioValue = object[i].value
				break
			    }
			}
		}
        return radioValue
}

// Function for displaying the pop-up for Receive subscription - BY
function BYFreeOnClickNo(pubCode){

	var url = "freepopup.do?mode=pageforward&forward=" + pubCode;	
	window.open(url,"optimize","height=210,width=510,left=80,top=80")

}

// Function for displaying the pop-up for Receive subscription - IT
function ITFreeOnClickNo(pubCode){

	var url = "freepopup.do?mode=pageforward&forward=" + pubCode;	
	window.open(url,"optimize","height=210,width=510,left=80,top=80")

}

// Function for displaying the pop-up for Receive subscription - IK
function IKFreeOnClickNo(pubCode){
	
	var url = "freepopup.do?mode=pageforward&forward=" + pubCode;
	window.open(url,"optimize","height=210,width=510,left=80,top=80")

}

// Function for displaying the pop-up for Receive subscription - NC
function NCFreeOnClickNo(pubCode){

	var url = "freepopup.do?mode=pageforward&forward=" + pubCode;	
	window.open(url,"optimize","height=210,width=510,left=80,top=80")

}

// Function for displaying the pop-up for Receive subscription - OP
function OPFreeOnClickNo(pubCode){

	var url = "freepopup.do?mode=pageforward&forward=" + pubCode;	
	window.open(url,"optimize","height=210,width=510,left=80,top=80")

}

// Function for displaying the pop-up for Receive subscription - WS
function WSFreeOnClickNo(pubCode){

	var url = "freepopup.do?mode=pageforward&forward=" + pubCode;	
	window.open(url,"optimize","height=210,width=510,left=80,top=80")

}

// Function for displaying the pop-up for Receive subscription - GS
function GSFreeOnClickNo(pubCode){

	if (confirm("Thank you for your request.\n\nYou have indicated that you do not wish to receive . If this is an error, please click the OK button to return to the  Qualification Form."))
	{
		document.forms[0].Free[0].checked = true;
				submitFlag = true;
		window.location = "http://globalservicesmedia.com/";
	} else {
           
        document.forms[0].Free[0].checked = true;
        document.forms[0].Free[1].checked = false;
    }

}

// Function for displaying the pop-up for Receive subscription - SD
function SDFreeOnClickNo(pubCode){

	if (confirm("Thank you for your request.\n\nYou have indicated that you do not wish to receive Dr. Dobb's. If this is an error, please click the \"Cancel\" button to return to the Dr. Dobbs qualification form."))
	{
		submitFlag = true;
		window.location = "http://www.ddj.com/";
	}
	else
	{
		document.forms[0].Free[0].checked = true;
        document.forms[0].Free[1].checked = false;
	}

}

// Function for displaying the pop-up for Receive subscription - ET
function ETFreeOnClickNo(pubCode){

	if (confirm("You have indicated that you do not wish to receive " +
      "EE Times Magazine. If this is an error, please click the Cancel button to"+
      " return to the EE Times Magazine form."))
      {
	      SubmitFlag = true;
	      window.location = "http://www.eetimes.com";
      } else {
            
        	document.forms[0].Free[0].checked = true;
	        document.forms[0].Free[1].checked = false;

      }
}

// Function for displaying the pop-up for Receive subscription - ES
function ESFreeOnClickNo(pubCode){

	if (confirm("You have indicated that you do not wish to receive " +
	"ESD Magazine. If this is an error, please click the Cancel button to"+
	" return to the ESD Magazine form."))
	{
		document.forms[0].Free[0].checked = true;
		SubmitFlag = true;
		window.location = "http://www.embedded.com/";
	} else {
		document.forms[0].Free[0].checked = true;
	    document.forms[0].Free[1].checked = false;
	}

}

// Function for displaying the pop-up for Receive subscription - VB
function VBFreeOnClickNo(pubCode){

	if (confirm("You have indicated that you do not wish to receive " +
	"VARBusiness Magazine. If this is an error, please click the Cancel button to"+
	" return to the VARBusiness Magazine form."))
	{
		SubmitFlag = true;
		window.location = "http://www.varbusiness.com/"
	} else {
		document.forms[0].Free[0].checked = true;
	    document.forms[0].Free[1].checked = false;
	}
}

//Function to validate Customer service survey 
/*
function checkSurvey(){
checked1=false;
checked2=false;
checked3=false;
for(i=0;i<5;i++){
if(document.forms[1].resolve[i].checked){
 checked1=true;
 }
if(document.forms[1].use[i].checked){
 checked2=true;
 }
if(document.forms[1].visit[i].checked){
 checked3=true;
 } 
}
if(checked1||checked2||checked3||(document.forms[1].surveyComments.value !="")){
  doSubmit();
  document.forms[1].submit();
 }else{
   alert("Please select any or all information");
  }           
}
*/
function openWindow(URL,nme,width,height,t,l,s,r)
{
   
	var w = screen.width;
	var h = screen.height;
	var left = (w - width) / 2;
	var top = (h - height) / 2;
	var args = "toolbar=" + t + ",location=" + l + ",scrollbars=" +
		s + ",resizable=" + r + ",width=" + width + ",height=" +
		height + ",left=" + left + ",top=" + top;

	//rdWin = 
	window.open(URL,nme,args);
	//rdWin.focus();

}

function OfferPageNoClickedPhase2() {

	document.forms[1].submit();
}
//Version 1.4 Comment 1 Start
function Down() { 
	sec--;      
	if (sec == -1) { sec = 59; min--; }

	if(min== 2 && sec == 0)
	{
		if (SubmitFlag == true || complete == true || (completeoffer != null && completeoffer == true)) 
		{
			min=0;
			sec=0;
		}
		else
		{
			window.focus();
			alert('Your session is about to time out. Please click on Submit/Continue to keep your session alive');
		}
		

	}

	if (min == 0 && sec == 0) {	}
	else down = setTimeout("Down()", 1000);

}

function timeIt() {
	min = 20; 
	sec = 0;
	Down();
}
//Version 1.7 Comment 1 Start
function checkNoSSOPwd(NoPwd){
		
	if('true'== NoPwd){
	
		var casPwdDiv =  document.getElementById("casPasswordDiv");
		var casPwdDiv1 =  document.getElementById("casPasswordDiv1");
		var casPwdField =  document.getElementById("passwordField");
		
		if(casPwdDiv!=null){
			casPwdDiv.style.display="none";
		}
		if(casPwdDiv1!=null){
			casPwdDiv1.style.display="none";
		}
		if(casPwdField!=null){
			casPwdField.style.display="none";
		}
	}
}
//Version 1.7 Comment 1 End
//Version 1.5 Comment 1 Start
function referFriend(){

	document.forms[0].action = "referfriend.do?mode=autosendreferenceemail&forward=samepage";
	document.forms[0].submit();
}

//Version 1.5 Comment 1 End
//Version 1.4 Comment 1 End

//Version 1.9 Comment 1 Start
//Dropdown question
function TextBoxInDropDown(test){
	if(test != null){
		var i=test.value;
		if(i!=null){
			var j=i.split("$")
			if(j!=null && j[0]=='OTHER'){
				var l="textother#"+test.name
				var frm_element = document.getElementById(l);
				if(frm_element!=null){
					var vis = frm_element.style;
					vis.display = '';
				}
				var frm_element = document.getElementById("OTHER$"+test.name+"$"+j[2]+"#label");
				if(frm_element!=null){
					var vis = frm_element.style;
					vis.display = '';
				}

				for (var ji = 0; ji < test.length; ji++)
				{
					var frm_element2 = test.options[ji].value;

					if(frm_element2!=null
						&& frm_element2!=""){

						var ans=frm_element2.split("$");
						
						if (i != frm_element2
							&& ans!=null && ans[0]=="OTHER"){
							frm_element = document.getElementById("OTHER$"+test.name+"$"+ans[2]+"#label");
							if(frm_element!=null){
								vis = frm_element.style;
								vis.display = 'none';
							}
						}
					}
				}
				
			} else if(j!=null && j[0]!= ""){
				var l="textother#"+test.name
				var frm_element = document.getElementById(l);
				if(frm_element!=null){
					var vis = frm_element.style;
					vis.display = 'none';
				}
				for (var ji = 0; ji < test.length; ji++)
				{
					var frm_element2 = test.options[ji].value;

					if(frm_element2!=null
						&& frm_element2!=""){

						var ans=frm_element2.split("$");
						
						if (i != frm_element2
							&& ans!=null && ans[0]=="OTHER"){
							frm_element = document.getElementById("OTHER$"+test.name+"$"+ans[2]+"#label");
							if(frm_element!=null){
								vis = frm_element.style;
								vis.display = 'none';
							}
						}
					}
				}
			}
		}
	}
}

//Radio button question
function TextBoxInRadio(test){

	if(test != null){
		var name1=test.name;
		var newName="";
		var frm_element2 = document.getElementsByName(name1);
		if(frm_element2!=null) {
			for (var ji = 0; ji < frm_element2.length; ji++)
			{
				if (frm_element2[ji].checked){
					newName = frm_element2[ji].value;
					var j=newName.split("$")
					if(j!=null && j[0]=='OTHER'
						&& j.length==3){
						var frm_element = document.getElementById(newName);
						if(frm_element!=null){
							var vis = frm_element.style;
							vis.display = '';
						}
						var frm_element = document.getElementById(newName+"#label");
						if(frm_element!=null){
							var vis = frm_element.style;
							vis.display = '';
						}
					}
				} else{
					newName = frm_element2[ji].value;
					var j=newName.split("$")
					if(j!=null && j[0]=='OTHER'
						&& j.length==3){
						var frm_element = document.getElementById(newName);
						if(frm_element!=null){
							var vis = frm_element.style;
							vis.display = 'none';
						}
						var frm_element = document.getElementById(newName+"#label");
						if(frm_element!=null){
							var vis = frm_element.style;
							vis.display = 'none';
						}
					}
				}
	
			}
		}
	}
}

//Checkbox question
function TextBoxInCheckBox(test){
	if(test != null){
		if(test.checked==true){
			var l=test.value
			var frm_element = document.getElementById(l);
			if(frm_element!=null){
				var vis = frm_element.style;
				vis.display = '';
			}
			var frm_element = document.getElementById(l+"#label");
			if(frm_element!=null){
				var vis = frm_element.style;
				vis.display = '';
			}
					
		} else{
			var l=test.value
			var frm_element = document.getElementById(l);
			if(frm_element!=null){
				var vis = frm_element.style;
				vis.display = 'none';
			}
			
			var frm_element = document.getElementById(l+"#label");
			if(frm_element!=null){
				var vis = frm_element.style;
				vis.display = 'none';
			}
		}
		
	}
}

//EET Two column Radio checkbox special question
function TextBoxInRadioCheckBox(test){
	if(test != null){
		var i=test.value;
		if(i!=null){
			var j=i.split("$")
			
			if(j!=null && j[0]=='EET'
				&& j.length==4){
				var l="EETOTHER_"+j[3]
				var frm_element = document.getElementById(l);
				var vis = frm_element.style;
				if(test.checked==true){
					vis.display = '';
				} else{ //Checking the Radio button
					var name1=test.name;
					var Name2=name1.split("#");
					var newName=Name2[0];
					var frm_element2 = document.getElementsByName(newName);
					for (var ji = 0; ji < frm_element2.length; ji++)
					{
						if (frm_element2[ji].checked)
							newName = frm_element2[ji].value;
					}

					if(newName !=null){
						frm_element2_split=newName.split("$");
						if(frm_element2_split!=null && frm_element2_split[0]=='EET'
							&& frm_element2_split.length==4){
								vis.display = '';
							} else{
								vis.display = 'none';
							}
					} else{
						vis.display = 'none';
					}
				}
			} else{ //For Radio button without textbox
				var name1=test.name+"#1";
				var frm_element2 = document.getElementsByName(name1);
				for (var ji = 0; ji < frm_element2.length; ji++) {
					if (frm_element2[ji].checked){
						newName = frm_element2[ji].value;
						if(newName !=null){
							frm_element2_split=newName.split("$");
							if(frm_element2_split!=null && frm_element2_split[0]=='EET'
								&& frm_element2_split.length==4){

								l="EETOTHER_"+frm_element2_split[3]
								frm_element = document.getElementById(l);
								vis = frm_element.style;
									vis.display = '';
							} 
						}
					} else {
						newName = frm_element2[ji].value;
						if(newName !=null){
							frm_element2_split=newName.split("$");
							if(frm_element2_split!=null && frm_element2_split[0]=='EET'
								&& frm_element2_split.length==4){

								l="EETOTHER_"+frm_element2_split[3]
								frm_element = document.getElementById(l);
								vis = frm_element.style;
									vis.display = 'none';
							} 
						}
					}
				}
			}
		}
	}
}
//Version 1.9 Comment 1 End
function populateStateOnLoad(){
		selCountry = document.getElementById('country'); 
		selState = document.getElementById('state'); 
		if(selCountry!=null){
			country = selCountry.options[selCountry.options.selectedIndex].value;
			if(country!='222' && country!='38')
				populateState(selCountry,selState);
		}
	
}
