// JavaScript Document

/// Brake from any frame
function Unframe(){
if (top != self) {
top.location.href = self.location.href;
	}
}


//Focus on object
function DoFocus(CHname){
	//alert(CHname)
	CHname.focus()
	}
//Blue from object
function DoBlur(CHname){
	//alert(CHname)
	CHname.blur()
	}
	
	
/// Check a checkbox by function
function DoCheckbox(CHname){
	//alert(CHname)
	if (CHname.checked == false)
	{
	CHname.checked = true
	}
	else
	{
	CHname.checked = false
	}
	
	}
	
/// Check a RadioButton by function
function DoRadioBT(CHname,NM){
	//alert(NM)
	if (CHname[NM].checked == false)
	{
	CHname[NM].checked = true
	}
	else
	{
	CHname[NM].checked = false
	}
	
	}


//Open window - Center screen
function WinOpen(winURL,winWidth,winHeight){
	var w = screen.width; 
	var h = screen.height;
	var left = (w-winWidth)/2;
	var top = (h-winHeight)/2;

window.open(winURL,'popWin','width='+winWidth+',height='+winHeight+',screenX='+top+',top='+top+',screenY='+left+',left='+left+'')
}

function WinOpenScroll(winURL,winWidth,winHeight){
	var w = screen.width; 
	var h = screen.height;
	var left = (w-winWidth)/2;
	var top = (h-winHeight)/2;

window.open(winURL,'popWin','width='+winWidth+',height='+winHeight+',screenX='+top+',top='+top+',screenY='+left+',left='+left+',scrollbars=1')
}


//  ValidMail(this.value)
function ValidMail(txtValid){
var re;
        re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
        if (re.test(txtValid) == true)
			return true;
        else
        {
            alert('יש למלא כתובת דואר אלקטרוני נכונה');
			return false;
        }
}

//   NoSpace(this.value,' שם פרטי')
function NoSpace(txtValid, fieldname){
	re = /\s/;
	if (re.test(txtValid)==false)
	{
		return true;
		}
	else
	{
		alert('אין להשתמש ברווחים בשדה - '+fieldname)
		return false;
		}
	
	}
	
//    NumbersOnly(this.value,'שם פרטי')	
function NumbersOnly(txtValid, fieldname){
	re = /\D/;
	if (re.test(txtValid)==false)
	{
		return true;
		}
	else
	{
		alert('נא להכניס מספרים בלבד בשדה - '+fieldname)
		return false;
		}
	
	}
	
	function NotEmpty(txtValid,fieldname){
		
		if (txtValid=="")
		{
			alert('יש למלא את שדה - '+fieldname+' - זהו שדה חובה  ')
			return false;
			}
			else{
				return true;
				}
		
		}
		
		
	function MinLength(txtValid,reqSize,fieldname){		
		if (txtValid.length<reqSize)
			{
				alert('שדה '+fieldname+' אינו מלא')
				return false;
			}
		else
			{
			return true;
			}
		}
		
	function MaxLength(txtValid,reqSize,fieldname){		
		if (txtValid.length>reqSize)
			{
				alert('שדה '+fieldname+' ארוך מדי')
				return false;
			}
		else
			{
			return true;
			}
		}
		
		
			function MinValue(txtValid,reqSize,fieldname,ReqInfo){		
		if (txtValid<reqSize)
			{
				alert('שדה '+fieldname+' אינו יכול להיות קטן מ'+reqSize +" "+ReqInfo)
				return false;
			}
		else
			{
			return true;
			}
		}
		
			function MaxValue(txtValid,reqSize,fieldname){		
		if (txtValid>reqSize)
			{
				alert('שדה '+fieldname+' אינו יכול להיות גדול מ'+reqSize)
				return false;
			}
		else
			{
			return true;
			}
		}
		
			function ValueLimits(txtValid,MinSize,MaxSize,fieldname){		
		if (txtValid<MinSize || txtValid>MaxSize)
			{
				alert('שדה '+fieldname+' חייב להיות בגודל שבין:'+MinSize+' ל:'+MaxSize)
				return false;
			}
		else
			{
			return true;
			}
		}
		

