/*
 * PHP File Uploader with progress bar Version 1.20
 * Copyright (C) Raditha Dissanyake 2003
 * http://www.raditha.com

 * Licence:
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Initial Developer of the Original Code is Raditha Dissanayake.
 * Portions created by Raditha are Copyright (C) 2003
 * Raditha Dissanayake. All Rights Reserved.
 *
 */


var postLocation="pgbar.php";

/*
 * add any extension that you do no want to upload to the list
 * below they should be placed with in the /^ and / characters
 * separate each extension by a pipe symbol |
 */


 var re = /^(\.jpg)|(\.jpeg)/;

/* var goodextensions = /^(jpg|jpeg|JPEG|JPG)$/; */

/**
 * dofilter = true; to enable filtering
 */
var dofilter=true;

/**
 * this method will match each of the filenames with a
 * given list of banned extension. If any one of the
 * extensions match, an alert will be popped up and the
 * upload will not continue;
 */

function check_types() {
	if(dofilter==false)
		return true;
	x=document.forms[1].elements['userfile'].value.indexOf(".jpg")
	z=document.forms[1].elements['userfile'].value.indexOf(".JPG")
/*	if(document.forms[1].elements['userfile'].value.indexOf(".jpg")==-1) { */
	if((x==-1) && (z==-1)){
		alert("Please upload only .jpg extention file");
	  	  return false;
	}
	else {
	  	  return true;
	}
	return true;
}

function check_types5() {
	if(dofilter==false)
		return true;
	x=document.forms[2].elements['userfile'].value.indexOf(".jpg")
	z=document.forms[2].elements['userfile'].value.indexOf(".JPG")
/*	if(document.forms[2].elements['userfile'].value.indexOf(".jpg")==-1) { */
	if((x==-1) && (z==-1)){
		alert("Please upload only .jpg extention file");
	  	  return false;
	}
	else {
	  	  return true;
	}
	return true;
}

function check_types3() {
	if(dofilter==false)
		return true;
	x=document.forms[3].elements['userfile'].value.indexOf(".jpg")
	z=document.forms[3].elements['userfile'].value.indexOf(".JPG")
/*	if(document.forms[3].elements['userfile'].value.indexOf(".jpg")==-1) { */
	if((x==-1) && (z==-1)){
		alert("Please upload only .jpg extention file");
	  	  return false;
	}
	else {
	  	  return true;
	}
	return true;
}

function check_types4() {
	
var mytool_array = document.websiteimageupload.elements['userfile'].value.split("\\");
var filenamewow = mytool_array.length -1;
var filename = mytool_array[filenamewow];


var invalid = "%"; // Invalid character is a space
var invalid2 = "'";

	x=document.websiteimageupload.elements['userfile'].value.indexOf(".jpg")
	z=document.websiteimageupload.elements['userfile'].value.indexOf(".JPG")
	a=filename.indexOf(invalid);
	b=filename.indexOf(invalid2);
	if((x==-1) && (z==-1)){
		alert("Please upload only .jpg extention file");
	  	  return false;
	}
	if(b > -1){
                alert("Files with ' in the filename are invalid");
                  return false;
        }
	if(a > -1){
                alert("Files with Spaces in the filename are invalid");
                  return false;

	}	

return true;

}


function check_types9() {
var mytool_array = document.forms[3].elements['userfile'].value.split("\\");
var filenamewow = mytool_array.length -1;
var filename = mytool_array[filenamewow];


var invalid = " "; // Invalid character is a space
var invalid2 = "'";

        x=document.forms[3].elements['userfile'].value.indexOf(".jpg")
        z=document.forms[3].elements['userfile'].value.indexOf(".JPG")
        a=filename.indexOf(invalid);
        b=filename.indexOf(invalid2);
        if((x==-1) && (z==-1)){
                alert("Please upload only .jpg extention file");
                  return false;
        }
        if(b > -1){
                alert("Files with ' in the filename are invalid");
                  return false;
        }
        if(a > -1){
                alert("Files with Spaces in the filename are invalid");
                  return false;

        }

	return true;
}

