
function setCookie(name, value, expires, path, domain, secure) 
{
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

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));
}

function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1) {
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function setVisibility(obj,disp)
{
	var obj, disp;
	if (disp == "show") {
		obj.style.visibility = 'visible';
		obj.style.display = 'block'
	}
	else {
		obj.style.visibility = 'hidden';
		obj.style.display = 'none'
	}
}
function toggleVisibility(obj)
{
	var obj;
	if (obj.style.display == null) {
		//obj.style.visibility = 'visible';
		obj.style.display = "inline";
		return;
	}
	if (obj.style.display == "inline")
		obj.style.display = "none";
	else
		obj.style.display = "inline";
	if (document.getElementById("topuname") != null)
		document.getElementById("topuname").focus();
}
function showHideImages(imgid,divObj)
{
	var name,imgid, divObj;
	name = imgid.src.substring(imgid.src.lastIndexOf("/")+1,imgid.src.length)
	if (name == "plus.gif")	{
		imgid.src = "images/minus.gif";
		imgid.alt = "Collapse";
		setVisibility(divObj,"show");
	}
	else {
		imgid.src = "images/plus.gif";
		imgid.alt = "Expand";
		setVisibility(divObj,"hide");
	}
}

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 Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function fixPercent(ele)
{
	var ele,ind,minus;
	minus = ""
	if (ele.value != "")
	{
		if (ele.value.indexOf('-') != -1)
		{
			minus = "-";
			ele.value = Right(ele.value,String(ele.value).length - 1);
		}
		if ((ele.value < 1) && (ele.value > 0))
		{
			ele.value = Math.round((ele.value * 100)*100)/100;
		}
		if (ele.value.indexOf('%') == -1)
			ele.value = ele.value + "%";
		if (ele.value.indexOf('.') == -1 )
		{
			if (ele.value.indexOf('%') == -1)
				ele.value = ele.value + ".0%";
			else
			{
				ele.value = Left(ele.value,ele.value.indexOf('%'));
				ele.value = ele.value + ".0%";
			}
		}
		if ((ele.value.indexOf('%') != -1)&&(Left(ele.value,ele.value.indexOf('%'))<1))
		{
			ele.value = Left(ele.value,ele.value.indexOf('%')) * 100 + "%";
		}
		if (minus == "-")
		{
			ele.value = "-" + ele.value;
			minus = "";
		}
	}	
}	

function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function isValidDate (strDate) {
	if (strDate.indexOf("/")!= -1)
		var parsedDate = strDate.split ("/");
	else
		var parsedDate = strDate.split ("-");		
   
   if (parsedDate.length != 3) return false;
   var day, month, year;
   month = parsedDate[0]-1;
   day = parsedDate[1];
   year = parsedDate[2];

   var objDate = new Date (strDate);
   if (month != objDate.getMonth()) return false;
   if (day != objDate.getDate()) return false;
   if (year != objDate.getFullYear()) return false;

   return true;
} 

function DateComare (date1Str, date2Str) {
	var date1  = new Date(date1Str);
	var date2  = new Date(date2Str);
	//
	if (date1 < date2)
	{
	return -1;
	}
	else if (date1 > date2)
	{
	return 1;
	}
	else {
	return 0;
	}
}

function formatDate(dt)
{
	if((dt == null) || (dt == undefined))
		return;
	var fullms = new Array("January","February","March","April","May","June","July",
                           "August","September","October","November","December");
	var ms = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul",
                           "Aug","Sep","Oct","Nov","Dec");
	var dt = new Date(dt);
	return ms[dt.getMonth()] + ' ' + dt.getDate() + ', '+ dt.getFullYear();
}
function getAppropriateSize(size_in_bytes)
{
	var size_in_bytes;
	return Math.round((size_in_bytes / 1024 / 1024) * 100)/100 + " MB";
}
function ShowHideLoading()
{
	var loadid;
	loadid = document.getElementById("Loading");
	loadid.style.visibility = 'visible';
}

