/// Query string Handler /////////////////////////////////////
//////////////////////////////////////////////////////////////
// Usage Sample :                                           //
//    var QueryString = new QSObject(window.location.href); //
//    alert(QueryString["sharon"]);                         //
//////////////////////////////////////////////////////////////

function QSObject(querystring){
	var qsReg = new RegExp("[?][^#]*","i");
	hRef = unescape(querystring);
	var qsMatch = hRef.match(qsReg);
	//removes the question mark from the url
	qsMatch = new String(qsMatch);
	qsMatch = qsMatch.substr(1, qsMatch.length -1);
	//split it up
	var rootArr = qsMatch.split("&");
	for(i=0;i<rootArr.length;++i){
	var tempArr = rootArr[i].split("=");
	if(tempArr.length ==2){
	tempArr[0] = unescape(tempArr[0]);
	tempArr[1] = unescape(tempArr[1]);

	this[tempArr[0]]= tempArr[1];
	}
	}
} 

function openDiv(controlId,opt)
{
	var div = document.getElementById(controlId);
	

	if(opt == "yes")
	{
		
		
		div.style.display = "";
	}
	else
	{
		
		div.style.display = "none";
	}
	
} 
//add to favorite
function addfav()
   {
   if (document.all)
      {
      window.external.AddFavorite
      (self.location,"Debis - " + " " + document.title)
      }
   }

function PrintScreen()
{
	this.print(false);
} // end func
function loadFlash()
{
    document.write('<OBJECT  id=pic_big3a codeBase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 height=131 width=269 align=middle classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 VIEWASTEXT><PARAM NAME="_cx" VALUE="9313"><PARAM NAME="_cy" VALUE="6482"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="/debis/Flash/calcul_ikons_3.swf" ><PARAM NAME="Src" VALUE="/debis/Flash/calcul_ikons_3.swf" style="TEXT-DECORATION: none"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE="sameDomain"><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE="FFFFFF"><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0">');
    document.write('<embed src="/debis/Flash/calcul_ikons_3.swf"  border="0" quality="high" bgcolor="#ffffff" width="269" height="131" name="calcul_ikons_3" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</OBJECT>');
}
function loadSideFlash()
{
   document.write('<span id=side_flash></span>');
   document.write('&nbsp;<BR/>');

   return;

   //fix 06122009
   var banners_path_arr = '/debis/Flash/Homepage/28891_130x200.swf'
   //07/01/2010 bennysa
   var multiFlash = new LoadMultiFlash(banners_path_arr, 17000, 130, 200, document.getElementById('side_flash'));
   multiFlash.StartRun();
}
function loadBigFlash()
{
    document.write('<OBJECT  id=pic_big3a codeBase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 height=245 width=352 align=middle classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 VIEWASTEXT><PARAM NAME="_cx" VALUE="9313"><PARAM NAME="_cy" VALUE="6482"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="/debis/Flash/DEBIS_home.swf" ><PARAM NAME="Src" VALUE="/debis/Flash/Homepage/hyundai_352x245.swf" style="TEXT-DECORATION: none"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE="sameDomain"><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE="FFFFFF"><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0">');
    document.write('<embed src="/debis/Flash/Homepage/hyundai_352x245.swf"  border="0" quality="high" bgcolor="#ffffff" width="245" height="352" name="DEBIS_home" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</OBJECT>');
}
function loadsochenFlash()
{
    document.write('<OBJECT id=pic_big3a codeBase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 height=147 width=130 align=middle classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 VIEWASTEXT><PARAM NAME="_cx" VALUE="9313"><PARAM NAME="_cy" VALUE="6482"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="/debis/Flash/sochen.swf" ><PARAM NAME="Src" VALUE="/debis/Flash/sochen.swf" style="TEXT-DECORATION: none"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE="sameDomain"><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE="FFFFFF"><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0">');
    document.write('<embed src="/debis/Flash/sochen.swf"  border="0" quality="high" bgcolor="#ffffff" width="269" height="131" name="sochen" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</OBJECT>');
}

