var detect = navigator.userAgent.toLowerCase();
var browser,total,thestring;
var the_timeout;
var startImage;
var endImage;
var image0;
var image1;
var image2;
var image3;
var image4;
var iobj;
var fobj;
var flip = 1;
var reset = 0;
var running = 0;

function doBrowserC(simg, eimg) {
 if (checkIt('msie')){ 
 browser = "Internet Explorer"
 } else browser = "one of the others";

 startImage = simg;
 endImage = eimg;
 
doTrans();
}

function dofrontBrowserC(img1, img2, img3, img4) {
 if (checkIt('msie')){ 
 browser = "Internet Explorer"
 } else browser = "one of the others";

 image1 = img1;
 image2 = img2;
 image3 = img3;
 image4 = img4;
  
frontpromo();
}

function popsubmit(formelement,locelement){
//first read vars and pop window
locid = document.getElementById(locelement).value;
vindue=window.open('inc/downloadn.php?locid='+locid+'&popped=yes','newwindow','width=400,height=300,top=100,left=100');

document.forms[formelement].submit();
}

function doslides(filterobj, imageobj, img0, img1, img2, img3, img4) {
 if (checkIt('msie')){ 
 browser = "Internet Explorer"
 } else browser = "one of the others";

 if ((fobj != filterobj) && (fobj != null)){ document.getElementById(iobj).src = image0; reset = 1;} 
 
 image0 = img0;
 image1 = img1;
 image2 = img2;
 image3 = img3;
 image4 = img4;
 
 fobj =  filterobj;
 iobj = imageobj; 
 
slidepromo();
}
function slidepromo() {

if (browser == "Internet Explorer")
{
        document.getElementById(fobj).filters[0].apply();
}

 if (reset == 1){
		flip = 1;
		reset = 0;
 }
        if (flip > 4) {
            document.getElementById(iobj).src = image0
						flip = 1;
       }
        else {
				         if (flip == 1) { document.getElementById(iobj).src = image1 }
				         if (flip == 2) { document.getElementById(iobj).src = image2 }
				         if (flip == 3) { document.getElementById(iobj).src = image3 }
				         if (flip == 4) { document.getElementById(iobj).src = image4 }								 
						flip++;
        }

if (browser == "Internet Explorer")
{
        document.getElementById(fobj).filters[0].play();
}						
	
	if ((running == 0) && (flip != 1)){			
	 the_timeout = setTimeout("togglerun();", 10000);
	 running = 1;
	}				
}

function togglerun(){
 running = 0;
 slidepromo();
}

function dosimpBrowserC() {
 if (checkIt('msie')){ 
 return "Internet Explorer"
 } else return "one of the others";

}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}



function doTrans() {

if (browser == "Internet Explorer")
{
        imgObj.filters[0].apply();
}


        if (flip == 0) {
            document.getElementById('oImg').src = endImage
						flip = 1;
       }
        else {
            document.getElementById('oImg').src = startImage
						flip = 0;
        }

if (browser == "Internet Explorer")
{
        imgObj.filters[0].play();
}						
				
	the_timeout = setTimeout("doTrans();", 5000);				
}

function frontpromo() {

if (browser == "Internet Explorer")
{
        imgObj.filters[0].apply();
}
        if (flip == 0) {
						flip++;
       }				

        if (flip > 4) {
            document.getElementById('oImg').src = image1
						flip = 0;
       }
        else {
				         if (flip == 2) { document.getElementById('oImg').src = image2 }
				         if (flip == 3) { document.getElementById('oImg').src = image3 }
				         if (flip == 4) { document.getElementById('oImg').src = image4 }
						flip++;
        }

if (browser == "Internet Explorer")
{
        imgObj.filters[0].play();
}						
				
	the_timeout = setTimeout("frontpromo();", 6000);				
}

nowShowing = "";
function showhidec(cid){
if(nowShowing!=""){
     document.getElementById("comment"+nowShowing).style.display= "none";
	}

if (nowShowing == cid){nowShowing = ""; return}

     if(document.getElementById("comment"+cid)){
		document.getElementById("comment"+cid).style.display = "block"}
    nowShowing = cid;
	}

function coolRedirect(url, msg)
{
   var TARG_ID = "COOL_REDIRECT";
   var DEF_MSG = "Redirecting...";

   if( ! msg )
   {
      msg = DEF_MSG;
   }

   if( ! url )
   {
      throw new Error('You didn\'t include the "url" parameter');
   }


   var e = document.getElementById(TARG_ID);

   if( ! e )
   {
      throw new Error('"COOL_REDIRECT" element id not found');
   }

   var cTicks = parseInt(e.innerHTML);

   var timer = setInterval(function()
   {
      if( cTicks )
      {
         e.innerHTML = --cTicks;
      }
      else
      {
         clearInterval(timer);
         document.body.innerHTML = msg;
         location = url;	  
      }

   }, 1000);
}


function ClipBoard(felement) 
{

if (dosimpBrowserC() == "Internet Explorer") {
 Copied = document.getElementById(felement).createTextRange();
 Copied.execCommand("Copy");
 alert("Your link has been saved to the ClipBoard. Use the shortcut Ctrl+V to paste your link anywhere you want!");
} else { alert("This function is only supported in Internet Explorer. Youll have to copy the link manually. Sorry :)");} 
}


function checkFile(felement) { 
  if (document.getElementById(felement).value.length <= 0) { 
   alert("Please select a file for upload."); 
   return false; 
  } 
  p = document.getElementById(felement).value.lastIndexOf("."); 
  if (p<0) { 
   alert("This is not a valid file. Only files with the .slap extension are allowed."); 
   return false; 
  } 
  ext = document.getElementById(felement).value.slice(p); 
if ((ext.toLowerCase() != ".slap")) { 
  alert("Only files with the .slap extension are allowed. Dont even try uploading anything malicious buddy ;)"); 
   return false; 
 }
document.getElementById('submitb').disabled = 'disabled';
document.getElementById('msg').innerHTML = 'Upload in progress... Please be patient'; 
 return true;
 } 


function windowOpenPos(pos,rurl,under) {
 var x=0;
 var y=0;
  var w=screen.availWidth;
//   w = w / 2;
		 w = 550;
  var h=screen.availHeight;
//   h = h / 2;
		 h = 485;

self.name = "parent_win"; 

 if (pos == 1) { 
  x = 1;
  y = 1;
 }
 if (pos == 2) { 
  x = w;
  y = 1;
 }
 if (pos == 3) { 
  x = 1;
  y = h;
 }
 if (pos == 4) { 
  x = w;
  y = h;
 }

 if (pos == 5) { 
  x = 1;
  y = 1;
  w=screen.availWidth;
  h=screen.availHeight;
 }

NewWin = window.open(rurl,"_blank","height=" + h + ",width=" + w + ",top=" + y + ",left=" + x + ",menubar=no,titlebar=yes,status=yes,scrollbars=yes,toolbar=no,resizable=yes,location=no,channelmode=no,directories=no",false);

if (under==1) {
  NewWin.blur();  
 }

}