function DoalWrite(user,domain){
var emailE=(user +'@' + domain)
document.write('<A href="mailto:' + emailE + '">' + emailE + '</a>')
}

function DoalWriteW(user,domain){
var emailE=(user +'@' + domain)
document.write('<A class="white" href="mailto:' + emailE + '">' + emailE + '</a>')
}

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}




function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}


function DateDiff(D1,M1,Y1,D2,M2,Y2){
var StartDate=new Date(Y1,M1,D1)
var EndDate=new Date(Y2,M2,D2)

if (EndDate.getTime()<=StartDate.getTime())
	{
	alert("תאריך הסיום מוקדם מתאריך ההתחלה")
	return false
	}
else
	{
	return true
	}

}

 function addMozillaPanel() {
      if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"))
      {
         window.sidebar.addPanel ("PrintMall",
         "http://www.printmall.co.il","");
      }
      else
      {
         window.alert("This sidebar for use with Mozilla.  ")
      }
   }


function toggle(item) {
	var obj = document.getElementById(item);
	var visible = (obj.style.display != "none");

	if(visible){
		obj.style.display = "none";
		} else {
		obj.style.display = "block";
		}
}



function IsVisible(item) {
	var obj = document.getElementById(item);
	var visible = (obj.style.display != "none");
	if(visible) 
		{
		return true
		}
		else
		{
		return false
		}
}




function toggleON(item) {
	var obj = document.getElementById(item);
	obj.style.display = "block";

}
function toggleOFF(item) {
	var obj = document.getElementById(item);
	obj.style.display = "none";

}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

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 replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }

    return str;
}

function SWclass(ObjID,newclass){
var Obj = O(ObjID)
Obj.style.className  = newclass
}

function OpenCell(Item_ID,AID){
var WinURL = "../Send_Cell_Download_Image.asp?ref="+AID+"&pop=1&Item_ID="+Item_ID
WinOpen(WinURL, '790',"460")
}


function altercontent(dcontent,NewTxt){

if (document.all){
var con = O(dcontent)
con.innerHTML=NewTxt;
}
else if (document.getElementById){
var rng = document.createRange();
var el = O(dcontent);
rng.setStartBefore(el);
var htmlFrag = rng.createContextualFragment(NewTxt);
while (el.hasChildNodes()) el.removeChild(el.lastChild);
el.appendChild(htmlFrag);}
}


//////////////////  Box Model

function addOvrDiv(){
var pr = document.getElementsByTagName("body")[0];

var newDiv1 = document.createElement("div"); 
var newDiv2 = document.createElement("div"); 
var newDiv3 = document.createElement("div"); 
var newDiv33 = document.createElement("div"); 
var newDiv4 = document.createElement("div"); 
var ap = document.createElement('a');


ap.setAttribute('href',"JavaScript:void(0)");
ap.setAttribute('title','Click to Close');
ap.setAttribute('onclick',"RemvOvrDiv()");
ap.onclick = function(){RemvOvrDiv()};
ap.setAttribute("class","green");
ap.setAttribute("className","green");
ap.appendChild(document.createTextNode("סגירה"));

newDiv1.setAttribute("id","modalPage");
newDiv2.setAttribute("class","modalBackground");
newDiv2.setAttribute("className","modalBackground");

newDiv3.setAttribute("id","modalContainer");
newDiv3.setAttribute("class","modalContainer");
newDiv3.setAttribute("className","modalContainer");

newDiv33.setAttribute("id","modalTop");
newDiv33.setAttribute("class","modalTop");
newDiv33.setAttribute("className","modalTop");
newDiv33.appendChild(ap)

newDiv4.setAttribute("id","modal");
newDiv4.setAttribute("class","modal");
newDiv4.setAttribute("className","modal");

newDiv1.appendChild(newDiv2)
newDiv1.appendChild(newDiv3)
newDiv3.appendChild(newDiv33)
newDiv3.appendChild(newDiv4)
pr.appendChild(newDiv1)


window.onscroll = function () { document.getElementById("modalPage").style.top = document.body.scrollTop;return false; };
document.getElementById("modalPage").style.display = "block";
document.getElementById("modalPage").style.top = document.body.scrollTop;


	}

