function openWin(file,winname, w, h)
{
	details="top=0,left=0,width="+w+",height="+h+",status=no,";
	details += "resizable=yes,scrollbars=yes,menubar=no,location=no";

	myWin = window.open(removeDOMXSS("A-Za-z0-9._- ",file), winname, details);
	myWin.focus();
}

function showHideDiv(tagname, showhide)
{
    if (showhide == 1)
    {
        //document.all[tagname].style.display = "block"
        document.getElementById(tagname).style.display='block';
    }

    if (showhide == 0)
    {
        //document.all[tagname].style.display = "none"
        document.getElementById(tagname).style.display='none';
    }

}

function setDivPosition(tagname, xpos, ypos)
{
	thisobj = document.getElementById(tagname).style.left = xpos;
	thisobj = document.getElementById(tagname).style.top = ypos;
}

// Returns TRUE if a valid Email Address.
function checkEmailAddress(email)
{
	var re = '^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$';
	var result;

	result = email.search(re);
	if(result == -1)
		return false;
	else
		return true;
}
//Added by Denali on 24Nov2010 for POSID validations
function check(form,toCheckEmpty)
{
	if(isNaN(form.POSID.value))
	{
            var str = '"'+ form.POSID.value +'" is not a valid number.';
            form.POSID.focus();
            alert(str);
            return false;
        }
	if(toCheckEmpty){
		// if(form.POSID.value == "")		
		//Added by Denali on 30Nov2010 for POSID mandatory field except for None option titles
		if(form.POSID.value == "" && form.Title.value != "None")
		{
			alert("Please enter the POS ID");
			form.POSID.focus();
			return false;
		}else{
			return true;
		}


	}else{
		return true;
	}

}

function maskDecimal(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/[^\d\.]*/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}

function maskCharityNumber(thefield)
{
    strobj = new String(thefield.value);
	if(strobj.length < 5)
		value = new String (strobj.replace(/\D/g, ""));
	else
		value = new String (strobj.replace(/[^a-zA-Z0-9]/g, ""));

    if(value.length > 4)
    {
        areacode = value.substr(0,4);
        n3 = value.substr(4,3);

        newvalue = areacode + "-";
        newvalue = newvalue + n3;

        thefield.value = newvalue;
    }
    else
    {
        thefield.value = value;
    }
}

function maskNumber(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/\D+/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}
function maskCreditCard(thefield)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/\D*/g, ""));
	if(newvalue.length > 16)
		value = newvalue.substr(0,16);
	else
		value = newvalue;
		
    thefield.value = value;
}

/*function validEmail(thefield)
{
    strobj = new String(thefield.value);
	res = strobj.match(/^[\w\.-]+\@[\w\.-]+$/i);
	if(res == true)
		return true;
	else
		return false;

}*/
//chagned by denali on 24feb2010
function maskZipCode(thefield)
{
    strobj = new String(thefield.value);
    //value = new String (strobj.replace(/\D*/g, ""));
    value1  = new String (strobj.replace(/\W*/g, ""));
	value = new String (value1.replace(/_/, ""));
		
    if(value.length > 5)
    {
        zip5 = value.substr(0,5);
        zip4 = value.substr(5,4);

        newvalue = zip5 + "-";
        newvalue = newvalue + zip4;

        thefield.value = newvalue;
    }
    else
    {
        thefield.value = value;
    }


}

function maskDate(thefield)
{
    strobj = new String(thefield.value);
    value = new String (strobj.replace(/\D*/g, ""));

    if(value.length > 4)
    {
        year = value.substr(0,4);
        month = value.substr(4,2);

        newvalue = year + "-";
        newvalue = newvalue + month;

        if(value.length > 6)
        {
            day  = value.substr(6,2);
            newvalue = newvalue + "-" + day;
        }

        thefield.value = newvalue;
    }
    else
    {
        thefield.value = value;
    }


}
function maskPhoneNumber(thefield)
{
    strobj = new String(thefield.value);
    value = new String (strobj.replace(/\D*/g, ""));

    if(value.length > 3)
    {
        areacode = value.substr(0,3);
        n3 = value.substr(3,3);

        newvalue = areacode + ".";
        newvalue = newvalue + n3;

        if(value.length > 6)
        {
            n4 = value.substr(6,4);
            newvalue = newvalue + "." + n4;
        }

        thefield.value = newvalue;
    }
    else
    {
        thefield.value = value;
    }


}
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	} else
	begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

function ele_showHide(div1, div2)
{
    document.getElementById(div1).style.display = "block";
    document.getElementById(div2).style.display = "none";
}
function showIPDiv()
{
        var sel_item = document.getElementById("FaxProviderID").selectedIndex;
        if(sel_item != 2)
        {
               showHideDiv('ipdiv',0);
        } else
        {
               showHideDiv('ipdiv',1);
        }
}

