var Windows_OS_Text = navigator.appVersion.indexOf("Windows NT 5.0") > 0 ? "Windows NT" : navigator.appVersion.indexOf("Windows NT 5.1") > 0 ? "Windows XP" : "Non Windows"
function popUp(URL, w, h, windowName, bUseScrollbars, bResizable) {
/********************************************************************
'  Author      : Enrique Garibay
'  Called From : Everywhere
'  Parameters  : URL, w, h, windowName, buserScrollbars, bResizeable
'  Returns     : --
'  Description : this function is used to create pop windows with the
'				 given parameters.  This will also center the popup
'				 window on the user's Screen.
'
'  Revision History
'  Date      	Author      		Description
'  08APR2003	Enrique Garibay	Original
'********************************************************************/
	day = new Date();
	id = day.getTime();
	var sScrollbars;
	var sResizable;
	var sWindowOptions = new String("toolbar=0,");

	if (bUseScrollbars == true){
		sScrollbars = "scrollbars=yes,";
	}else{
		sScrollbars = "scrollbars=0,";
	}
	if (bResizable == true){
		sResizable = "resizable=yes,";
	}else{
		sResizable = "resizable=0,";
	}
	sWindowOptions += sScrollbars + sResizable + "fullscreen=no,location=0,statusbar=0,status=no,menubar=0,directories=no,";
	try {
		l = (screen.Width - w) / 2;
		if (l < 0 || l > 1400) {
			l = 100
		}
	}
	catch (e) {
		l = 100;
	}
		
	try {
		t = (screen.Height - h) / 2;
		if (t < 0 || t > 1000) {
			t = 100
		}
	}
	catch (e) {
		t = 100;
	}

	if (windowName.length <= 0){
		eval("page" + id + " = window.open(URL, '" + id + "', '" + sWindowOptions + ",width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + "');");
	}
	else{
		eval(windowName + " = window.open(URL, '" + id + "', '" + sWindowOptions + ", width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + "');");
	}
}


//***   STRING MANIPULATION FUNCTIONS   ***********************************************
String.prototype.trim = function() {
/********************************************************************
'  Author      : --
'  Called From : --
'  Parameters  : sURL, iHeight, iWidth
'  Returns     : --
'  Description : --
'
'  Revision History
'  Date      	Author      		Description
'********************************************************************/
  return(this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1')); 
}

String.prototype.isNumeric = function() {
  return (parseFloat(this, 10)== (this * 1)); 
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	var returnValue = "";
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			returnValue = pair[1];
			break;
		}
	} 
	return returnValue;
}

function makePOSTRequest(url, parameters) 
{
    http_request = false;
     if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
   function alertContents() {

      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            //alert(result);
         } else {
       alert(http_request.status + "="+http_request.responseText);
            alert('There was a problem with the request.');
         }
      }
   }
   
   
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {

	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	}
	else
	{
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
    }
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function ValidateTextbox (e,txt)
{
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
    { 
        var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
//        if(key!="8" && key!="35" && key!="36" && key!="37" && key!="39"  && key!="46"   && key!="50"  && !( key>="51" && key <= "56")&& !( key>="65" && key <= "90") )
//        {
	        //var str=document.getElementById("txtquan1");	
	        var str=txt;	
	        var SearchTxt=str.value;				
	        
	        SearchTxt=SearchTxt.replace('~','');
	        SearchTxt=SearchTxt.replace(',','');
	        SearchTxt=SearchTxt.replace('(','');
	        SearchTxt=SearchTxt.replace(')','');
	        SearchTxt=SearchTxt.replace('[','');
	        SearchTxt=SearchTxt.replace(']','');
	        SearchTxt=SearchTxt.replace('\'','');
	        SearchTxt=SearchTxt.replace('\"','');
	        SearchTxt=SearchTxt.replace('!','');
	        SearchTxt=SearchTxt.replace(':','');
	        SearchTxt=SearchTxt.replace('#','');
	        SearchTxt=SearchTxt.replace('|','');
	        SearchTxt=SearchTxt.replace('&','');
	        str.value=SearchTxt;				
	       
       //} 
    }
}

function ValidateSearch(e, txt) {
    var evt = (e) ? e : (window.event) ? window.event : null;
    if (evt) {
        var key = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
        var str = txt;
        var SearchTxt = str.value;

        SearchTxt = SearchTxt.replace('~', '');
        SearchTxt = SearchTxt.replace(',', '');
        SearchTxt = SearchTxt.replace('(', '');
        SearchTxt = SearchTxt.replace(')', '');
        SearchTxt = SearchTxt.replace('[', '');
        SearchTxt = SearchTxt.replace(']', '');
        SearchTxt = SearchTxt.replace('\'', '');
        SearchTxt = SearchTxt.replace('\"', '');
        SearchTxt = SearchTxt.replace('!', '');
        SearchTxt = SearchTxt.replace(':', '');
        SearchTxt = SearchTxt.replace('#', '');
        SearchTxt = SearchTxt.replace('|', '');
        str.value = SearchTxt;
    }
}

function ValidateTagTextbox (e,txt)
{
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
    { 
        var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
        
        if(key!="8" && key!="35" && key!="36" && key!="37" && key!="39"  && key!="46"   && key!="50"  && !( key>="51" && key <= "56")&& !( key>="65" && key <= "90") )
        {
	        var str=txt;	
	        var SearchTxt=str.value;				
	        
	        SearchTxt=SearchTxt.replace('~','');
	        SearchTxt=SearchTxt.replace(',','');
	        SearchTxt=SearchTxt.replace('(','');
	        SearchTxt=SearchTxt.replace(')','');
	        SearchTxt=SearchTxt.replace('[','');
	        SearchTxt=SearchTxt.replace(']','');
	        SearchTxt=SearchTxt.replace('\'','');
	        SearchTxt=SearchTxt.replace('\"','');
	        SearchTxt=SearchTxt.replace('!','');
	        SearchTxt=SearchTxt.replace(':','');
	        SearchTxt=SearchTxt.replace('#','');
	        SearchTxt=SearchTxt.replace('|','');
	        SearchTxt=SearchTxt.replace('&','');
	        
            SearchTxt=SearchTxt.replace('.','');
            SearchTxt=SearchTxt.replace('?','');
            SearchTxt=SearchTxt.replace('<','');
            SearchTxt=SearchTxt.replace('>','');
            SearchTxt=SearchTxt.replace('\/','');
            SearchTxt=SearchTxt.replace('\\','');
            
             SearchTxt=SearchTxt.replace('_','');
            SearchTxt=SearchTxt.replace('=','');
            SearchTxt=SearchTxt.replace('+','');
            SearchTxt=SearchTxt.replace('%','');
            SearchTxt=SearchTxt.replace('^','');
            SearchTxt=SearchTxt.replace('@','');
             SearchTxt=SearchTxt.replace('*','');
              SearchTxt=SearchTxt.replace('%','');
               SearchTxt=SearchTxt.replace('$','');
           
	        str.value=SearchTxt;				
	       
        } 
    }
}

    function recordServiceUsage(service_name,video_id,locale){
    getUrl("/sharing_services?name="+encodeURIComponent(service_name)+"&v="+video_id+"&locale="+locale,true);
    }

function openPopup(url,name,height,width,opt_show_scrollbars){
var scrollbar_param=opt_show_scrollbars?",scrollbars=1":"";
var newwindow=window.open(url,name,'height='+height+',width='+width+scrollbar_param);
if(newwindow&&!newwindow.opener){newwindow.opener=window;}
if(window.focus){newwindow.focus()}
return false;
}

function getUrl(url,async,opt_handleStateChange)
{
    var xmlHttpReq=getXmlHttpRequest();
    if(!xmlHttpReq)
    return;
    if(opt_handleStateChange)
    {
    xmlHttpReq.onreadystatechange=function()
    {
    opt_handleStateChange(xmlHttpReq);
    };
    }
    else
    {
    xmlHttpReq.onreadystatechange=function(){;}
    }
    xmlHttpReq.open("GET",url,async);
    xmlHttpReq.send(null);
    }
    function postUrl(url,data,async,stateChangeCallback)
    {
    var xmlHttpReq=getXmlHttpRequest();
    if(!xmlHttpReq)
    return;
    xmlHttpReq.open("POST",url,async);
    xmlHttpReq.onreadystatechange=function()
    {
    stateChangeCallback(xmlHttpReq);
    };
    xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlHttpReq.send(data);
}
    
 function getXmlHttpRequest()
{
    var httpRequest=null;
    try
    {
    httpRequest=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
    try
    {
    httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e)
    {
    httpRequest=null;
    }
    }
    if(!httpRequest&&typeof XMLHttpRequest!="undefined")
    {
    httpRequest=new XMLHttpRequest();
    }
    return httpRequest;
}  

function validtag(textArea)
{

    var txt = document.getElementById(textArea).value.trim();
    if(txt.length < 1)
    {
        alert("You must enter a tag.");
        return false;
    }
}
function isEmail(aStr)
	{
		var reEmail=/^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\.-]+\.[0-9a-zA-Z_\.-]+$/;
		if(!reEmail.test(aStr))
			{
				return false;
			}
		return true;
	}


function ShowGoogleCheckout() {
		popUp('/App_UI/site/pHion/Public/PopUps/GoogleCheckout.htm', 820, 700, 'phion', true,true);
	}

function ShowPayPal() {
		popUp('/App_UI/site/pHion/Public/PopUps/PayPal.htm', 820, 700, 'phion', true,true);
	}	

function ShowPrint(product) {
		//popUp('/App_UI/site/pHion/Public/PopUps/PrintProduct.aspx?p=' + product, 800, 700, 'phion', true, false);
		popUp('/App_UI/site/pHion/Public/PopUps/PrintProduct.aspx?p=' + product, 960, 800, 'phion', true, false);
}
function PrintRecipe(Recipe) {
    popUp('/App_UI/site/pHion/Public/PopUps/Recipe.aspx?id=' + Recipe, 978, 600, 'phion', true, false);
}
	function ShowAutoReplenishDetail() {
		//popUp('/App_UI/site/pHion/Public/PopUps/AutoReplenishDetail.htm', 400, 300, 'phion', true, false);
		popUp('/App_UI/site/pHion/Public/PopUps/AutoReplenishDetail.htm', 820, 500, 'phion', true, false);
	}
	
	function ShowImage(product) {
		popUp('/App_UI/site/pHion/Public/PopUps/ShowProductImage.aspx?p=' + product+"&img="+document.getElementById("hdnImage").value, 820, 700, 'phion', true, false);
	}
    
     function ShowTags() {
		popUp('/App_UI/site/pHion/Public/PopUps/Tags.htm', 820, 700, 'phion', true,true);
	}
	
	function ShowSupplementImage(img) {
		popUp('/App_UI/site/pHion/Public/PopUps/SupplementIamge.aspx?img=' + img, 820, 700, 'phion', true, false);
	}
    
	
function ShowImageBorder(pId)
    {
        var prefix = "ctl00_ContentPageBody_Img"; 
        for(i=1;i<=4;i++)
        {
            if(document.getElementById(prefix + i) != null)
                document.getElementById(prefix + i).style.border = "solid 2px #ffffff";
        }
        document.getElementById(prefix + pId).style.border = "solid 2px #DDDDDD";
    }	
    
