function ajaxRequest(server_page, r_method, div_id_update, query){

        new Ajax(server_page, {
            method: r_method,
            postBody: query,
            update: div_id_update
        }).request();
        return false;
};

var OpaqueWin = {
     MakeWinOpaque: function(target){
		if(status == 1) {
               //$(target).setOpacity(1);
               $(target).setStyles({
                    'opacity':'1',
                    'z-index':'99'
               });
               status = 0;
            }
		else{
               //$(target).setOpacity(0.5);
               $(target).setStyles({
                    'opacity':'.5',
                    'z-index':'0'
               })
               status = 1;
          }
	},
	ShowWin: function(){

      var surpriseCoord = $('surprise_box').getCoordinates();
      var surpriseBoxWidth = surpriseCoord.width;
      var boxCoord = $('main_container').getCoordinates();
      var boxWidth = boxCoord.width;
      var boxLeftPos = boxCoord.left;
      var boxTopPos = boxCoord.top;

      var positiontop = boxTopPos + 20;
      var positionleft = ((boxWidth - surpriseBoxWidth) / 2) + boxLeftPos;

          $('surprise_box').setStyles({
               'visibility' : 'visible',
               'top' : positiontop,
               'left' : positionleft
           });
     }

}

function submit_form(myswitch, passover, buttonGroup){
     //call request
     if(myswitch == 1){

          if(passover == 0){
               var btn_count = 0;
               if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
                    for (var i=0; i<buttonGroup.length; i++) {
                         if (buttonGroup[i].checked) {
                              //mean user selected something
                              btn_count++;
                         }
                    }
               } else {
                    if (buttonGroup.checked) { btn_count++; } // if the one button is checked, return zero
               }
               //if 0 mean nothing selected
               if(btn_count > 0){
                    document.form1.submit();
                    return;
               }
          }
          
          var r_method = "GET";
          var div_id_update = "surprise_box";
          var query = $('form1').toQueryString();
          var server_page = "/quiz/surprise.php?" + query;

          ajaxRequest(server_page, r_method, div_id_update, query);
          OpaqueWin.MakeWinOpaque('super_wrapper');
          OpaqueWin.ShowWin();
          setTimeout('document.form1.submit()', 3000);
          return;
          
     }
     else if (myswitch == 2){
          document.form1.submit();
          return;
     }
}
function submit_form2(myswitch, passover, buttonGroup){
     //call request
     if(myswitch == 1){
//alert(buttonGroup.length);
          if(passover == 0){
               var btn_count = 0;
               if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
                    for (var i=0; i<buttonGroup.length; i++) {
                         if (buttonGroup[i].checked) {
                              //mean user selected something
                              btn_count++;
                         }
                    }
               } else {
                    if (buttonGroup.checked) { btn_count++; } // if the one button is checked, return zero
               }
               //if 0 mean nothing selected
               if(btn_count > 0){
                    document.form1.submit();
                    return;
               }
          }
//alert(btn_count);alert(myswitch);alert(passover);

          if(btn_count == 0){
          var r_method = "GET";
          var div_id_update = "surprise_box";
          var query = $('form1').toQueryString();
          var server_page = "/quiz/surprise.php?" + query;

          ajaxRequest(server_page, r_method, div_id_update, query);
          OpaqueWin.MakeWinOpaque('super_wrapper');
          OpaqueWin.ShowWin();
          setTimeout('document.form1.submit()', 3000);
          return;
}
          
     }
     else if (myswitch == 2){
          document.form1.submit();
          return;
     }
}
function check_radio(radiobtn){     $(radiobtn).checked = true;     return true;}
function referit(link, cat){

        //if (cat == 1){ //which is story
            var referrer_i = link;
        //}else if (cat == 2 ){ //which is kip perosnal finance
            //var referrer_i = link;
        //}

        if (top && top.window.opener)
            {
             // alert("1");
            top.window.opener.location.replace(referrer_i);
            top.self.opener.location.replace(referrer_i);
            top.window.opener.focus();
            //top.window.close();

            }
        else if(top && top.location)
            {
           //alert("2");
             //top.location.replace(referrer_i);
             location.href = referrer_i;
            }
        else
            {
            //alert("3");
             //location.replace(referrer_i);
             location.href = referrer_i;
            }
}
function SlidePopUp(url,awidth,aheight)
{
    var wname="popup";
    var popup=window.open(url,wname,"width="+awidth+",height="+aheight+",location=0,menubar=0,resizable=0,scrollbars=1,statusbar=0,titlebar=1,toolbar=0,screenX=0,screenY=0");
    
    var winHeight = window.getHeight();
    var boxCoord = $('main_container').getCoordinates();
    var boxWidth = boxCoord.width;
    var boxLeftPos = boxCoord.left;
    var boxTopPos = boxCoord.top;

    var positiontop = ((winHeight - aheight) / 2) + boxTopPos;
    var positionleft = ((boxWidth - awidth) / 2) + boxLeftPos;
    
    popup.moveTo(positionleft, positiontop);
    popup.focus();
}