function RemvOvrDiv(){
var bd = document.getElementsByTagName("body")[0];
var modalPage = O("modalPage")
bd.removeChild(modalPage)
	
	}


//////////////////  END  Box Model







function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
var bw=new checkBrowser()


function changeBc(obj,color){
 var div=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
	if(bw.dom || bw.ie4) div.backgroundColor=color;
	else if(bw.ns4) div.bgColor=color;
}


function RemoveDiv(id){
opacity(id, 100, 0, 1500)
setTimeout("toggleOFF('"+id+"')", 1550)
	
}


function SwitchZ(id,z){
	var obj = O(id)
	obj.style.zIndex = z
	}



function selectVal(id){
var SID = O(id)
return SID.options[SID.selectedIndex].value
}

function O(id){
return document.getElementById(id)
	}


function G(id){
return document.getElementById(id).value
	}
	
function S(id,val){
document.getElementById(id).value = val
}	




//////////////////// Opacity funcs

function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if(opacStart > opacEnd) {
        for(var i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(var i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) {
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 

function currentOpac(id, opacEnd, millisec) {
    var currentOpac = 100;
    if(document.getElementById(id).style.opacity < 100) {
        currentOpac = document.getElementById(id).style.opacity * 100;
    }
    opacity(id, currentOpac, opacEnd, millisec)
} 


function winW(){
var winW = 0
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
 }
}
return winW
}

function winH(){

var winH = 0

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winH = document.body.offsetHeight;
 }
}
return winH
}



/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

    obj : null,

    init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
    {
        o.onmousedown    = Drag.start;

        o.hmode            = bSwapHorzRef ? false : true ;
        o.vmode            = bSwapVertRef ? false : true ;

        o.root = oRoot && oRoot != null ? oRoot : o ;

        if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
        if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
        if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
        if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

        o.minX    = typeof minX != 'undefined' ? minX : null;
        o.minY    = typeof minY != 'undefined' ? minY : null;
        o.maxX    = typeof maxX != 'undefined' ? maxX : null;
        o.maxY    = typeof maxY != 'undefined' ? maxY : null;

        o.xMapper = fXMapper ? fXMapper : null;
        o.yMapper = fYMapper ? fYMapper : null;

        o.root.onDragStart    = new Function();
        o.root.onDragEnd    = new Function();
        o.root.onDrag        = new Function();
    },

    start : function(e)
    {
        var o = Drag.obj = this;
        e = Drag.fixE(e);
        var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
        o.root.onDragStart(x, y);

        o.lastMouseX    = e.clientX;
        o.lastMouseY    = e.clientY;

        if (o.hmode) {
            if (o.minX != null)    o.minMouseX    = e.clientX - x + o.minX;
            if (o.maxX != null)    o.maxMouseX    = o.minMouseX + o.maxX - o.minX;
        } else {
            if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
            if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
        }

        if (o.vmode) {
            if (o.minY != null)    o.minMouseY    = e.clientY - y + o.minY;
            if (o.maxY != null)    o.maxMouseY    = o.minMouseY + o.maxY - o.minY;
        } else {
            if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
            if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
        }

        document.onmousemove    = Drag.drag;
        document.onmouseup        = Drag.end;

        return false;
    },

    drag : function(e)
    {
        e = Drag.fixE(e);
        var o = Drag.obj;

        var ey    = e.clientY;
        var ex    = e.clientX;
        var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
        var nx, ny;

        if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
        if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
        if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
        if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

        nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
        ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

        if (o.xMapper)        nx = o.xMapper(y)
        else if (o.yMapper)    ny = o.yMapper(x)

        Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
        Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
        Drag.obj.lastMouseX    = ex;
        Drag.obj.lastMouseY    = ey;

        Drag.obj.root.onDrag(nx, ny);
        return false;
    },

    end : function()
    {
        document.onmousemove = null;
        document.onmouseup   = null;
        Drag.obj.root.onDragEnd(    parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
                                    parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
        Drag.obj = null;
    },

    fixE : function(e)
    {
        if (typeof e == 'undefined') e = window.event;
        if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
        if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
        return e;
    }
};


///////////  XHTP

function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}
