//
// txt_name_position(ident,text)
//



function priceField(elm) {

    var el = $(elm);
    
    el.onkeydown = function(e) { return enterDigit(e);  }
    el.onblur = function(e) {
         
        el.value = numberToPrice(el.value); 
        }
    el.onfocus = function(e)  { el.value = priceToNumber(el.value); }
    
    el.value = numberToPrice(el.value);  
    
}


function elToNumber(id) {
    
    var el = $(id);
    el.value = priceToNumber(el.value);
}


function priceToNumber(pr) {
        
        
        pr = pr.replace(/\,/g, '');
        pr = pr.replace(/\$/, '');
        
        if(pr != '') {
            pr = parseInt(pr);
        }
        if(pr == 'NaN') {
            pr = false;
        }
            
        return pr;
}


function enterDigit(e) { 
   
    e=e||window.event;
    
    var key = e.keyCode;

    if (key == 8 || key == 46 || key == 35 || key == 36 || key == 37 || key == 39 || key == 9 || key == 17 || key == 18 || key == 116) return true;
    if ((key < 45 || key > 57) && (key < 95 || key > 106)) return false;

}

function numberToPrice(n){

        if(!n) { return ''; }
        
        
        var temp = priceToNumber(n);
        var s = Number(temp).toFixed(2);

        for (var i = s.length / 3 - 2; i > 0; i--) {
            s = s.replace(/(\d)(\d{3}[^\d])/, "$1,$2");
        }
        s = s.replace(/(.00)$/, '');
        
        if(s != 0 || s != false) {
        s = '$' + s;
        } else { s = '';}
        
        return s;
}







function txt_name_position(ident,text){
	var k = text.length;
	if(k > 35) {
		var new_text = text.substr(0,35)+"...";
	} else {
		var new_text = text;
	}
	$(ident).innerHTML = new_text;

}

function txt_name_position2(ident,text){
    var k = text.length;
    if(k > 48) {
        var new_text = text.substr(0,48)+"...";
    } else {
        var new_text = text;
    }
    $(ident).innerHTML = new_text;

}

function checkClick(control) {
    
    var id  = control.id;
    var i = '';
    
    var cid = control.previousSibling;
    
    if(cid.checked) { i = 1; }
    control.style.backgroundImage = 'url("img/v4/but_chekbox'+i+'.gif")';
    cid.checked = !cid.checked;
}


function datetime_update(){
	var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var d = new Date();
	var datetime = $('datetime');
	var date = d.getDate();
	var year = d.getFullYear();
	var hour = d.getHours();
	var minute = d.getMinutes();
	var day = days[d.getDay()];
	var month = months[d.getMonth()];
	if(minute < 10) minute = "0" + minute;
	datetime.innerHTML = "" + day + ", " + month + " " + date + ", " + year + " "+hour+":"+minute;
	setTimeout("datetime_update()", (60 - d.getSeconds())*1000);
}

function disclaimerRadioCheck(element,ielement,k){
	for(var i = 0;i<k;i++){
		$(ielement+i).className = "radio";
	}
	$(element).className = "radiochecked";
}

function disclaimerButtonCheck(val){
//alert(val);

	if(val == "y"){
    
        $('next_disabled').hide();
        $('button_next').show();

		if(navigator.appName == "Microsoft Internet Explorer"){
		$('button_next').setAttribute("onclick",new Function ("$('f').submit();")); // для IE
		} else {
		
		$('button_next').setAttribute("onclick","$('f').submit();");   // для Mozilla, Opera
		}
		$('accept').value = "y";
	} else {
    
        $('button_next').hide();
        $('next_disabled').show();
        
    
		if(navigator.appName == "Microsoft Internet Explorer"){
		$('button_next').setAttribute("onclick",new Function ("alert('задизейбленая')")); // для IE
		} else {
		$('button_next').setAttribute("onclick","alert('задизейбленая2')");   // для Mozilla, Opera
		}
		$('accept').value = "n";
		//alert('задизейбленая');

	}
}






















//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function lostpwd(){
if($('my_login') != "" && $('my_email') != ""){        
    new Ajax.Request('index.php',
  {
    method:'post',
    parameters: $('flostpwd').serialize(false),

    onSuccess: function(transport){
    
      var response = transport.responseText || "no response";
                   
      if(response == "0"){
         $('loading').src = done_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loading').src = "img/v4/0.gif";
                        $('loading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + done_image.src+ '",sizingMethod="scale")';
                    }
         $('loading').style.width = '64px';
         $('loading').style.height = '69px';
         $('forgotpwd-alert-loading-span').innerHTML = 'Password successfully sent to your email';
         $('forgotpwd-alert-loading-span').style.marginTop = '30px';               
         $('loading').style.marginLeft = '140px';
        $('loading').style.marginTop = '10px';
        $('forgotpwd-alert-loading').innerHTML = $('forgotpwd-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';
      }
      if(response == "1"){
         $('loading').src = undone_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loading').src = "img/v4/0.gif";
                        $('loading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + undone_image.src+ '",sizingMethod="scale")';
                    }
         $('loading').style.width = '88px';
         $('loading').style.height = '72px';
         $('forgotpwd-alert-loading-span').innerHTML = 'Your login or e-mail was incorrect';      
         $('forgotpwd-alert-loading-span').style.marginTop = '30px';
         $('loading').style.marginLeft = '140px';
        $('loading').style.marginTop = '10px';
        $('forgotpwd-alert-loading').innerHTML = $('forgotpwd-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';
      }
      
      
    },
    onFailure: function(){ alert('Something went wrong...') }
  });    
  $('forgotpwd-body').innerHTML = '<div id="forgotpwd-alert-loading"><img src="img/v4/0.gif" id="loading" alt="" border="0" width="164" height="28"/><div id=    "forgotpwd-alert-loading-span">Please wait! Sending data...</div></div>';
  $('loading').src = loading_image.src;
  $('loading').style.width = '168px';
  $('loading').style.height = '28px';
  $('loading').style.marginLeft = '100px';
  $('loading').style.marginTop = '30px';
  $('forgotpwd-alert-loading-span').style.marginTop = '30px'; 
  
  }
}

function changepwd(){
if($('old_pass').value != "" && $('new_pass').value != "" && $('new_pass2').value != ""){
  new Ajax.Request('change_password.php',
  {
    method:'post',
    parameters: {
        'change_password' : 'update',
        'old_pass': $('old_pass').value,
        'new_pass': $('new_pass').value,
        'new_pass2': $('new_pass2').value
    },

    onSuccess: function(transport){
      var response = transport.responseText || "no response";
      //alert(response);             
      if(response == "0"){
         $('loading').src = done_image.src;
         if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loading').src = "img/v4/0.gif";
                        $('loading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + done_image.src+ '",sizingMethod="scale")';
         }
         $('loading').style.width = '64px';
         $('loading').style.height = '69px';
         $('forgotpwd-alert-loading-span').innerHTML = 'Password successfully changed';
         $('loading').style.marginLeft = '140px';
        $('loading').style.marginTop = '10px';
        $('forgotpwd-alert-loading').innerHTML = $('forgotpwd-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';     
      }
      if(response == "1"){
         $('loading').src = undone_image.src;
         if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loading').src = "img/v4/0.gif";
                        $('loading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + undone_image.src+ '",sizingMethod="scale")';
         }
         $('loading').style.width = '88px';
         $('loading').style.height = '72px';
         $('forgotpwd-alert-loading-span').innerHTML = _ONCHANGE_PWD_INCORRECT_;      
         $('loading').style.marginLeft = '140px';
        $('loading').style.marginTop = '10px';
      $('forgotpwd-alert-loading').innerHTML = $('forgotpwd-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';
      }
      if(response == "2"){
         $('loading').src = undone_image.src;
         if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loading').src = "img/v4/0.gif";
                        $('loading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + undone_image.src+ '",sizingMethod="scale")';
         }
         $('loading').style.width = '88px';
         $('loading').style.height = '72px';
         $('forgotpwd-alert-loading-span').innerHTML = PASSWORD_DONOT_MATCH;      
         $('loading').style.marginLeft = '140px'; 
        $('loading').style.marginTop = '10px';
        $('forgotpwd-alert-loading').innerHTML = $('forgotpwd-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';     
      } 
      if(response == "3"){
         $('loading').src = undone_image.src;
         if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loading').src = "img/v4/0.gif";
                        $('loading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + undone_image.src+ '",sizingMethod="scale")';
         }
         $('loading').style.width = '88px';
         $('loading').style.height = '72px';
         $('forgotpwd-alert-loading-span').innerHTML = PASSWORD_TOOSHORT;      
         $('loading').style.marginLeft = '140px'; 
        $('loading').style.marginTop = '10px';   
        $('forgotpwd-alert-loading').innerHTML = $('forgotpwd-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';
      }  
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
  $('forgotpwd-body').innerHTML = '<div id="forgotpwd-alert-loading"><img src="img/v4/0.gif" id="loading" alt="" border="0" width="164" height="28"/><div id=    "forgotpwd-alert-loading-span">Please wait! Sending data...</div></div>';
  $('loading').src = loading_image.src;
  $('loading').style.width = '168px';
  $('loading').style.height = '28px';
  $('loading').style.marginLeft = '115px';
  $('loading').style.marginTop = '30px';
  $('forgotpwd-alert-loading-span').style.marginTop = '30px'; 
  }
}

function rateuser(){
    new Ajax.Request('main.php?SendRaitingUrl=true',
        {
            method:'post',
            parameters: {
                'uid': $('user_id').value,
                'uname': $('user_name').value,
                'uemail': $('user_email').value
            },    
            onSuccess: function(transport){
                var response = transport.responseText || "no response";
                //alert("DEBUG: "+response);
                if(response == "0"){
    
                    $('rloading').src = done_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('rloading').src = "img/v4/0.gif";
                        $('rloading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + done_image.src+ '",sizingMethod="scale")';
                    }
                    $('rloading').style.width = '64px';
                    $('rloading').style.height = '69px';
                    $('rloading').className = 'png';
                    $('rateuser-alert-loading-span').innerHTML = 'Email with URL for providing reference has been successfully sent.';
                    $('rateuser-alert-loading-span').style.marginTop = '2px';
                    $('rloading').style.marginLeft = '144px';
                    //$('rloading').style.marginBottom = '-15px';
                    $('rloading').style.marginTop = '20px';        
                    $('rateuser-alert-loading').innerHTML = $('rateuser-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';   
                } else if(response == "1"){
                    alert("3");
                    $('rloading').src = undone_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('rloading').src = "img/v4/0.gif";
                        $('rloading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + undone_image.src+ '",sizingMethod="scale")';
                    }
                    $('rloading').style.width = '88px';
                    $('rloading').style.height = '72px';
                    $('rateuser-alert-loading-span').innerHTML = 'Can not send email.';      
                    $('rateuser-alert-loading-span').style.marginTop = '2px';
                    $('rloading').style.marginLeft = '134px';
                    $('rloading').style.marginTop = '20px';
                    $('rateuser-alert-loading').innerHTML = $('rateuser-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';
                    //$('rloading').style.marginBottom = '-15px';
                }
            },
            onFailure: function() { alert('Something went wrong...');}
        });
    
    $('rateuser-body').innerHTML = '<div id="rateuser-alert-loading"><img src="img/v4/0.gif" id="rloading" alt="" border="0" width="164" height="28"/><div id=    "rateuser-alert-loading-span">Please wait! Sending url to your email...</div></div>';
    $('rloading').src = loading_image.src;
    $('rloading').style.width = '168px';
    $('rloading').style.height = '28px';
    $('rloading').style.marginLeft = '95px';
    $('rloading').style.marginTop = '50px';         
}

function send_areport(id){
    new Ajax.Request('main.php?SendReport=true',
        {
            method:'post',
            parameters: {
                'uid': id,
                'motivation': $('motivations').value
            },    
            onSuccess: function(transport){
                var response = transport.responseText || "no response";
                //alert("DEBUG: "+response);
                if(response == "0"){
                    $('rloading').src = done_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('rloading').src = "img/v4/0.gif";
                        $('rloading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + done_image.src+ '",sizingMethod="scale")';
                    }
                    $('rloading').style.width = '64px';
                    $('rloading').style.height = '69px';
                    $('rateuser-alert-loading-span').innerHTML = 'Abuse report successfully sent.';
                    $('rloading').style.marginLeft = '144px';
                    $('rloading').style.marginBottom = '-15px';
                    $('rloading').style.marginTop = '20px';  
                    $('rateuser-alert-loading').innerHTML = $('rateuser-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';                    
                } else if(response == "1"){
                    $('rloading').src = undone_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('rloading').src = "img/v4/0.gif";
                        $('rloading').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + undone_image.src+ '",sizingMethod="scale")';
                    }
                    $('rloading').style.width = '88px';
                    $('rloading').style.height = '72px';
                    $('rateuser-alert-loading-span').innerHTML = 'Can not send report.';      
                    $('rloading').style.marginLeft = '134px';
                    $('rloading').style.marginTop = '20px';
                    $('rloading').style.marginBottom = '-15px';
                    $('rateuser-alert-loading').innerHTML = $('rateuser-alert-loading').innerHTML + '<div align="right" style="margin-right:15px;margin-top:10px;"><input type="button" value="" class="nc-userdetails-popupclose" onclick="$(\'overlay\').style.display=\'none\';return hs.close(this);" onMouseUp="this.style.backgroundPosition=\'0px -19px\'" onMouseDown="this.style.backgroundPosition=\'0px -38px\'" onMouseOut="this.style.backgroundPosition=\'0px 0px\'" onMouseOver="this.style.backgroundPosition=\'0px -19px\'"></div>';
                }
            },
            onFailure: function() { alert('Something went wrong...');}
        });
    $('rabuse-body').innerHTML = '<div id="rateuser-alert-loading"><img src="img/v4/0.gif" id="rloading" alt="" border="0" width="164" height="28"/><div id="rateuser-alert-loading-span">Please wait! Sending report...</div></div>';
    $('rloading').src = loading_image.src;
    $('rloading').style.width = '168px';
    $('rloading').style.height = '28px';
    $('rloading').style.marginLeft = '95px';
    $('rloading').style.marginTop = '50px';
}


function yn_ansverRadioCheck(element,ielement,k){
    for(var i = 0;i<k;i++){
        $(ielement+i).className = "radio";
    }
    $(element).className = "radiochecked";
}

function yn_answerButtonCheck(el,val){
    $(el).value = val;
}

function appSendComment(id){
    new Ajax.Request('view_application.php?id='+id,
        {
            method:'post',
            parameters: {
                'actAddComment': 'Update',
                'comment': $('comment').value
            },    
            onSuccess: function(transport){
                var response = transport.responseText || "no response";
                //alert("DEBUG: "+response);
                if(response == "0"){
                    $('loadingImage').src = done_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loadingImage').src = "img/v4/0.gif";
                        $('loadingImage').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + done_image.src+ '",sizingMethod="scale")';
                    }
                    $('loadingImage').style.width = '64px';
                    $('loadingImage').style.height = '69px';
                    $('loadingImage').style.marginTop = '20px';
                    if(!$('loadingText')){
                    var boo = document.createElement('div');
                    boo.setAttribute('id','loadingText');
                    boo.className = 'nc-viewapplication-label';
                    $('commentloading').appendChild(boo);
                    boo.style.marginTop = '5px';
                    boo.innerHTML = 'Saved';      
                    }
                    setTimeout("Effect.Fade('commentloadingdiv',{from:0.6,to:0.0})",2000);
                    
                } else if(response == "1"){
                    $('loadingImage').src = undone_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loadingImage').src = "img/v4/0.gif";
                        $('loadingImage').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + undone_image.src+ '",sizingMethod="scale")';
                    }
                    $('loadingImage').style.width = '88px';
                    $('loadingImage').style.height = '72px';
                    $('loadingImage').style.marginTop = '20px';
                    if(!$('loadingText')){  
                    var boo = document.createElement('div');
                    boo.setAttribute('id','loadingText');
                    boo.className = 'nc-viewapplication-label';
                    $('commentloading').appendChild(boo);
                    boo.style.marginTop = '5px';
                    boo.innerHTML = 'Error saving';  
                    }                 
                    setTimeout("Effect.Fade('commentloadingdiv',{from:0.6,to:0.0})",2000);
                }
            },
            onFailure: function() { alert('Something went wrong...');}
        });                          
    
    Effect.Appear('commentloadingdiv',{from:0.0,to:0.6});
    if(!$('loadingImage')){
    var simg = document.createElement("img");
    simg.setAttribute('id','loadingImage');
    $('commentloading').appendChild(simg);
    }
    $('loadingImage').src=loadingsmall.src;  
    $('loadingImage').style.marginTop = '60px';
}

function appSendEmail(id){
    new Ajax.Request('view_application.php?id='+id,
        {
            method:'post',
            parameters: {
                'actSendEmail': 'Send',
                'subject': $('subject').value,
                'message': $('message').value
            },    
            onSuccess: function(transport){
                var response = transport.responseText || "no response";
                //alert("DEBUG: "+response);
                if(response == "0"){
                    $('loadingImage2').src = done_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loadingImage2').src = "img/v4/0.gif";
                        $('loadingImage2').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + done_image.src+ '",sizingMethod="scale")';
                    }
                    $('loadingImage2').style.width = '64px';
                    $('loadingImage2').style.height = '69px';
                    $('loadingImage2').style.marginTop = '20px';
                    if(!$('loadingText2')){
                    var boo2 = document.createElement('div');
                    boo2.setAttribute('id','loadingText2');
                    boo2.className = 'nc-viewapplication-label';
                    $('commentloading2').appendChild(boo2);
                    }
                    boo2.style.marginTop = '5px';
                    boo2.innerHTML = 'Sent';
                    setTimeout("Effect.Fade('commentloadingdiv2',{from:0.6,to:0.0})",2000);
                    $('subject').value = '';
                    $('message').value = '';
                    bdisabled = '1';
                    $('sendmsg').style.backgroundPosition = '0px -57px';
                } else if(response == "1"){
                    $('loadingImage2').src = undone_image.src;
                    if(navigator.appName == "Microsoft Internet Explorer"){
                        $('loadingImage2').src = "img/v4/0.gif";
                        $('loadingImage2').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + undone_image.src+ '",sizingMethod="scale")';
                    }
                    $('loadingImage2').style.width = '88px';
                    $('loadingImage2').style.height = '72px';
                    $('loadingImage2').style.marginTop = '20px';
                    if(!$('loadingText2')){
                    var boo = document.createElement('div');
                    boo2.setAttribute('id','loadingText2');
                    boo2.className = 'nc-viewapplication-label';
                    $('commentloading2').appendChild(boo2);
                    }
                    boo2.style.marginTop = '5px';
                    boo2.innerHTML = 'Error saving';                   
                    setTimeout("Effect.Fade('commentloadingdiv2',{from:0.6,to:0.0})",2000);
                    $('subject').value = '';
                    $('message').value = '';
                    bdisabled = '1';
                    $('sendmsg').style.backgroundPosition = '0px -57px';
                }
            },
            onFailure: function() { alert('Something went wrong...');}
        });                          
    
    Effect.Appear('commentloadingdiv2',{from:0.0,to:0.6});
    if(!$('loadingImage2')){
    var simg2 = document.createElement("img");
    simg2.setAttribute('id','loadingImage2');
    }
    $('commentloading2').appendChild(simg2);
    $('loadingImage2').src=loadingsmall.src;  
    $('loadingImage2').style.marginTop = '60px';
}



function validatesearch(f){
    if($('query').value == '') {
        return false;
    }
}

function blockError() {
    return true;
}
window.onerror = blockError;


var parentNodeCount = 0;
var nodeCount = 0;

function onParentNodeImageClick(node) {
    var divNode = $(node.name.replace("parentNodeImage","parentNodeDiv"));
    var imageNode = node;

     if (divNode.style.display == "none"){
        imageNode.src = "img/v4/minus.gif";
        divNode.style.display = "block";
    }
    else {
        imageNode.src = "img/v4/plus.gif";
        divNode.style.display = "none";
    }
}
function onParentNodeTextClick(node,id) {
    if($('catid_'+id).value == "0"){
        node.style.backgroundColor = '#62c8db';
        node.style.color = '#ffffff';
        $('catid_'+id).value = "1";
        
        var anchors = document.getElementsByTagName('input');
        for (var i=0; i<anchors.length; i++){
            var relAttribute = String(anchors[i].getAttribute('alt'));
            if (relAttribute.toLowerCase().match('pcat_'+id)){
                anchors[i].value = '0';
            }
        }
        el = document.getElementsByClassName('tdpcat_'+id);
                for(var j = 0;j<el.length;j++){
                    el[j].style.backgroundColor = '#ffffff';
                    el[j].style.color = '#336699';
                }
    } else {
        node.style.backgroundColor = '#ffffff';
        node.style.color = '#336699';
        $('catid_'+id).value = "0";
    }
}

function onNodeTextClick(node,id,cid) {
    if($('scatid_'+id).value == "0"){
        $('scatid_'+id).value = "1";
        $('catid_'+cid).value = "0";
        $('catidtd_'+cid).style.backgroundColor = '#e5f9fc';
        $('catidtd_'+cid).style.color = '#336699';
        node.style.backgroundColor = '#62c8db';
        node.style.color = '#336699';
    } else {
        node.style.backgroundColor = '#ffffff';
        node.style.color = '#336699';
        $('scatid_'+id).value = "0";
    }
}
function onNodeImageClick(node, url, target){
    var imageNode = node
    setSelectedNode(imageNode);
}

function setSelectedNode(imageNode){
       imageNode.src = "img/v4/0.gif";
}

function startParentNode(text, id, sel,name){
    
    document.write('<table border="0" cellpadding="1" cellspacing="0">');
    document.write('  <tr>');
    document.write('    <td><img src="img/v4/plus.gif" id="catidimg_'+id+'" name="parentNodeImage' + parentNodeCount + '" onclick="onParentNodeImageClick(this)" style="cursor:pointer;"/></td>');
    document.write('<input type="hidden" id="catid_'+id+'" value="'+sel+'" name="'+name+'['+id+']"/>');
    if(sel == 1){
        var style = 'background-color:#62c8db;color:#ffffff;';
    } else {
        var style = 'background-color:#ffffff;color:#336699;';
    }
    document.write('    <td class="parentTreeNode" id="catidtd_'+id+'" onclick="onParentNodeTextClick(this,'+id+')" style="height:18px;cursor:pointer;'+style+'">');//<a  name="parentNodeText' + parentNodeCount + '" >
    document.write(text);
    document.write('  </td>');
    document.write('  </tr>');
    document.write('  <tr>');
    document.write('    <td></td><!-- SPACING -->');
    document.write('    <td><DIV id="parentNodeDiv' + parentNodeCount + '" style="display:none;">');    
    this.parentNodeCount = this.parentNodeCount + 1;
}
function endParentNode(){
    document.write('</DIV></td>');
    document.write('  </tr>');
    document.write('</table>');
}
function addNode(text, url, target, id, cid, sel,name){
   // alert(sel);
    if(sel == 1){
        var style = 'background-color:#62c8db;color:#ffffff;';
    } else {
        var style = 'background-color:#ffffff;color:#336699;';
    }
     if(sel == 1){
    $('catidtd_'+cid).style.backgroundColor = '#e5f9fc';
    $('catidtd_'+cid).style.color = '#ffffff';
        $('catid_'+cid).value = "0"
        var anchors = document.getElementsByTagName('input');
        for (var i=0; i<anchors.length; i++){
            var relAttribute = String(anchors[i].getAttribute('alt'));
            if (relAttribute.toLowerCase().match('pcat_'+cid)){
                anchors[i].value = '1';
            }
        }
        
        el = document.getElementsByClassName('tdpcat_'+cid);
        for(var j = 0;j<el.length;j++){
            //alert(el[j].parentNode.innerHTML);
            el[j].parentNode.style.backgroundColor = '#ffffff';
            el[j].parentNode.style.color = '#336699';
        }
        
        var divNode = $($('catidimg_'+cid).name.replace("parentNodeImage","parentNodeDiv"));
    var imageNode = $('catidimg_'+cid);
        imageNode.src = "img/v4/minus.gif";
        divNode.style.display = "";
     } 
    
    document.write('<table border="0" cellpadding="1" cellspacing="0">');
    document.write('  <tr>');
    document.write('    <td>');
    document.write('<img src="img/v4/0.gif" border="0" name="nodeImage' + this.nodeCount + '" onclick="onNodeImageClick(this);" />');
    document.write('    </td>');
    document.write('<td class="normalTreeNode tdpcat_'+cid+'" onclick="onNodeTextClick(this,'+id+','+cid+');" onfocus="this.hideFocus=true;" style="height:18px;outline-style:none;cursor:pointer;padding:0px;padding-left:2px;margin-top:-2px;margin-bottom:-2px;'+style+'"><input type="hidden" id="scatid_'+id+'" value="'+sel+'" name="'+name+'['+id+']" alt="pcat_'+cid+'"/>' + text + '</td>');//<a name="nodeText' + this.nodeCount + '"  href="' + url + '" target="' + target + '"  ></a>
    document.write('  </tr>');
    document.write('</table>');  
    this.nodeCount = this.nodeCount + 1;
}

/**
 *
 *
 *
 */

 function deleteApplication(id){
	if(window.confirm("Do you want to delete this application?")){
		
		var element_id = 'row_'+id;

		new Ajax.Request('applications.php',
		  {
		      method:'get',
		      parameters: {act:'delete',aid:id},
		          onSuccess: function(transport){
			      var response = transport.responseText || "no response text";
		//	      alert("Success! \n\n" + response);

				if(response == "delete"){
		                        if(document.all){
		                                Effect.Fade(element_id);
		                        } else {
		                                $(element_id).setStyle({display:'none'});
		                        }
		                        $(element_id).remove();
		                        $A(document.getElementsByTagName("tr")).each(function(row,i){
	                	                if(row.style.display == 'none') {i--;return}
	        	                        row.setStyle({backgroundColor:'#fbfcfd'});
		                                if(i%2==1) row.setStyle({backgroundColor:'#e5f9fb'});
		                        });
				}
			  },
			  onFailure: function(){ alert('Something went wrong...') }
		});
	}
 }
