slinks = new Array("web","pictures","blogsearch","ans");
smrk = new Array(8,92,176,260);
var engineId;

function SetCookie(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+
  ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function setEngine ( eid )
{

	$('#nav li').removeClass('active');
	$('#eng_'+eid).addClass('active');
	engineId = eid;
	var path = slinks[eid];
	if(((eid == 3) && (HostFunctions.indexOf('A') == -1)) // no answers
	|| ((eid == 2) && (HostFunctions.indexOf('B') == -1))){ // no blogs
		path = slinks[0]; // redirect to web
		engineId = 0;
	}
	if((eid == 1) && (HostFunctions.indexOf('I') == -1)){ // no images
		document.getElementById('sform').attributes.action.value="http://int.ask.com/"+path;
		document.getElementById('sform').siteid.value="10000831";
	}
	else{
	  document.getElementById('sform').attributes.action.value="http://"+document.getElementById('searchHost').value+"/"+path;
	  document.getElementById('sform').siteid.value=document.getElementById('baseSiteId').value;
	}
//	document.getElementById('searchcontrols').style.backgroundImage="url(../i/start_b"+eid+".png)";
	if(RTL)
		document.getElementById('searchcontrols').style.backgroundPosition=$('#searchcontrols').width()-smrk[eid]-84+"px"+" 100%";
	else
		document.getElementById('searchcontrols').style.backgroundPosition=smrk[eid]+"px"+" 100%";

	$('#srch_q').focus();
    document.getElementById('sform').fromSite.value = document.getElementById('sform').attributes.action.value;
	document.getElementById('sform').attributes.action.value = baseDir + 's/';
}

var activePopup;

function showPopup(id){
	var fader = $('#fader');
	var height = $('body').height();
	if($(window).height() > height)
		height = $(window).height();
	fader.css('height', height + 'px');
	fader.css('visibility', 'visible');
	var div = document.getElementById(id);
	$(div).css('top', $(window).scrollTop() + Math.round(($(window).height() - $(div).height()) / 2) + 'px');
	$(div).css('left', Math.round(($(window).width() - $(div).width()) / 2) + 'px');
	$(div).css('visibility', 'visible');
	activePopup = div;
}

function loadIframe(src){
	document.getElementById('iframe').src = src;
}

function hidePopup(){
	$(activePopup).css('visibility', 'hidden');
	$('#fader').css('visibility', 'hidden');
	if(activePopup == document.getElementById('iframePopup'))
		document.getElementById('iframe').src = 'about:blank';
	activePopup = null;
}

function uploadSkin(){
	loadIframe('uploadSkin.php');
}

function submitSearchForm(onSubmit) {
  if (!document.forms.srchform.elements[0].value) {
    document.forms.srchform.elements[0].focus();
	return false;
  } else {
	if(!onSubmit)
	  document.forms.srchform.submit();
	return true;
  }
}

function iframeLoaded(){
	var iframe = document.getElementById('iframe');
	if((iframe.src == 'about:blank') || (iframe.src == ''))
		return;
	// show abnormally loaded frame
	var doc;
	if(iframe.contentWindow)
		doc = iframe.contentWindow.document;
	else
		doc = iframe.contentDocument;
	var height = $(doc.body).height();
	iframe.style.height = height + 'px';
	showPopup('iframePopup');
}

function doUpload(){
	if(!document.getElementById('agree').checked){
		alert("You should warrant that this image complies with Ask com's terms of service");
		return;
	}
	document.getElementById('doUploadButton').innerHTML = "Uploading..";
	document.getElementById('doUploadButtonTable').className = "button btnCancel";
	document.getElementById('doUploadButton').onclick = "";
	document.getElementById('uploadForm').submit();
	$('#progressNote').html('<img src="i/ajaxLoader.gif" width="16" height="16" border="0"> Upload in progress... please wait.');
}

function submitonce(theform) {
  if (document.all || document.getElementById) {
    for (i=0;i<theform.length;i++) {
      var tempobj=theform.elements[i];
      if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {
        tempobj.disabled=true;
      }
    }
  }
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function selectCheckBoxes( form, prefix, checked )
{
    for (i=0;i<form.length;i++) {
      var input=form.elements[i];
      if( (input.type.toLowerCase()=="checkbox") && ( input.name.indexOf(prefix) == 0 ) )
	        input.checked = checked;
    }
}

function selectedCheckBoxes( form, prefix )
{
	result = "";
    for (i=0;i<form.length;i++) {
      var input=form.elements[i];
      if( (input.type.toLowerCase()=="checkbox") && ( input.name.indexOf(prefix) == 0 ))
      	if( input.checked )
      	{
      		if( result != "" )
      			result = result + ",";
	        result = result + input.value;
      	}
    }
    return result;
}

function checkedCount(form, prefix) {
	nCount = 0;
    for (i=0;i<form.length;i++) {
      var input=form.elements[i];
      if((input.type.toLowerCase()=="checkbox") && ( !prefix || ( input.name.indexOf(prefix) == 0 ) ) )
	        if(input.checked)
	        	nCount++;
    }
	return nCount;
}

// check that at least one radio is checked
function radioChecked( form, radioName )
{
	result = false;
	for( i=0; i < form.length; i++ )
	{
		var element=form.elements[i];
	  	if( ( element.type.toLowerCase() == "radio" )
	  	&& ( element.name == radioName )
	  	&& element.checked )
	    	result = true;
	}
	return result;
}

// check that at least one radio is checked
function radioValue( form, radioName )
{
	result = '';
	for( i=0; i < form.length; i++ )
	{
		var element=form.elements[i];
	  	if( element.name == radioName )
	  	{
	  		if( element.type.toLowerCase() == "radio" )
	  		{
	  			if( element.checked )
	    			result = element.value;
	  		}
	  		else
    			result = element.value;
	  	}
	}
	return result;
}

// enable radio buttons
function enableRadio( form, radioName, enable )
{
	for( i=0; i < form.length; i++ )
	{
		var element=form.elements[i];
	  	if( ( element.type.toLowerCase() == "radio" )
	  	&& ( element.name == radioName ) )
	    	element.disabled = !enable;
	}
}

function openAWindow( pageToLoad, winName, width, height, center, scroll) {
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) &&(center)) {
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	args = "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0,"
	+ "menubar=0,"
	+ "resizable=1,"
	+ "scrollbars="+scroll+","
	+ "status=0,"
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + "," //NN Only
	+ "screeny=" + yposition + "," //NN Only
	+ "left=" + xposition + "," //IE Only
	+ "top=" + yposition; //IE Only
	window.open( pageToLoad, winName, args );
}