function popUP(mypage, myname, w, h, scroll, titlebar)
{

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function postIt()
{

	if(check_types() == false)
	{
		return false;
	}
	baseUrl = postLocation;
	sid = document.forms[1].sessionid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&sessionid=" + sid;

	popUP(baseUrl,"Uploader",500,145,false,false);
	document.forms[1].submit();
}


function postIt5()
{

	if(check_types5() == false)
	{
		return false;
	}
	baseUrl = postLocation;
	sid = document.forms[2].sessionid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&sessionid=" + sid;

	popUP(baseUrl,"Uploader",500,145,false,false);
	document.forms[2].submit();
}

function postIt3()
{

	if(check_types3() == false)
	{
		return false;
	}
	baseUrl = postLocation;
	sid = document.forms[3].sessionid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&sessionid=" + sid;

	popUP(baseUrl,"Uploader",500,145,false,false);
	document.forms[3].submit();
}

function postIt4()
{
	if(check_types4() == false)
	{
		return false;
	}
	baseUrl = postLocation;
	sid = document.websiteimageupload.sessionid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&sessionid=" + sid;

	popUP(baseUrl,"Uploader",500,145,false,false);
	document.websiteimageupload.submit();
}



function postIt9()
{

	if(check_types9() == false)
	{
		return false;
	}
	baseUrl = postLocation;
	sid = document.forms[3].sessionid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&sessionid=" + sid;

	popUP(baseUrl,"Uploader",500,145,false,false);
	document.forms[3].submit();
}


function check_types3() {
	if(dofilter==false)
		return true;
	a=document.forms[3].elements['userfile'].value.indexOf(".txt")
	b=document.forms[3].elements['userfile'].value.indexOf(".TXT")
	c=document.forms[3].elements['userfile'].value.indexOf(".JPG")
	d=document.forms[3].elements['userfile'].value.indexOf(".jpg")
	e=document.forms[3].elements['userfile'].value.indexOf(".mpg")
	f=document.forms[3].elements['userfile'].value.indexOf(".MPG")
	g=document.forms[3].elements['userfile'].value.indexOf(".avi")
	h=document.forms[3].elements['userfile'].value.indexOf(".AVI")
	i=document.forms[3].elements['userfile'].value.indexOf(".mp3")
	j=document.forms[3].elements['userfile'].value.indexOf(".MP3")
	k=document.forms[3].elements['userfile'].value.indexOf(".zip")
	l=document.forms[3].elements['userfile'].value.indexOf(".ZIP")
	m=document.forms[3].elements['userfile'].value.indexOf(".mov")
	n=document.forms[3].elements['userfile'].value.indexOf(".MOV")
	o=document.forms[3].elements['userfile'].value.indexOf(".wmv")
	p=document.forms[3].elements['userfile'].value.indexOf(".WMV")
	q=document.forms[3].elements['userfile'].value.indexOf(".GIF")
	r=document.forms[3].elements['userfile'].value.indexOf(".gif")
	s=document.forms[3].elements['userfile'].value.indexOf(".DOC")
	t=document.forms[3].elements['userfile'].value.indexOf(".doc")
	u=document.forms[3].elements['userfile'].value.indexOf(".wav")
	v=document.forms[3].elements['userfile'].value.indexOf(".WAV")

	if((a==-1) && (b==-1) && (c==-1) && (d==-1) && (e==-1) && (f==-1) && (g==-1) && (h==-1) && (i==-1) && (j==-1) && (k==-1) && (l==-1) && (m==-1) && (n==-1) && (o==-1) && (p==-1) && (q==-1) && (r==-1) && (s==-1) && (t==-1) && (u==-1) && (v==-1)){
		alert("Please upload only jpg,gif,avi,txt,mp3,mov,wmv,doc or zip extention file");
	  	  return false;
	}
	else {
	  	  return true;
	}
	return true;
}

function popUP2(mypage, myname, w, h, scroll, titlebar)
{

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function postIt2()
{

	if(check_types2() == false)
	{
		return false;
	}
	baseUrl = postLocation;
	sid = document.forms[1].sessionid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&sessionid=" + sid;

	popUP2(baseUrl,"Uploader",500,145,false,false);
	document.forms[1].submit();
}




/*
function putInTextBox(txt) {
var str = document.selection.createRange().text;
  document.webcodeform.content.focus();
  var sel = document.selection.createRange();
  sel.text = str + "[IMG]" + txt + "[/IMG]";
  return;

}
*/


function addsmiley(txt) {
var str = document.selection.createRange().text;
  document.webcodeform.content.focus();
  var sel = document.selection.createRange();
  sel.text = str + txt;
  return;
}

function addsmileycomment(txt) {
var str = document.selection.createRange().text;
  document.commentwebform.message.focus();
  var sel = document.selection.createRange();
  sel.text = str + txt;
  return;

}

function addsmileycomment2(txt) {
var str = document.selection.createRange().text;
  document.commentwebform.message2.focus();
  var sel = document.selection.createRange();
  sel.text = str + txt;
  return;

}

function format_sel(v) {
  var str = document.selection.createRange().text;
  document.webcodeform.content.focus();
  var sel = document.selection.createRange();
  sel.text = "[" + v + "]" + str + "[/" + v + "]";
  return;
}

function putInTextBoxO() {
var str = document.selection.createRange().text;
  document.webcodeform.content.focus();
  var sel = document.selection.createRange();
test5=prompt("Enter The Remote URL to the image", "http://");

  sel.text = str + "[oimg]" + test5 + "[/oimg]";
  return;
}

function putInTextBoxOURL() {
var str = document.selection.createRange().text;
  document.webcodeform.content.focus();
  var sel = document.selection.createRange();
test5=prompt("Enter the remote URL", "http://");
test6=prompt("Enter the text to be displayed", "click here");

  sel.text = str + "[url=" + test5 + "]" + test6 + "[/url]";
  return;

}



function emailCheck (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|COM|NET|ORG|EDU|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s) AND MAKE SURE the email address is NOT ALL CAPS");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Ths username contains invalid characters.");
	return false;
	}
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths domain name contains invalid characters.");
	return false;
	   }
	}

	if (user.match(userPat)==null) {
	alert("The username doesn't seem to be valid.");
	return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 &&
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
	}

	if (len<2) {
	alert("This address is missing a hostname!");
	return false;
	}

	if( document.register.word.value == "gotstang"){
	return true;
	} else {
	alert("Please type the word, gotstang in the Action Word field below");	
	return false;
	}
}


