/*
Common JavaScript Library
*/

/*
 This is being used to ensure cross-browser consistency. 
 Please use css (hover) wheverever possible (e.g., <A> tags should use hover styles) 
 Example of use:  
 onmouseover="ChangeElementSrc(this,'/sharedResources/images/buttons/login_over.jpg');"
*/
function ChangeElementSrc(obj,strNewValue){
    if (obj.src){
        obj.src = strNewValue;
    }
}


/*
 This is being used to ensure cross-browser consistency- and really only on forms and sales tools lists
 Please note amrkup dependencies if you reuse this
*/
function DoZoom(parentObject,blnZoom){
    if (parentObject.getElementsByTagName){
        var containedDivs = parentObject.getElementsByTagName('div');

        for (var i=0, j=containedDivs.length; i<j; ++i){
            x = containedDivs[i];
            if (x.className && 'Zoomed' == x.className){
                x.style.display = (blnZoom? 'block':'none');
                parentObject.parentNode.parentNode.style.zIndex = (blnZoom? '999':'996');
            }
        }
    }
}


function openHelp(sType,sCode){
	var url = "/Marketing/Help/HelpPopUpPage.aspx?ContentID=" + sCode
	helpWin = window.open(url,'OnlineHelp','resizable=yes,toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,width=680,height=550,top=0,left=0');
	helpWin.focus();
}


function showHideSwap(show, hide){
    //	retrieve object
    //------------------------------
    SHOW	= getObject(show);
    HIDE	= getObject(hide);


    //	check state and reset
    //------------------------------
    //SHOW.style.visibility	= SHOW.style.visibility == "hidden" ? "visible" : "hidden";
    SHOW.style.display		= SHOW.style.display == "none" ? "block" : "none";

    //HIDE.style.visibility	= SHOW.style.visibility == "hidden" ? "visible" : "hidden";
    HIDE.style.display		= SHOW.style.display == "block" ? "none" : "block";

}

//------------------------------------------------
//	Get Object for usage
//------------------------------------------------
function getObject(id){
    //	retrieve object
    //------------------------------
    if (document.getElementById){
       OBJ = document.getElementById(id);
    }
    else if (document.all){
       OBJ = document.all[id];
    }
    else if (document.layers){
	    if (document.layers[id]){
		    OBJ = document.layers[id];
	    }
    }
    //	return object to caller
    //------------------------------
    return OBJ;
}

function CreateXMLHttpRequestObject()
{
if (window.XMLHttpRequest) {
       return new XMLHttpRequest();
   }
   else
   {
        var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ];    
        for (var i = 0; i < progIDs.length; i++) {
            try {
                var xmlHttp = new ActiveXObject(progIDs[i]);
                return xmlHttp;
            }
            catch (ex) {
            }
        }	     
   }
   return null;
}

function IsValidPasswordPattern(tbPassword, requiredStrongPassword){

	var p = document.getElementById(tbPassword).value;

	// normal validation
	var re1=/\d{1,}/;
        var re2=/\w{6,14}/;
      
	// strong password validation
        var hasNum=/[0-9]/;
        var hasLCase=/[a-z]/;
        var hasUCase=/[A-Z]/;
        var hasSpChar=/[!@#$%&+=)^(*~?]/;
        var underscope =/_/;

	/* 
	 Required Strong Password needs below:
	 8 to 14 characters.  least one character from three of these four categories:  
	 Upper case letters, lower case letters, numerals, and special characters [!, @, #, $, %, etc])
	*/
	if (requiredStrongPassword) {
		var Score =(hasNum.test(p)?1:0)+(hasLCase.test(p)?1:0)+(hasUCase.test(p)?1:0)+(hasSpChar.test(p)?1:0);
	        if (Score>=3 && !underscope.test(p) && p.length<15 && p.length>7){
			return true;
		}
	}

	if ((requiredStrongPassword == 'False') && (re1.test(p) && re2.test(p))) {
		return true;
	}

	return false;
}


