function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
         field.value = field.value.substring(0, maxlimit);
         alert("You have exceeded the maximum characters allowed (250).");
         // otherwise, update 'characters left' counter
    } else {
         countfield.value = maxlimit - field.value.length;            
    }
}

var query = window.location.search.substring(1);
var vars = query.split("&");
var offid = "";
for (var i=0;i<vars.length;i++) {
  var pair = vars[i].split("=");
	if (pair[0] == "offid") {
	var offid = pair[1];
    }
}

var sPageTitle=document.title + " - " + offid;
document.title=sPageTitle;

var elqPPS = '50';
var elqDLKey = escape('429F1564D4134B5CABF1695AEEC15500');
var elqDLLookup = '';


function toggleList(e,f){
	element = document.getElementById(e).style;
	element.display == 'none' ? element.display = 'block' : 
	element.display='none';
	element2 = document.getElementById(f).style;
	element2.display == 'none' ? element2.display = 'block' : 
	element2.display='none';
}

function getQueryStringParamValue(strQStrParam)
{
    var strURL = document.location.href;
    var strQStrParamValue = '';
 
    if (strURL.indexOf('?') != -1)
    {
        strQStrParamValue = strURL.substr(strURL.indexOf('?')+1);
        if (strQStrParamValue.indexOf(strQStrParam + '=') != -1)
        {
            strQStrParamValue = strQStrParamValue.substr(strQStrParamValue.indexOf(strQStrParam + '='));
              strQStrParamValue = strQStrParamValue.substr(strQStrParamValue.indexOf('=') + 1);
              if (strQStrParamValue.indexOf('&') != -1){
                strQStrParamValue = strQStrParamValue.substr(0, strQStrParamValue.indexOf('&') );
            }else{
                if (strQStrParamValue.indexOf('&') != -1)
                    strQStrParamValue = strQStrParamValue.substr(0, strQStrParamValue.indexOf('&') - 1);
            }
        }
        else{
           strQStrParamValue = '';
        }
    }
 
    //alert(strQStrParamValue);
    return strQStrParamValue;
}
 
function checkPurlID() {
var PURLid;
var PURLPageId;
var offerId;
var mc;

PURLPageId = getQueryStringParamValue('elqPURLPage');
offerId = getQueryStringParamValue('offid');
mc = getQueryStringParamValue('mc');


if (this.GetElqContentPersonalizationValue) {
   //alert(PURLPageId);
   //alert(offerId);
   //alert(mc);
    if (GetElqContentPersonalizationValue('V_PURL_Name__Forms_cognosp') != '' && GetElqContentPersonalizationValue('V_MostRecentFormSubmitted')!='') {
           PURLid = GetElqContentPersonalizationValue('V_PURL_Name__Forms_cognosp');
           if (mc != ''){
               mc = '&mc=' + mc;
           }
           if(offerId != ''){
               offerId = '&offid=' + offerId;
           }
           location.href = 'http://forms.cognos.com/' + PURLid + '?elqPURLPage='  + PURLPageId +  mc + offerId;//no profile
    }
	SetElqContent();
}

}
function setOfferID() {
          var offId = getQueryStringParamValue('offid');
               if (this.GetElqContentPersonalizationValue) {
                     if (offId  == ''){
	          if (GetElqContentPersonalizationValue('V_Offe_rID1p') == '') {
	                      document.forms['CognosForm'].elements['retURL'].value = 'http://www.ibm.com/cognos/';//no profile
	         }else {
                                  offId = GetElqContentPersonalizationValue('V_Offe_rID1p');
                                  document.forms['CognosForm'].elements['retURL'].value = 'http://forms.cognos.com/content/global-confirmation-rd?offid=' +  
                                           offId; //set returl to profile value
                              }
                      }
                      else{               
                              document.forms['CognosForm'].elements['retURL'].value = 'http://forms.cognos.com/content/global-confirmation-rd?offid=' + offId;
                     }
               }
               else if (offId != ''){
                                   document.forms['CognosForm'].elements['retURL'].value = 'http://forms.cognos.com/content/global-confirmation-rd?offid=' +  
                                   offId; //set returl to profile value
               }
               else {
	document.forms['CognosForm'].elements['retURL'].value =  'http://www.ibm.com/cognos/';//no profile
               }
               document.forms['CognosForm'].elements['offId'].value = offId;

}

function SetCookie(sCookieName,iSecs) 
{
	var oToday = new Date();
	var oExpire = new Date();
	if (iSecs==null || iSecs==0) iSecs=30000;
	oExpire.setTime( oToday.getTime() +10000*iSecs );
	document.cookie = sCookieName+"="+escape(true)+ ";expires="+oExpire.toGMTString();
} 

function GetCookie(sCookieName) 
{
	iIndex = document.cookie.indexOf(sCookieName);
	if (iIndex != -1)
		return true;
	else
		return false;
}

function new_window(url) {
	link = window.open(url,"Link","toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=800,height=600,left=10,top=2");
	}
	
function new_win_noresize(url,x,y)
	{
		var str_features_1 = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="
		var str_features_2 = ",height="
		var str_features_3 = ",left=0,top=0"
		var str_features=str_features_1+x+str_features_2+y+str_features_3
		link = window.open(url,"Link",str_features);
    	link.focus();
	}
