// a2kGlobal.js
isIE=(navigator.userAgent.toLowerCase().indexOf("msie") != -1);
isFF=(navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
  
function getExt(flName){
  firstpos=flName.lastIndexOf('.');
  lastpos=flName.length;
  return flName.substring(firstpos,lastpos);
}

function a2kImgOver(img){
  var ext= getExt(img.src);
  img.oldSrc=img.src;

  var indx=img.src.lastIndexOf('-on');
  if(indx==-1)
    indx=img.src.lastIndexOf(ext);
  img.src=img.src.substring(0,indx)+"-over"+ext;
}
function a2kImgOn(img){
  var ext= getExt(img.src);
  var indx1=img.src.lastIndexOf('-');
  var indx2=img.src.lastIndexOf('/');
  var indx = -1;
  if(indx1 > indx2)
    indx=indx1;
  if(indx==-1)
    indx=img.src.lastIndexOf(ext);
  img.src=img.src.substring(0,indx)+"-on"+ext;
}
function a2kImgOut(img){
  img.src=img.oldSrc
  img.oldSrc=null;
}
function a2kImgOff(img){
  var ext= getExt(img.src);
  var indx1=img.src.lastIndexOf('-');
  var indx2=img.src.lastIndexOf('/');
  var indx = -1;
  if(indx1 > indx2)
    indx=indx1;
  if(indx==-1)
    indx=img.src.lastIndexOf(ext);
  img.src=img.src.substring(0,indx)+"-off"+ext;
}

function plainPopup(url) {
  plainPopup(url, '_blank');
}

function plainPopup(url, name) {
  popupWin = window.open(url, name, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=800, height=600');
  if (popupWin == null)
    alert('Please enable popups in your popup blocker for this site.');
  else
    popupWin.focus();
}


function getWait(url){
  var waitDiv = document.getElementById("loadingWait");
  if(waitDiv)
    waitDiv.style.display="block";    
  document.location.href=url;
}
function getWaitPopup(url) {
  if (navigator.appVersion.indexOf('Safari') == -1){
	  popupWin = window.open("", '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=800, height=600');
	  if (popupWin == null)
	    alert('Please enable popups in your popup blocker for this site.');
	  else {
	    popupWin.document.write('<html><head></head><body>');
	    popupWin.document.write('<div id="loadingWait" style="position:absolute;width:150px;height:150px;left:50%;top:200px;margin-left:-75px;display:none;z-index: 10000;background:transparent;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="150" height="150" id="waiting" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/a2kWeb/flash/waiting.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><embed src="/a2kWeb/flash/waiting.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="150" height="150" name="waiting" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></div>');
	    popupWin.document.write('</body></html>');
	    var waitDiv = popupWin.document.getElementById("loadingWait");
	    if(waitDiv)
	      waitDiv.style.display="block";    
	    popupWin.document.location.href=url;
	  }
  }
  else {
    popupWin = window.open(url, '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=800, height=600');
  }
}

function postWait(frm){
  var waitDiv = document.getElementById("loadingWait");
  if(waitDiv)
    waitDiv.style.display="block";    
  if(frm)
    frm.submit();
}

function waitWithoutSubmit(){
  var waitDiv = document.getElementById("loadingWait");
  if(waitDiv)
    waitDiv.style.display="block";  
}

function doubleConfirm(msg1, msg2){
	var result = false;
	if(confirm(msg1)){
		if(confirm(msg2)){
			result = true;
		}
	}	
	
	return result;
}


function promptPOC(msgText) {     
     if($.browser.msie && $.browser.version <= 6){
       var varText = 'We have noticed you have not viewed the Welcome to Amway Presentation.\nThis is a short presentation that you will find very valuable as you dive into your new business. \nPlease note you cannot order products until you view this presentation.';
       if (confirm(varText)) {
       	 window.open('/downloads/welcometoAmway.html', 'POC', 'height=420,width=530,status=no,menubar=no,toolbar=no,location=no,scrollbars=no,resizable=no');
    	 doPoc('Y');  /* user considered to have viewed presentation now */
       	 return false;
       }else{
       	return false;
       }
     } else{    
	     $.alerts.okButton="View it now";
	     $.alerts.cancelButton="Ask me later";	
	     				
	   	 $.alerts.dialogClass = "pocReminder";  
		 jConfirm(msgText, 'Welcome to Amway Presentation Reminder', function(result) {
		    if (result == true) {
				window.open('/downloads/welcometoAmway.html', 'POC', 'height=420,width=530,status=no,menubar=no,toolbar=no,location=no,scrollbars=no,resizable=no');
		    	doPoc('Y');   /* user considered to have viewed presentation now */
			}
		});
		return false;
	}	
} 

function processedPOCUpdate(data) {
	alert(data); 
	return false;
}


function openRenewalPopup(){
	renewal=window.open(cxtPth+"/renewUser.a2k", "renewal","toolbar=no,width=573,height=675,scrollbars=yes,status=yes");
	if(renewal=='undefined' || renewal==null)
	   	alert("You have a pop-up blocker enabled.\nTo use the full functionality you must enable pop-ups for Amway online.\nSee the help pages for details.");
	else
		renewal.focus(); 
}

function openRenewalPopup(msgText) {
     $.alerts.okButton="Renew now!";
     $.alerts.cancelButton="Do it later";	
     				
   	 $.alerts.dialogClass = "renewalReminder";  
	 jConfirm(msgText, 'Renewal Reminder', function(result) {
	    if (result == true){
			window.location = cxtPth+"/renewIbo.a2k";
		}
	});
	return false;
} 

function closeReminderPopup(){	
 	document.getElementById("backgroundPopup").style.display = "none";
	document.getElementById("divReminderPopup").style.display = "none";	  	 
    window.scrollTo(0,0); 
}
function displayReminderPopup(){
     document.getElementById("backgroundPopup").style.display = "block";
	 $("#divReminderPopup").fadeIn("slow");
	 window.scrollTo(0,0);   	 	
}

function displayPopup(popupDivName){
     var backgroundDiv =  document.getElementById("backgroundPopup");
     if (backgroundDiv != null){
     	backgroundDiv.style.display = "block";
     }    
     var popupDiv = document.getElementById(popupDivName); 
     if (popupDiv != null){                  
         $("#" + popupDivName).fadeIn("slow");     
	 }
	 window.scrollTo(0,0);   	 	
}

function closePopup(backgroundDivName, reminderDivName){
    var backGroundDiv = document.getElementById(backgroundDivName);
    if (backGroundDiv != null){
    	backGroundDiv.style.display = "none";
    }
    var reminderdiv = document.getElementById(reminderDivName);
    if (reminderdiv != null){
		reminderdiv.style.display = "none";	  	 
	}
    window.scrollTo(0,0); 
}

function displayVgnPopup(){
    var vgnOkButton = document.getElementById("vgnButtonYes");
    var vgnNoButton = document.getElementById("vgnButtonNo");
	// if vgnNoButton or vgnOkButton can be found,  it means the message has been retrieved from vignette,  then show popup.
	 if (vgnNoButton != null || vgnOkButton != null){
			displayPopup("divPopupMsg");
	 }
}	
function printPage() {
  try{
    print();  // implement this method on specific pages that require special printing
  } catch (err) {
    window.print();
  }
}

function goto(url) {
	window.location=url;
	return false;
}

//Gloabl Validation Functions.

function isBlankEmail(value) {
  var blkExp = /^\s*$/;
  return blkExp.test(value);
}

function isValidEmail(strEmail) {  
  var emlRegExp = new RegExp('^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$');
  return emlRegExp.test(strEmail);
}

function goodEmail(obj){
	if(obj!=null && obj!=undefined){
		if(obj.value)
			return isValidEmail(obj.value);
		else
			return isValidEmail(obj);
	}else{
		return false;
	}
}

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

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

