var imagesPreloadersACCBXS00 = new Array();
imagesPreloadersACCBXS00[0] = new Image();
imagesPreloadersACCBXS00[0].src = 'images/login-box-bg.jpg';

imagesPreloadersACCBXS00[1] = new Image();
imagesPreloadersACCBXS00[1].src ='images/menu-button-over-bg.jpg';

imagesPreloadersACCBXS00[2] = new Image();
imagesPreloadersACCBXS00[2].src ='images/button-home-big-over.gif';

 



function submitTaf() 
{
    var prodLink = document.getElementById('prodLink').value;
	var email = document.getElementById('your_mail').value;
	var demail = document.getElementById('dest_mail').value;
	var code= document.getElementById('contactCheck').value;
	document.getElementById('taf_error').style.display='none';
	document.getElementById('taf_error2').style.display='none';
	document.getElementById('taf_error3').style.display='none';
	emailTest = "^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\\.)+[a-z]{2,4}$"; 
	var regex = new RegExp(emailTest); 
	var err=0;
	if (!regex.test(email) || !(email.length > 0)) {
		document.getElementById('taf_error').style.display='inline';
		err = 1;
	} 
	if (!regex.test(demail) || !(demail.length > 0)) {
		document.getElementById('taf_error2').style.display='inline';
		err = 1;
	} 
	if (code.length == 0) {
		document.getElementById('taf_error3').style.display='inline';
		err = 1;
	}
	if(err==0) {
		var sessionParams = AJAXSessionParam;
		var unique = Math.round(Math.random()*1000);
		var urlReq = AJAXBaseURL+'/ajaxapi.php?taf_process=1'+sessionParams+'&prodLink='+prodLink+'&your_mail='+email+'&dest_mail='+demail+'&contactCheck='+code+'&unique='+unique;
		dhtmlCampusAveLoadScript(urlReq);

	}
	return false;
}

function setTafSuccess()
{
	var w = screen.availWidth;
	//var h = screen.availHeight;
	var h = document.body.scrollHeight;

	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;

	var taf = document.getElementById("taf_success_box");
	taf.style.position = 'absolute';
	taf.style.display = 'block';
	taf.style.top = (dsoctop+screen.availHeight/2-100)+'px';
	taf.style.left = (w/2)+'px';
	document.getElementById("taf_box").style.display='none';
}

function setTafError(error)
{
      if (error==1) {
		document.getElementById('taf_error').style.display='inline';
	} 
	if (error==2) {
		document.getElementById('taf_error2').style.display='inline';
	} 
	if (error==3) {
		document.getElementById('taf_error3').style.display='inline';
	}
}


		
document.observe("dom:loaded",function(){
    if(document.getElementById("save-info-message"))
		 CMPS_blink(document.getElementById("save-info-message"));
   return ;
   	$$("ul.main-menu li").each(function(element){
         element.observe('mouseover', function(e){
			if(e.target!=null)
			{
			 var elm = e.target;
			 if(elm.tagName == 'A')
				{ 
				 elm = elm.parentNode;
				}
			 if(elm)
			 {
			   elm.style.backgroundImage = 'url(images/menu-button-over-bg.jpg)';
			   elm.style.color = '#000';
			   var linksChild = elm.getElementsByTagName('A');
			   if(linksChild.length)
				  linksChild[0].style.color  = '#000';
			 }
			}
		  });
		  element.observe('mouseout', function(e)
		  {
			if(e.target!=null)
			{
			 var elm = e.target;
			 if(elm.tagName == 'A')
			   elm = elm.parentNode;
			 if(elm && elm.className!='menu-selected')
			 {
			   elm.style.backgroundImage = 'url(images/menu-button-bg.jpg)';
			   elm.style.color = '#EFEFF1';
			   var linksChild = elm.getElementsByTagName('A');
			   if(linksChild.length)
				  linksChild[0].style.color  = '#EFEFF1';
			 }
			}
		  });
		 
		   element.observe('click', function(e)
			 {
				if(e.target!=null)
				{
				 var elm = e.target;
				 if(elm.tagName == 'A')
				   return true;
				 if(elm)
				 {
				   var linksChild = elm.getElementsByTagName('A');
				   if(linksChild.length)
					 {
					    if (linksChild[0].dispatchEvent)
						{
						var e2 = document.createEvent("MouseEvents");
						e2.initEvent("click", true, true);
						linksChild[0].dispatchEvent(e2);
						}
						else
						{
						linksChild[0].click();
						}
						 
						if(e && e.preventDefault)
							e.preventDefault();
						return false;
					 }
				 }
				}
			  });
               
	});

   //home buttons
	$$("a.button_home_big,a.button_home_big span").each(
	 function(element)
	 {
        element.onmouseover = function(e)
		{
				if(element)
				{
				     var elm = element;
					 if(elm.tagName == 'A')
						{ 
						  var spansChild = elm.getElementsByTagName('SPAN');
						   if(spansChild.length)
							   elm = spansChild[0];
						}
					 if(elm)
					 {
					   elm.style.backgroundImage = 'url(images/button-home-big-over.gif)';
					   elm.style.color = '#000';

					 }
				}
		}
		element.onmouseout = function(e)
		{
				if(element)
				{
				     var elm = element;
					 if(elm.tagName == 'A')
						{ 
						  var spansChild = elm.getElementsByTagName('SPAN');
						   if(spansChild.length)
							   elm = spansChild[0];
						}
					 if(elm)
					 {
					   elm.style.backgroundImage = 'url(images/button-home-big.gif)';
					   elm.style.color = '#FFF';

					 }
				}
		}
	  });


	 
	 
	
});


