var addToCartSuccessMessage = 'added to cart successfully';
var addToCartFailedMessage = 'Failed to add to cart';
var addToQueueOrderFailedMessage = 'Failed to add to Queue Order';
function XMLPost(strTaget,strXML){
	try	{
		var xmlhttp;
        if(window.XMLHttpRequest)// Firefox, Safari, Opera... 
        {
            xmlhttp=new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
        }
		xmlhttp.open("POST", strTaget , false);
		var xmldoc ;
		if( window.ActiveXObject && /Win/.test(navigator.userAgent) )
       {
         xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
         xmldoc.loadXML(strXML);
       }
       else if( document.implementation && document.implementation.createDocument )
       {
         xmldoc = document.implementation.createDocument("", "", null);
         xmldoc.async="false";
         xmldoc.load(strXML);
         xmlhttp.setRequestHeader("Content-Type", "text/xml,application/xml")

       }
		//alert('before send' + xmldoc.innerXml);
		xmlhttp.send(strXML);
		//var resultDocument;
		//alert('after send  send' + xmlhttp.status );
		if(xmlhttp.status >=200 && xmlhttp.status <= 300) {
		    //alert('xmlhttp.responseXML' + xmlhttp.responseText );
//		    if( window.ActiveXObject && /Win/.test(navigator.userAgent) )
//           {
//                resultDocument = new ActiveXObject ("Microsoft.XMLDOM");
//                resultDocument.loadXML(xmlhttp.responseText)
//           }else if( document.implementation && document.implementation.createDocument )
//           {
//                resultDocument = document.implementation.createDocument("", "", null);
//                resultDocument.async="false";
//                resultDocument.onload=function (){};
//                resultDocument.load(xmlhttp.responseText)
//           }
//			if( resultDocument != null ) {
//			    alert('coming inside load');
//			   
//                if(SelectSingleNode(resultDocument,"//error")){
//				    alert(SelectSingleNode(resultDocument,"//error").text);  
//				    return false;
//			    }else{
//				    return SelectSingleNode(resultDocument,"//success").text;
//			    }
//           		
//			}
            return xmlhttp.responseText;
		}
	}catch(ex)	{
		alert(ex.description);
		return false;
	}	
}

 function SelectSingleNode(xmlDoc, elementPath)
    {
        if(window.ActiveXObject)
        {
            return xmlDoc.selectSingleNode(elementPath);
        }
        else
        {
           var items = xmlDoc.getElementsByTagName("success")
           var xpe = new XPathEvaluator();
           //var nsResolver = xpe.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
           //var results = xpe.evaluate(elementPath,xmlDoc,null,XPathResult.FIRST_ORDERED_NODE_TYPE, null);
            var results=document.evaluate(elementPath, xmlDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
            //results=nodes.iterateNext();
            return results;   
           //return results.singleNodeValue; 
        }
    }


	function Trim(s) 
	{
		while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
		{
			s = s.substring(1,s.length);
		}

		while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
		{
			s = s.substring(0,s.length-1);
		}
		return s;
	}
	
		function replaceSubstring(inputString, fromString, toString){
				var temp = inputString;
				if (fromString == ""){
					return inputString;
				}
				if (toString.indexOf(fromString) == -1) {
					while (temp.indexOf(fromString) != -1){
						var toTheLeft = temp.substring(0, temp.indexOf(fromString));
						var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
						temp = toTheLeft + toString + toTheRight;
					}
				} else{
					var midStrings = new Array("~", "`", "_", "^", "#");
					var midStringLen = 1;
					var midString = "";
					while (midString == ""){
						for (var i=0; i < midStrings.length; i++){
							var tempMidString = "";
							for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[j]; }
							if ((fromString.indexOf(tempMidString) == -1) && (temp.indexOf(tempMidString) == -1)){
								midString = tempMidString;
								i = midStrings.length + 1;
							}
							midStringLen = midStringLen + 1;
						}
						if(midString == ""){
							midString = tempMidString;
						}
					} 
					while (temp.indexOf(fromString) != -1){
						var toTheLeft = temp.substring(0, temp.indexOf(fromString));
						var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
						temp = toTheLeft + midString + toTheRight;
					}
					while (temp.indexOf(midString) != -1){
						var toTheLeft = temp.substring(0, temp.indexOf(midString));
						var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
						temp = toTheLeft + toString + toTheRight;
					}
				}
				return temp;
			}
			
		function Encrypt(inputString){
			var encryptedString=replaceSubstring(inputString,"&","&amp;");
			encryptedString=replaceSubstring(encryptedString,"<","&lt;");
			encryptedString=replaceSubstring(encryptedString,">","&gt;");
			encryptedString=replaceSubstring(encryptedString,"\"","&quot;");
			return encryptedString;
			
		}
		
	function GetDeleteConfirmString(title,description,message,CancelNotNeeded){
		var deleteConfirmString="/c360/Portal/ConfirmDialogBox.aspx?";
		deleteConfirmString +="OrgName=" + ORG_UNIQUE_NAME;
		deleteConfirmString +="&dialogTitle="+title; 
		deleteConfirmString +="&dialogDesc="+description; 
		deleteConfirmString +="&confirmMessage="+message; 
		deleteConfirmString +="&CancelNotNeeded="+CancelNotNeeded; 
		return deleteConfirmString;
	}
	
	function GetConfirmString(title,description,message,CancelNotNeeded){
		var deleteConfirmString="/c360/Portal/ConfirmDialogBox.aspx?";
		deleteConfirmString +="OrgName=" + ORG_UNIQUE_NAME;
		deleteConfirmString +="&dialogTitle="+title; 
		deleteConfirmString +="&dialogDesc="+description; 
		deleteConfirmString +="&confirmMessage="+message; 
		deleteConfirmString +="&CancelNotNeeded="+CancelNotNeeded; 
		return deleteConfirmString;
	}
	
	function checkEmail(txtValue){
		 var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		 //var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;// valid
		 var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]/;// valid
		 if (!reg1.test(txtValue) && reg2.test(txtValue)) { 
			return true;
		 }else{
			return false;
		 }
	}
	function checkEmailComplete(txtValue){
		 var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		 var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;// valid
		 if (!reg1.test(txtValue) && reg2.test(txtValue)) { 
			return true;
		 }else{
			return false;
		 }
	}
	function ValidateSpecialCharCmbination(txtValue){
		var reg1 = /\<|((\<)(\!|\?|\/|\&))/;
		if(reg1.test(txtValue)){
			return false;
		}
		return true;
	}
	
	function isFormChanged() {
		var rtnVal = false; 
		var frm = document.forms[0];
		var ele = frm.elements;

		for ( i=0; i < ele.length; i++ ) {
			if ( ele[i].type.length > 0 ) {
				if ( isElementChanged( ele, i ) ) {
					rtnVal = true;
					break;
				}
			}
		}
		return rtnVal;
	}
	
	function isElementChanged( ele, i ) {
		var isEleChanged = false; 

		switch ( ele[i].type ) { 

			case "text" : 
			if ( ele[i].value != ele[i].defaultValue ) return true;
			break;

			case "textarea" : 
			if ( ele[i].value != ele[i].defaultValue ) return true;
			break;

			case "radio" :
			val = "";
			if ( ele[i].checked != ele[i].defaultChecked ) return true;
			break;

			case "select-one" : 
			for ( var x =0 ; x <ele[i].length; x++ ) {
				if ( ele[i].options[ x ].selected 
				!= ele[i].options[ x ].defaultSelected ) 
					return true;
			}
			break;

			case "select-multiple" :
			for ( var x =0 ; x <ele[i].length; x++ ) {
				if ( ele[i].options[ x ].selected 
				!= ele[i].options[ x ].defaultSelected ) 
					return true;
			}
			break;

			case "checkbox" :
			if ( ele[i].checked != ele[i].defaultChecked ) return true;
			  
			default:
			return false;
			break;
		}
	}
	
	 function DoAction(strURL, iWidth, iHeight) 
        {
		    if(strURL != "") 
		    {
			    var strReturnValue = openStdDlg(strURL, null, iWidth, iHeight);
		    }
		    return false;
	    }
	    
	    
	    function openStdDlg(sPath, oArgs, iWidth, iHeight, bResizable, bModeless, sCustomWinParams)
        {
            if (IsNull(sCustomWinParams))
            {
            sCustomWinParams = "";
            }
            // Take into consideration any global increases in dialog size.  Used by localization teams.
            // Only use these increased sizes if the dialog is already resizeable.  If it is not resizeable then the increased sizes will
            // most likely not help much because the dialog probably has a fixed layout.
            if ((!IsNull(bResizable) && bResizable))
            {
               //If some exception is coming because of variable is not declared 
               //then catch it and set the default width and height.
                try{
                    iWidth	+= parseInt(LOCID_DIALOG_OFFSET_WIDTH, 10);
                    iHeight += parseInt(LOCID_DIALOG_OFFSET_HEIGHT, 10);
                 }catch(e){
                     iWidth	+= 10;
                     iHeight += 10;
                 }
                
            }
        // Adjust height for screen size.
        //iWidth	= getAdjustedWidthForScreen(iWidth);
        //iHeight	= getAdjustedHeightForScreen(iHeight);
            bResizable = (!IsNull(bResizable) && bResizable) ? "yes" : "no";
        // Get the left and top margin.
//        var iLeft = getLeftMargin(iWidth);
//        var iTop = getTopMargin(iHeight);
//        if ( LOCID_UI_DIR == "RTL")
//        iLeft = screen.availWidth-iLeft-iWidth;
        //sCustomWinParams = "dialogWidth:" + iWidth + "px;dialogHeight:" + iHeight + "px;dialogLeft=" + iLeft + "px;dialogTop=" + iTop + "px;help:0;status:1;scroll:0;center:1;resizable:" + bResizable + ";" + sCustomWinParams;
            sCustomWinParams = "dialogWidth:" + iWidth + "px;dialogHeight:" + iHeight + "px;help:0;status:1;scroll:1;center:1;resizable:" + bResizable + ";" + sCustomWinParams;
//            if (IsNull(bModeless) || !bModeless)
//            {
                return safeWindowShowModalDialog(sPath, oArgs, sCustomWinParams);
//            }
//            else
//            {
//                return safeWindowShowModelessDialog(sPath, oArgs, sCustomWinParams);
//            }
        }
        function IsNull(o)
        {
            return ("undefined" == typeof(o) || "unknown" == typeof(o) || null == o);
        }
	    function safeWindowShowModalDialog(sUrl, vArguments, sFeatures)
        {
            var returnVar = null;
            try
            {
                returnVar = window.showModalDialog(sUrl, vArguments, sFeatures);
            }
            catch (e)
            {
            handlePopupBlockerError();
            }
            return returnVar;
        }
        function handlePopupBlockerError()
        {
            alert("Popups blocked on" +  window.location.hostname);
        }
        
        function UpdateCartCountForAjax( count )
        {
            if( document.getElementById(cartLabel) )
			{
			    if( !isNaN( count ) )
			    {
			        document.getElementById(cartLabel).innerHTML = count;
			    }
			    
			}
        }
        
        function isEven(num) 
        {
            return !(num % 2);
        }
        
   function isInteger (s) {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

   function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }





