function GoHome(page, from)
{
   if(from=="main")
      document.location.href = page;      
   else
      document.location.href = "../" + page;
}

function GoSearch(page, from)
{
   if(from=="main")
      document.location.href = "Search/" +page;
   else
      document.location.href = "../Search/" + page;
}

/*
function GoHome(page)
{
   var uri = new Object();
   getURL(uri);
   
   var a = uri.path.split("/");
   if(a.length==1)
      document.location.href = page;
   else if(a.length==2)
      document.location.href = "../" + page;
   else
      document.location.href = "../../" + page;
}

function GoSearch(page)
{
   alert("Old");
   var uri = new Object();
   getURL(uri);
   
   var a = uri.path.split("/");
   if(a.length==1)
      document.location.href = "Search/" + page;
   else if(a.length==2)
      document.location.href = "../Search/" + page;
   else
      "../../Search/" + page;     
}

function GoSearch(page, from)
{
   alert("From: " + from);
   var uri = new Object();
   getURL(uri);
   
   var a = uri.path.split("/");
   if(a.length==1)
      document.location.href = "Search/" + page;
   else if(a.length==2)
      document.location.href = "../Search/" + page;
   else
      "../../Search/" + page;     
}
*/

function getURL(uri) 
{
   uri.dir = location.href.substring(0, location.href.lastIndexOf('\/'));
   uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/') uri.dom = uri.dom.substr(7);
   uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
   uri.page = location.href.substring(uri.dir.length+1, location.href.length+1);
   pos = uri.page.indexOf('?');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
   pos = uri.page.indexOf('#');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
   uri.ext = ''; pos = uri.page.indexOf('.');if (pos > -1) {uri.ext =uri.page.substring(pos+1); uri.page = uri.page.substr(0,pos);}
   uri.file = uri.page;
   if (uri.ext != '') uri.file += '.' + uri.ext;
   if (uri.file == '') uri.page = 'index';
   uri.args = location.search.substr(1).split("?");
   return uri;
}

function GotoPop(url)
{
	var windowWidth = 550; 
	var windowHeight = 450;
	
   var h = url.substr(0, 3).toLowerCase();

   if(h!="htt")
      url = "http://" + url;

	
	var oWindow = window.open(url, "_blank", "");

	return false;
}

function GotoPopSize(url, width, height)
{
	var oWindow = window.open(url, "_blank", "scrollbars=yes,resizable=yes,width=" + width+ ",height=" + height);
	CenterWindow(oWindow, width, height);
	oWindow.focus();

	return false;
}

function CenterWindow(windowObject, windowWidth, windowHeight) 
{ 
	windowX = (screen.availWidth - windowWidth) / 2; 
	windowY = (screen.availHeight - windowHeight) / 2; 
	windowObject.moveTo(windowX,windowY); windowObject.focus(); 
} 

function GoTo(url)
{
	document.location.href = url;
	
	return false;
}

function PopUp(url, width, height)
{
   var h = url.substr(0, 3).toLowerCase();
	var link = url;

   if(h!="htt")
      link = "http://" + url;
      
	var oWindow = window.open(url, "_blank", "scrollbars=yes,resizable=yes,width=" + width+ ",height=" + height);
	CenterWindow(oWindow, width, height);
	oWindow.focus();
	
	return false;
}

function PopUp(url)
{
   var width = 950;
   var height = 850;
   var h = url.substr(0, 3).toLowerCase();
	var link = url;

   if(h!="htt")
      link = "http://" + url;
      
	var oWindow = window.open(url, "_blank", "scrollbars=yes,resizable=yes,width=" + width+ ",height=" + height);
	//centerWindow(oWindow, width, height);
	oWindow.focus();
	
	return false;
}

function Empty(s)
{
	var whitespace = " \t\n\r";
	var i;

    if (IsEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}

function IsInt(txt)
{
	var isValid = true;
	var pattern = /[.]/gi;
	var comma = /,/gi;	

	txt = txt.replace(comma, "");

	if(txt.search(pattern)>-1)
		return false;
	
	if(IsWhitespace(txt))
		return false;
	
	if(isNaN(txt))
		isValid = false;
	
	return isValid;
}

function GetIntValue(txt)
{
	if(IsInt(txt))
		return parseInt(txt);
	else
		return -1;	
}

function CleanNumber(num)
{
	var pattern = /[.]/gi;
	var comma = /,/gi;	

	if(num!=null)
		num = num.replace(comma, "");

	return num;
}

function IsWhitespace(s)
{
	var whitespace = " \t\n\r";
	var i;

    if (IsEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}

function IsEmpty(s)
{
	return ((s == null) || (s.length == 0))
}

function ListClearOne(lstBoxObj, idx) 
{
	lstBoxObj.remove(idx);
}

function GetlstNameByIndex(lstBoxObj, idx)
{
   var listItemText;

   listItemText = lstBoxObj.options[idx].text;
   return listItemText;
}

function ListLoad(lstBoxObj, txt, Value) 
{
	var NewOption

	NewOption = document.createElement("OPTION");
	NewOption.text = txt;
	NewOption.value = Value;
	lstBoxObj.options.add(NewOption);
}

function ListBoxClear(obj) 
{
	var kill, i;
	
	i = obj.length;
	for (kill=0;kill<i;kill++) 
	{
		obj.remove(0);
	}
}

function HasParseChars(txt)
{
	var bp = false;
	var pattern = /[~^]/gi;
	var i = txt.search(pattern);
	
	if(i>-1)
		bp = true;
		
	return bp;
}

function IsValidPrice(txt)
{
	var isValid = true;
	var np = "";
	var comma = /,/gi;
	
	np = txt.replace("$", "");
	np = np.replace(comma, "");

	if(isNaN(np))
		isValid = false;

	if(IsWhitespace(txt))
		return false;

	return isValid;
}

function ValidXMLName(name)
{
	var pattern = /[\W]/gi;
	var pattern2 = /[0-9]/gi;
	
	if(isWhitespace(name))
		return false;

	if(name.charAt(0).search(pattern2)>-1)
		return false;
		
	if(name.search(pattern)>-1)
		return false;		

	return true;
}

function Trim(txt)
{
	while('' + txt.charAt(txt.length-1)==' ')
		txt = txt.substring(0, txt.length-1);

	return txt;
}

function ValidateDate(date) 
{
	var ad = date.split("/");
 
	var myDayStr = ad[1];
	var myMonthStr = ad[0];
	var myYearStr = ad[2];
	var myDateStr = myDayStr + ' ' + myMonthStr + ' ' + myYearStr;
	var aDate = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

	var myDate = new Date(date);

	// Convert the date to a string so we can parse it.
	var myDate_string = myDate.toLocaleDateString();

	var myDate_array = myDate_string.split( ' ' );

	if(myDate_array[1] != aDate[myMonthStr-1])
		return false;
	else
		return true;
 }

function AddCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   
   return IsNumber;
}

function BoldText(obj)
{
	obj.style.fontWeight = "bolder";
	obj.style.color = "yellow";
}

function NormalText(obj)
{
	obj.style.fontWeight = "bold";
		obj.style.color = "white";
	var floatPhoto = document.getElementById("divPhoto");
}