function doClipboard(txt) {
    if(window.clipboardData) { // IE
        window.clipboardData.setData("Text", txt);
    }
    else { //  IE
        var fc = document.getElementById("flashCopier");
        if(!fc) { //   "flashCopier"  
            fc = document.createElement("div"); // 
            fc.id = "flashCopier"; //  id
            document.body.appendChild(fc); //     <body>
        }
        fc.innerHTML = '<embed src="clipboard.swf" FlashVars="clipboard=' + // src="clipboard.swf" -   clipboard.swf
            encodeURIComponent(txt) +
            '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    }
}





function Campus_Posting_Refund_Ad(type,id,price,channelID,cardType,pagename)
{
     showCustomModalDialog(430,280,'<div><h2>Refund paid ad</h2> \
                                      <form>\
									  <BR> '+(type==1?'Select partners and categories to refund':'Select partners and publication dates to refund')+'\
                                      <BR><BR><div id="campus-refund-ads-list">Loading list....</div>\
									   <BR><small> Note: the card processing comission will be subtracted from the amount</small>\
									  <BR><BR><input type="button" value="Continue" class="button_grey1" id="campus-refund-submit-button" disabled onclick="Campus_Posting_Refund_Ad_Submit('+type+','+channelID+','+cardType+',\''+pagename+'\');">\
									  &nbsp;&nbsp;&nbsp;&nbsp;<img src="images/loading.gif" width="30" height="30" id="campus-posting-main-submit-preloader" style="position:relative;top:10px;visibility:hidden">\
									  </form> \
									  </div>');
    var unique = Math.round(Math.random()*1000);
    var urlParams = 'ajaxapi.php?admin_refund_ad_form=1&id='+id+'&type='+type+'&pagename='+escape(pagename)+AJAXSessionParam+'&unique='+unique;
    $('campus-posting-main-submit-preloader').style.visibility = 'visible';
    dhtmlCampusAveLoadScript(AJAXBaseURL+'/'+urlParams);
}

function Campus_Posting_AdminRefundFormCallback(resultCode,ads,pagename)
{
  if(resultCode>0)
  {
    var popup = document.getElementById('campus-custom-popup');
    popup.style.height = (190+20*ads.length)+'px';
    var html = '';
    for(var i=0;i<ads.length;i++)
     if(ads[i].price>0)
      html += '<input type="checkbox" id="refund_check_'+i+'" value="'+ads[i].id+'|'+ads[i].subid+'"><label for="refund_check_'+i+'">'+ads[i].title+' - $'+ads[i].price+'</label><BR>';
    $('campus-refund-ads-list').innerHTML = html;
    $('campus-refund-submit-button').disabled = false;
    $('campus-posting-main-submit-preloader').style.visibility = 'hidden';

  }
    else
      $('campus-refund-ads-list').innerHTML = 'Error';
}
function Campus_Posting_Refund_Ad_Submit(type,channelID,cardType,pagename)
{
    var ins = document.getElementsByTagName('input');
    var found = '';
    for(var i=0;i<ins.length;i++)
    {
        if(ins[i].type =='checkbox' && ins[i].id && /refund_check_[0-9]+/.test(ins[i].id))
        {
            if(ins[i].checked)
            {
                found += '&ads[]='+ ins[i].value;
            }
        }
    }
  if(found.length>0)
  {
    //dhtmlLoad
	var urlParams = 'ajaxapi.php?admin_refund_ad_process=1'+found+'&type='+type+'&channelID='+channelID+'&cardType='+cardType+'&pagename='+escape(pagename)+AJAXSessionParam+'&unique='+unique;
    //alert(AJAXBaseURL+'/'+urlParams);
    //SEND
     var unique = Math.round(Math.random()*1000);
    $('campus-posting-main-submit-preloader').style.visibility = 'visible';
    dhtmlCampusAveLoadScript(AJAXBaseURL+'/'+urlParams);
  }
  else
   {
    $('campus-posting-main-submit-preloader').style.visibility = 'hidden';
	alert('Please select at least one element');
   }
}

function Campus_Posting_AdminRefundCallback(resultCode,message,pagename)
{
  if(resultCode>0)
  {
    Campus_OpenLink(pagename);
  }
  else
    {
      $('campus-posting-main-submit-preloader').style.visibility = 'hidden';	
	  alert(message);
	}
}

function Campus_Posting_Void_Ad(type,id,price,channelID,cardType,pagename)
{
     showCustomModalDialog(430,280,'<div><h2>Void paid ad</h2> \
                                      <form>\
									  <BR> You are going to void the order. Note that all ads placed by this order will be voided and removed from listings.\
                                      <BR><BR>Following ads will be voided:\
                                      <BR><div id="campus-refund-ads-list">Loading list....</div>\
									   <BR>\
									  <BR><BR><input type="button" value="Continue" class="button_grey1" id="campus-refund-submit-button" disabled onclick="Campus_Posting_Void_Ad_Submit('+id+','+type+','+cardType+',\''+pagename+'\');">\
									  &nbsp;&nbsp;&nbsp;&nbsp;<img src="images/loading.gif" width="30" height="30" id="campus-posting-main-submit-preloader" style="position:relative;top:10px;visibility:hidden">\
									  </form> \
									  </div>');
    var unique = Math.round(Math.random()*1000);
    var urlParams = 'ajaxapi.php?admin_void_ad_form=1&id='+id+'&type='+type+'&pagename='+escape(pagename)+AJAXSessionParam+'&unique='+unique;
    $('campus-posting-main-submit-preloader').style.visibility = 'visible';
    dhtmlCampusAveLoadScript(AJAXBaseURL+'/'+urlParams);
}

function Campus_Posting_AdminVoidFormCallback(resultCode,ads,pagename)
{
  if(resultCode>0)
  {
    var popup = document.getElementById('campus-custom-popup');
    popup.style.height = (190+20*ads.length)+'px';
    var html = '';
    for(var i=0;i<ads.length;i++)
     if(ads[i].price>0)
      html += '&nbsp;&nbsp;<B>'+ads[i].title+' - $'+ads[i].price+'</b><BR>';
    $('campus-refund-ads-list').innerHTML = html;
    $('campus-refund-submit-button').disabled = false;
    $('campus-posting-main-submit-preloader').style.visibility = 'hidden';

  }
    else
      $('campus-refund-ads-list').innerHTML = 'Error';
}

function Campus_Posting_Void_Ad_Submit(id,type,cardType,pagename)
{
  	var unique = Math.round(Math.random()*1000);
    var urlParams = 'ajaxapi.php?admin_void_ad_process=1&id='+id+'&type='+type+'&cardType='+cardType+'&pagename='+escape(pagename)+AJAXSessionParam+'&unique='+unique;
    //alert(AJAXBaseURL+'/'+urlParams);
    //SEND
    $('campus-posting-main-submit-preloader').style.visibility = 'visible';
    dhtmlCampusAveLoadScript(AJAXBaseURL+'/'+urlParams);
}

function Campus_Posting_AdminVoidCallback(resultCode,message,pagename)
{
  if(resultCode>0)
  {
    Campus_OpenLink(pagename);
  }
  else
  {
      $('campus-posting-main-submit-preloader').style.visibility = 'hidden';	
	  alert(message);
  }
}





	//SHOULD be rewritten for API mode
function Campus_OpenLink(page)
{
    var sessionParams = AJAXSessionParam;

	var unique = Math.round(Math.random()*1000);
	var BaseURL = AJAXBaseURL;
	if(page.indexOf('?')>=0)
	 page = page + '&';
	else
	 page = page + '?';
	var link =  page+'unique='+unique+sessionParams;
	if(page.indexOf('http')<0)
	 link = BaseURL+'/'+link;
	location.href = link;
}



function submitHomePageQuickForm(form,url,sessionParam)
{
 var req = url+'/ajaxapi.php?quick_join_process=1&'+sessionParam+Campus_formToURL(form);
 dhtmlCampusAveLoadScript(req);
}


function quickJoinCallback(status,message,errorControl)
{
   if(status)
   {
            $("login_box").style.display ='none'; 
			var html = '<div style="height:70px;"></div><BR>\
			            <table width="540" height="115" style="margin-left:27px" align="center" bgColor="#E4FBEA"><tr><td width="100"><img src="/images/sign_smile_big.gif"></td>\
			            <td>\
						 <b style="font-size:14px">Success! One of our customer representatives will contact you within 24 hours</b><BR><BR>\
						 <BR>\
						 <BR>\
						 <a href="/">Back to home page &gt;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
						</td>\
						</tr>\
						</table>';
			showCustomModalDialog(600,300,html,true);
			
   }
   else
   {
    $('proposal-error').innerHTML = message;
	CMPS_blink($('proposal-error'));
   }
}