function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; }
}
function queryString(key){
var page = new PageQuery(window.location.search);
return unescape(page.getValue(key));
}

function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              inTag = false;
              i++;
        }
        if(!inTag) newString += oldString.charAt(i);
   }
   return newString;
}

function format(obj,curr)
{
	var curr,obj;
	if (Trim(obj.value) == "")
		return;
	if (!IsNumeric(Trim(obj.value.replace("$","").replace(",",""))))
		return;
	if(curr == 'dollar')
		obj.value = formatCurrency(obj.value);
}
// Function used to fade "out" a div
function FadeOut($WhichDiv) {
	for( var i = 0 ; i <= 100 ; i++ ) {
		   setTimeout( 'setOpac(\''+$WhichDiv+'\',' + (100 - i) + ')' , 10 * i );
	}
	setTimeout('ToggleDiv(\''+$WhichDiv+'\')', 10 * i);
	setOpac($WhichDiv,100); // set it to opaque (just in case)
}

// Function used to show/hide the target div
function ToggleDiv($WhichDiv) {
	if (document.getElementById($WhichDiv).style.display == "none") {
		setOpac($WhichDiv,100); // set it to opaque (just in case)
		document.getElementById($WhichDiv).style.display = "block";
	} else {
		document.getElementById($WhichDiv).style.display = "none";
	}
}

// Function used to set the opacity of a div (from 0 to 10)
function setOpac( $WhichDiv, value ) {
	document.getElementById($WhichDiv).style.opacity = value / 100;
	document.getElementById($WhichDiv).style.filter = 'alpha(opacity=' + value + ')';
}

// Function used to shrink/grow a div vertically
function ToggleVert($WhichDiv, $MinHeight, $MaxHeight) {
	var $CurrHeight = parseInt($($WhichDiv).getHeight());
	if ($CurrHeight < ($MaxHeight - 10)) {
		VertScale($WhichDiv,$MaxHeight);
	} else {
		VertScale($WhichDiv,$MinHeight);
	}
}

// Function used to animate the scaling of a div vertically
function VertScale($WhichDiv, $EndHeight) {
	var $StartHeight = parseInt($($WhichDiv).getHeight());
	document.getElementById($WhichDiv).style.display = "block"; // display as block just in case
	document.getElementById($WhichDiv).style.overflow = 'hidden'; // set the overflow to hidden
	for( var i = 0 ; i <= 50 ; i++ ) {
		   $CurrHeight = ($StartHeight - ((($StartHeight - $EndHeight) / 50) * (i-1)));
		   setTimeout( 'setHeight(\''+$WhichDiv+'\',' + $CurrHeight + ')' , 10 * i );
	}
	if ($EndHeight == 0) {
		setTimeout('ToggleDiv(\''+$WhichDiv+'\')', 10 * i);
	}
}
// Function used to set the height of a div
function setHeight( $WhichDiv, value ) {
	document.getElementById($WhichDiv).style.height = parseInt(value) + "px";
}
function addbookmark()
{
	var IE = navigator.appName.match(/(Microsoft Internet Explorer)/gi),
    NS = navigator.appName.match(/(Netscape)/gi),
    OP = navigator.appName.match(/(Opera)/gi);
    if(IE && document.uniqueID)
	{
		var bookmarkurl="http://www.heyev.com/"
		var bookmarktitle="Heyev.Com"
		window.external.AddFavorite(bookmarkurl,bookmarktitle)
    }
    else if(OP || IE && !document.uniqueID)
	{
       alert('Your browser requires to Press Ctrl & D\n for Bookmark this Site.');              
    }
    else if(NS)
	{
       alert('Your browser requires to Press Ctrl & D\n for Bookmark this Site.');     
    }
    else{ BK.innerHTML = '' }
}
function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}

function urldecode(str) {
str = str.replace('+', ' ');
str = unescape(str);
return str;
}
// ENCODES, IN UNICODE FORMAT
function encode(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}

	}

	return utftext;
}