function setText(text){
	document.nominate.sigcode.value=text;
}


function thehunt() {
	if(dofilter==false)
		return true;
	a=document.huntclaimform.elements["userfile[]"][0].value.indexOf(".jpg")
	b=document.huntclaimform.elements["userfile[]"][0].value.indexOf(".JPG")
	c=document.huntclaimform.elements["userfile[]"][1].value.indexOf(".jpg")
	d=document.huntclaimform.elements["userfile[]"][1].value.indexOf(".JPG")

	if((a==-1) && (b==-1) && (c==-1) && (d==-1)){
		alert("Please upload only .jpg extention file");
	  	  return false;
	}
	else {
	
		var iChars = "#\'";

  	for (var i = 0; i < document.huntclaimform.elements["userfile[]"][0].value.length; i++) {
  		if (iChars.indexOf(document.huntclaimform.elements["userfile[]"][0].value.charAt(i)) != -1) {
  		alert ("Your Angle 1 image name has special characters. \nThese are not allowed.\n Please remove them and try again.");
  		return false;
  		} 
	}
	

	for (var j = 0; j < document.huntclaimform.elements["userfile[]"][1].value.length; j++) {
  		if (iChars.indexOf(document.huntclaimform.elements["userfile[]"][1].value.charAt(j)) != -1) {
  		alert ("Your Angle 2 image name has special characters. \nThese are not allowed.\n Please remove them and try again.");
  		return false;
  		} 
	}

return true;

}


	

	return true;
}


function showStatusDetail(id) {
	document.getElementById('stat'+id).style.display="block";
	document.getElementById('stat'+id).style.float="left";
}

function hideStatusDetail(id) {
	document.getElementById('stat'+id).style.display="none";
}


function showhuntcomment(id,count){

alert("Please tell us why you voted fake (you will remain anonymous!)");
	document.getElementById('hunt'+id).style.display="block";
}

function hidehuntcomment(id){

	document.getElementById('hunt'+id).style.display="none";
}

function showpageoptionshelp(id) {
        document.getElementById('pageoptions_right_helpd').style.display="none";
        document.getElementById('pageoptions_right_help'+id).style.display="block";
        document.getElementById('pageoptions_right_help'+id).style.float="left";
        document.getElementById('pageoptions_right_help'+id).style.color="black";
}

function hidepageoptionshelp(id) {
        document.getElementById('pageoptions_right_help'+id).style.display="none";
        document.getElementById('pageoptions_right_helpd').style.display="block";
}

function votenow(wow,wow2){
	document.getElementById(wow).style.border="1px solid #00CC33"; 
	document.getElementById(wow).style.color="#00CC33"; 
	document.getElementById(wow2).style.border="1px solid red"; 
	document.getElementById(wow2).style.color="red"; 
}




function checkgo()
{
    var length = document.deletegb.elements.length;
    if (document.deletegb.checkall.checked==1)
    {
        for (i=length-1; i>0; i--)
        {
            var e = document.deletegb.elements[i];
            if (e.type=='checkbox' && e.name.indexOf("giddeletesent") != -1)
            {
                e.checked=1;
                var msgno = 'msg'+i;
            }
        }
    }
    else
    {
        for (i=length-1; i>0; i--)
        {
            var e = document.deletegb.elements[i];
            if (e.type=='checkbox' && e.name.indexOf("giddeletesent") != -1)
            {
                e.checked=0;
                var msgno = 'msg'+i;
            }
        }
    }
}