//added by denali for canadian zip on 24feb2010
function maskCanadaZipCode(thefield)
{
	strobj = new String(thefield.value);
    //value = new String (strobj.replace(/\D*/g, ""));
	value1  = new String (strobj.replace(/\W*/g, ""));
	value = new String (value1.replace(/_/, ""));

	if(value.length > 6)
	{
		zip5 = value.substr(0,6);
		zip4 = value.substr(6,4);

		newvalue = zip5 + "-";
		newvalue = newvalue + zip4;

		thefield.value = newvalue;
	}else
   	{
		thefield.value = value;
	}
}
//added by denali for canadian zip on 24feb2010
function maskCanadaNumber(thefield, limit)
{
    strobj = new String(thefield.value);
	newvalue = new String (strobj.replace(/\W+/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
	thefield.value = value;
}

// CI-107 Code
 function showInvitationInfoDiv()
 {
         var radio_sel_1 = document.getElementById("CustomizeIEM1").checked;
       var radio_sel_0 = document.getElementById("CustomizeIEM0").checked;
 
       if(radio_sel_1)
       {
               showHideDiv('invitation_info_div',1);
               showHideDiv('show_remove_from_chain_div',0);
       }
         if(radio_sel_0)
       {
                 showHideDiv('invitation_info_div',0);
               showHideDiv('show_remove_from_chain_div',1)
       }
 }
 
 function showCustomInvitaionDiv()
 {
       var inv_sel_item = document.getElementById("B2BTier").selectedIndex;
         if(inv_sel_item != 2 &&  inv_sel_item != 3)
         {
                 showHideDiv('custom_invitation_div',0);
               showHideDiv('invitation_info_div',0);
         } else
         {
               var radio_sel_1 = document.getElementById("CustomizeIEM1").checked;
               var radio_sel_0 = document.getElementById("CustomizeIEM0").checked;
 
               if(radio_sel_1)
                       showHideDiv('invitation_info_div',1);
               if(radio_sel_0)
                         showHideDiv('invitation_info_div',0);
               showHideDiv('custom_invitation_div',1);
         }
 
 }
 function submitFormToUpdateCustomInvitationMsg(action)
 {
       var greeting_msg = document.getElementById("GroupInviteGreetingMsg").value;
       var msg_timefmt = document.getElementById("GroupInviteOrderTimeFmt").value;
       var msg_body = document.getElementById("GroupInviteBody").value;
       var msg_signature = document.getElementById("Signature").value;
       var ChainFranchiseID = document.getElementById("chainFranchiseID").value;
       var retid= document.getElementById("restid").value;
       var restowner = document.getElementById("RestOwner").value;
       var set_customize_message = document.getElementById("CustomizeIEM1").checked;
       var send_request = true;      
       if(set_customize_message)
       {
               if(msg_signature.length <= 0)
               {
                       alert("Signature value should not be null");
                       send_request = false;
               }
                 if(msg_body.length <= 0)
                 {
                         alert("Invitation Message body value should not be null");
                       send_request = false;
                 }
               if(greeting_msg.length <= 0)
                 {
                         alert("Greeting message value should not be null");
                       send_request = false;
                 }
       }
       if(send_request)
       {
               var paramsList = "cmd=updateinvi&restid="+retid+"&ChainFranchiseID="+ChainFranchiseID;
               paramsList += "&RestOwner="+restowner+"&ActionToChain="+action;
               paramsList += "&GroupInviteGreetingMsg="+escape(greeting_msg)+"&GroupInviteBody="+escape(msg_body);
               paramsList += "&GroupInviteOrderTimeFmt="+escape(msg_timefmt)+"&Signature="+escape(msg_signature);
               url= "updateCustomInvitationMessage.php";
               $.post(url, paramsList, function(data){
                       if(action == 'apply')
                               alert('Applied custom invitation message to the entire chain');
                       if(action == 'remove')
                               alert('Removed custom invitation message to the entire chain');
               });
       }
 }
 // End of CI-107
// CI-138 Start here
function maskLabelFiled(thefield)
{
    strobj = new String(thefield.value);
    //value1  = new String (strobj.replace(/\W*/g, ""));
    value1  = new String (strobj.replace(/[^a-zA-Z0-9 ]/g, ""));
    value = new String (value1.replace(/_/, ""));
    thefield.value = value;
}
// CI-138 ends here	

//for DOM based XSS
function removeDOMXSS(regExp, inputVal)
{
	var regEx = "/[^"+regExp+"$]/";
	 if (inputVal.replace(regEx,""))
	 {
	      return inputVal;
	 }
}