//banners_path_arr - path of banners, split by ;
//time_to_run      - time to show each flash
//width            - flash width
//height           - flash height
//objectToFill     - object to fill with the flash (innerHTML) else null
function LoadMultiFlash(banners_path_arr, time_to_run, width, height, objectToFill)
{
    //bennysa: fix for now, show only the first banner...
    this.paths_arr          = banners_path_arr.split(';');//banners_path_arr.split(';');
    this.prefix_id          = Math.floor(Math.random()* 1000 );
    this.active_banner      = Math.floor(Math.random()* this.paths_arr.length+1 ) - 1
    this.time_to_run        = time_to_run;
    this.StartRun           = StartRun;
    this.RunBannerControls  = RunBannerControls;
    this.RenderControl      = RenderControl;
    this.width              = width;
    this.height             = height;
    this.firstRender        = true;
    this.objectToFill       = objectToFill
    this.id_settimeout      = 0;
    
    function StartRun()
    { 
       this.RunBannerControls(this);
    }
    
    function RunBannerControls(thisObj)
    {
        RenderControl(thisObj);

        if(this.active_banner == this.paths_arr.length-1)
            this.active_banner = 0;
        else
            this.active_banner = this.active_banner + 1;
       
         //this.id_settimeout = setTimeout(function() { thisObj.RunBannerControls(thisObj); }, this.time_to_run);
    }
    
    function RenderControl(thisObj)
    {
        if( thisObj.id_settimeout > 0 )
            clearTimeout(thisObj.id_settimeout);
        
        var spn_id       = 'spn_banner_' + thisObj.prefix_id;
        var need_to_fill = thisObj.objectToFill != null && typeof(thisObj.objectToFill) != 'undefined';
        
        if(need_to_fill)
            spn_id = thisObj.objectToFill.id;
            
        var spnInnerHtml = "";
        
        if(thisObj.firstRender && !need_to_fill)
            document.write('<SPAN  id="' + spn_id + '">');
        else
            document.getElementById(spn_id).innerHTML = "";
        
        spnInnerHtml = '<OBJECT codeBase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 height=' + thisObj.height + ' width=' + thisObj.width + ' align=middle classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 VIEWASTEXT><PARAM NAME="_cx" VALUE="9313"><PARAM NAME="_cy" VALUE="6482"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="' + thisObj.paths_arr[thisObj.active_banner] + '" ><PARAM NAME="Src" VALUE="' + thisObj.paths_arr[thisObj.active_banner] + '" style="TEXT-DECORATION: none"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE="sameDomain"><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE="FFFFFF"><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0">';
        spnInnerHtml += '<embed src="' + thisObj.paths_arr[thisObj.active_banner] + '"  border="0" quality="high" bgcolor="#ffffff" width="'+ thisObj.width +'" height="' + thisObj.height + '" name="sochen" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        spnInnerHtml += '</OBJECT>';
        
        if(thisObj.firstRender && !need_to_fill)
        {
            document.write('</SPAN>');
            thisObj.firstRender = false;
        }
            
        document.getElementById(spn_id).innerHTML = spnInnerHtml;
    }
}

/*
 * validateForm - For use in conjunction with InfraWise inputField Validator
 */
function validateForm(form)
{
	
	if (!form)
		{form=window.document.forms[0].id}
	
	var rtn=true;
	
	var inputFields=window.document.forms[form].tags('input');	
	for (i=inputFields.length-1; i>=0; --i)
	{
		if (inputFields[i].className.indexOf('IWInputField')>-1)
		{
			
			if (!inputFields[i].isValid())
			{
				rtn=false;								
			}
		}
	}
	
	return rtn;
}

function onLoadFunction()
{
	// set focus on the first input in page (if exist)
	var inputCollection = document.getElementsByTagName("INPUT");
	var i = 0;
	var stop = false;
	
	
	while (!stop && i<inputCollection.length)
	{
		if (inputCollection[i].type == "text")
		{
			inputCollection[i].focus();
			stop = true;
		}
		++i
	}
}

function f_showMsg(as_msg,al_icon,as_title)  {
	//var ll_rc=window.showModalDialog("msgWin.asp?msg=" + as_msg + "&icon=" + al_icon +"&title=" + as_title,"","dialogHeight:150px;dialogWidth:330px;help:no;resizable:no;status:no;scroll:no;")
	//return ll_rc;
	alert(as_msg);
}

// confirming the delete action does not invoke a delete action,
// it sends relevant information in the querystring,
// and the decision whether to use this info or not is taken in the server side 
function confirmDelete(msg,deletePostingGuid)
{
	//alert('nir');

	if (confirm(msg))
	{
		var curUrl = document.location.href;

		if(curUrl.indexOf('?') < 0)
		{
			curUrl += "?";
		}
		
		curUrl += "&deletePostingGuid=" + deletePostingGuid;
		document.location.href = curUrl;
	}
	
	else 
	{
		location.href = '#';
	}
}