function checkgo2()
{
    var length = document.deletegb.elements.length;
    if (document.deletegb.checkall.checked==1)
    {
        for (i=length-1; i>0; i--)
        {
            var e = document.deletegb.elements[i];
            if (e.type=='checkbox' && e.name.indexOf("giddelete") != -1)
            {
                e.checked=1;
                var msgno = 'msg'+i;
            }
        }
    }
    else
    {
        for (i=length-1; i>0; i--)
        {
            var e = document.deletegb.elements[i];
            if (e.type=='checkbox' && e.name.indexOf("giddelete") != -1)
            {
                e.checked=0;
                var msgno = 'msg'+i;
            }
        }
    }
}




function validatepw(){
var returnval;

var pw1 = document.profilesave.passwordnew.value;
var pw2 = document.profilesave.passwordnew2.value;

if(pw1==pw2){

returnval = true;
} else {
document.profilesave.passwordnew.focus();
alert("Your Password Fields DONOT Match, Please Make Sure They Do");
returnval = false;
}

return returnval;

}



function checkforblogtitle(){
var returnval;


document.addablog.title.focus();

var pw1 = document.addablog.title.value;


if(pw1.length > 1){
returnval = true;
} else {
alert("Your Blog Must Have A Title!!");
returnval = false;
}

return returnval;

}

function popitupmulti(url)
{
        newwindow=window.open(url,'name','height=500,width=650,scrollbars=0');
        if (window.focus) {newwindow.focus()}
        return false;
}



function testimage()
{
var link = "";
var link2 = "";
var divweb = document.getElementById("website"); 
if(divweb){
var cells = divweb.getElementsByTagName("a"); 
//alert(cells.length);
for (var i = 0; i < cells.length; i++) { 
    status = cells[i].className; 
    if ( status == "img") {
//	alert(cells[i].href); 
	link = cells[i].href;
	link2 = link.replace("http://www.gotstang.com","");
	//alert(link2);
    	cells[i].onclick = function(){window.open(link2,"name","height=600,width=800,scrollbars=0");return false;}
	link = "";
	link2 = "";
	}
}
}


}


function givemeimage(div2show,url,description){
var text = "<img width=150 height=112 src=\"" + url + "\"><BR>" + description;
/*         var IE = (document.all) ? 1 : 0;
    var DOM = 0;
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"
    if (DOM) {
        var viewer = document.getElementById(div2show);
        if(viewer){
        viewer.innerHTML = text;
        }
    }  else if(IE) {
         if(document.all[div2show]){
         document.all[div2show].innerHTML = text;
         }
    } else {

        alert("Looks like there is an issue with your web-browser. Contact J@gotstang.com");

    }
*/

$("#"+div2show).html(text);
}




function addfavorite(uid,pid){
$.get("/ajax/managefavorites.php", { uid: uid, pid: pid },
  function(data){
var e = document.getElementById('favoritewatch'); 
e.innerHTML = data;
  });
}

function deletefavorite(uid,pid){

$.get("/ajax/managefavorites.php", { uid: uid, pid: pid,deletego: 1 },
  function(data){
var e = document.getElementById('favoritewatch');
e.innerHTML = data;
  });

}

function nextpagepreview(page,carnumber,userid){


$.get("/ajax/mini_imagespreview.php", { from: page,carnumber:carnumber,uid:userid },
  function(data){
    $("#"+userid + "_" + carnumber).html(data);
  });

}

function showstuff(b,id1,id2){

/*

$(document.body).click(function () {
      if ($("div:first").is(":hidden")) {
        $("div").slideDown("slow");
      } else {
        $("div").hide();
      }
    });
*/

if(b){
$("#"+id1).css("display","none");
$("#"+id2).css("display","block");
/*$("#"+id2).slideDown(3000,function(){
        $(this).css("border", "2px red inset")
               .filter(".middle")
                 .css("background", "yellow")
                 .focus();
	$("#"+id1).css("display","none");
      });
*/

} else {
$("#"+id1).css("display","block");
$("#"+id2).css("display","none");
}

}

function showonoff(id1,id2,words1,words2){

if($("#"+id1).css("display") == "none"){
$("#"+id1).css("display","block");
$("#"+id2).text(words2);
} else {
$("#"+id1).css("display","none");
$("#"+id2).text(words1);
}

}


function editdescript(iid,big){

if(big){
rows = 5;
cols = 50;
} else {
rows = 3;
cols = 30;
}


if($("#editid_"+iid).text() == "edit"){
$("#id_"+iid).html("<textarea rows='" + rows + "' cols='"+ cols +"'>"+ $("#id_"+iid).text() + "</textarea>");
$("#editid_"+iid).text("save");
} else {

updatedescript(iid,$("#id_"+iid).text());
$("#id_"+iid).html($("#id_"+iid).text());
$("#editid_"+iid).text("edit");
}

}

function updatedescript(iid,descript){

safety = new Array();

$.post("/ajax/imageupdate.php",{iid:iid,text:descript},function(data){
});


}


function getQueryString(name){ 
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )    return "";
  else    return results[1];
}