function changeImage(ctrl,parmeter)
{
	if(parmeter == 'on')
	{
		ctrl.src = ctrl.src.replace(".gif","_on.gif");
	}

	else
	{
		ctrl.src = ctrl.src.replace("_on","");
	}
}

function handleDescQuestions(trNumbers)
{
    if(typeof(trNumbers) == 'undefined' || typeof(trNumbers) != 'object' || trNumbers.length == 0)
        return;

    for(var i = 0 ; i < trNumbers.length ; i++)
        handleDescQuestion(null, trNumbers[i]);
}

function handleDescQuestion(imgObj, trNumber)
{
	var descTD = document.getElementById("FAQCollector1_desc_" + trNumber);
	
	if( descTD == null )
	    return;
	
	var beforeStyle = descTD.style.display;
	var allTR = document.getElementsByTagName("TR");
	//benny
	/*for(i = 0 ; i < allTR.length ; ++i)
	{
		if(allTR[i].id.indexOf("FAQCollector1_desc_") > -1)
		{
			if(allTR[i].style.display == "")
			{
				allTR[i].style.display = "none";
			}
		}	
	}*///benny
	
	if (beforeStyle == "none")
	{
		descTD.style.display = "";

		/*if (tdNumber % 2 == 0)
		{	
			imgObj.src = imgObj.src.replace("answer.gif", "CloseDark.gif");
		}
		else
		{
			imgObj.src = imgObj.src.replace("answer.gif", "CloseLight.gif");
		}*/
	}

	else 
	{
		descTD.style.display = "none";		
		/*if (tdNumber % 2 == 0)
		{	
			imgObj.src = imgObj.src.replace("CloseDark.gif", "answer.gif");
		}
		else
		{
			imgObj.src = imgObj.src.replace("CloseLight.gif", "answer.gif")
		}*/
	}
}

function isNullOrUndefined ( o )
{
    var isNullOrUndefined = ( o === null )      || ( o == null )      ||
                            ( o === undefined ) || ( o == undefined ) ||
                            ( typeof( o ) == "undefined" );
    return isNullOrUndefined;
}

function notNullOrUndefined (o)
{
    var notNullOrUndefined = (!isNullOrUndefined(o));
    return notNullOrUndefined;
}

if (!document.getElementById) {
	document.getElementById=function (id) {
		if (document.all) {
			return document.all[id];
		}
	}
}
function changeStyle(myTR,newClass)
{
	
	myTR.className = newClass;
}

var calendarDiv=null;
function toggleCalendar(fieldToUpdate,XPlace,YPlace)
{
	if (calendarDiv==null)				// Construct the calendar for the 1st time
	{
		
		var startYear = 1930;
		var endYear = 2030;
		
		if(location.href.indexOf("OrderMaintain")>-1)
		{
			
			var d = new Date();
			startYear = d.getFullYear();
		}
		if(location.href.indexOf("UpdateDetails")>-1)
		{
		
			var d = new Date();
			endYear = d.getFullYear();
		}
		
		
		calendarDiv=document.createElement("div");
		calendarDiv.style.position='absolute';
		calendarDiv.setAttribute("MINYEAR",startYear);//ששש // year 2000 - 120 years = 1880
		calendarDiv.setAttribute("MAXYEAR",endYear);			
		calendarDiv.setAttribute("UPDATE","");
		calendarDiv.className="calendar";
		calendarDiv.setAttribute("showTitle","false");			
		calendarDiv.setAttribute("Status","init");			
		calendarDiv.style.display="none";
		
		document.getElementById('mainDiv').appendChild(calendarDiv);
	}
		
	if (calendarDiv.style.display=="none" || calendarDiv.attributes["UPDATE"].value!=fieldToUpdate)
	{									
		if (calendarDiv.style.display=="inline")
			calendarDiv.hide();			
		//calendarDiv.style.pixelLeft=event.clientX-200;
		//calendarDiv.style.pixelTop=event.clientY+20+document.body.scrollTop;		
		if (isNullOrUndefined(XPlace))
		{
					XPlace = 200;
		}
		if (isNullOrUndefined(YPlace))
		{
			XPlace = 20;
		}
		calendarDiv.style.pixelLeft=event.clientX - parseInt(XPlace);
		
		calendarDiv.style.pixelTop=event.clientY+ parseInt(YPlace) +document.body.scrollTop;
		
		calendarDiv.setAttribute("UPDATE",fieldToUpdate);
		
		if (calendarDiv.attributes["Status"].value!="init")
			calendarDiv.refresh();			
			
		calendarDiv.style.display="inline";			
	}		
	else
	{
		calendarDiv.hide();			
	}
}
