/************************************************************************/
/* AllMyGuests: Professional PHP Guestbook Application                  */
/* ==================================================================== */
/*                                                                      */
/* Copyright (c) 2004 by voice of web                                   */
/*        http://www.php-resource.net                                   */
/* ==================================================================== */
/*                                                                      */
/* This file is part of the "AllMyPHP Project"!                         */
/* The "AllMyPHP Project" is part of voice of web.                      */
/* All rights reserved, see license for details!                        */
/*                                                                      */
/* ==================================================================== */
/*                                                                      */
/* Author: Voice of web <allmyphp@voice-of-web.de>                      */
/*                                                                      */
/* ==================================================================== */
/*                                                                      */
/* file          : ./template/{}/js/allmyphp.js                         */
/* version       : 0.5.0                                                */
/* project       : AllMyGuests                                          */
/* last modified : Jul 19, 2004                                         */
/*                                                                      */
/************************************************************************/


/******************************************************************************************************************************************
   AllMyPHP Image Window resizer
*/
function AMJ_windowresize()
{
	var width, Height;
	if (self.document.AMPImage.complete == true) 
	{
		width=self.document.AMPImage.width;
		Height=self.document.AMPImage.Height;
		self.resizeTo(width, Height);
		var count=0;
		while (count<600)
		{
			count=count+1;
		}
	} else {
		setTimeout("AMJ_windowresize()",300);
	}
}


/******************************************************************************************************************************************
   AllMyPHP JS password checker
*/
function checkPassword(form,field1,field2)
{
    // Gets the elements pointers
    if (the_form.name == 'addUserForm' || the_form.name == 'chgPassword') {
        var pswd_index = 1;
        var pswd1_name = 'pma_pw';
        var pswd2_name = 'pma_pw2';
    } else {
        pswd_index     = 2;
        pswd1_name     = 'new_pw';
        pswd2_name     = 'new_pw2';
    }

    // Validates
    if (the_form.elements['nopass'][pswd_index].checked) {
        if (the_form.elements[pswd1_name].value == '') {
            alert(jsPasswordEmpty);
            the_form.elements[pswd2_name].value = '';
            the_form.elements[pswd1_name].focus();
            return false;
        } else if (the_form.elements[pswd1_name].value != the_form.elements[pswd2_name].value) {
            alert(jsPasswordNotSame);
            the_form.elements[pswd1_name].value  = '';
            the_form.elements[pswd2_name].value = '';
            the_form.elements[pswd1_name].focus();
            return false;
        } // end if...else if
    } // end if

    return true;
} // end of the 'checkPassword()' function


/******************************************************************************************************************************************
   table linkhover changes
*/
function AMJ_linkhover(Object)	
{
	 Object.style.backgroundColor = '#EE9215';
}


/******************************************************************************************************************************************
   table linkout changes
*/
function AMJ_linknormal(Object)	
{
	Object.style.background='#514A73';
}


/******************************************************************************************************************************************
   form field style change onblur/focus
*/
function AMJ_setformstyle(form, field, style)
{
	if (eval("document."+form)) 
	{
		eval("document."+form+"."+field+".id = '"+style+"'");	
	}
}

/******************************************************************************************************************************************
   providing "words less" counter
*/
function AMJ_WordLimitCounter(field, countfield, limit) 
{
	WordLimitCounter=0;
	for (x=0;x<field.value.length;x++) 
	{
		if(field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")
		{
		WordLimitCounter++
		}
		if(WordLimitCounter > limit) 
		{
			field.value = field.value.substring(0, x);
		} else {
			countfield.value = limit - WordLimitCounter;
		}
	}
}


/******************************************************************************************************************************************
   providing "character less" counter
*/
function AMJ_CharacterLimitCounter(field, countfield, limit) 
{
	if(field.value.length > limit)
	{
		field.value = field.value.substring(0, limit);
	} else {
		countfield.value = limit - field.value.length;
	}
}
  
  
/******************************************************************************************************************************************
   set and show topic image
*/
function AMJ_settopicimage(Image) 
{
	document.AMG_signin.post_topicicon.value = Image;
	document.post_topicicon.src=Image;
}


/******************************************************************************************************************************************
   provides js popup ubb code generator
*/
function AMJ_setbbcode(code,requesttext,text)
{
	popup = prompt(requesttext+"\n["+code+"]xxx[/"+code+"]",text);
	
	if ((popup != null) && (popup != ""))
	{
		AddCode = "["+code+"]"+popup+"[/"+code+"] ";
	}
	if (AMG_signin.post_message.createTextRange && AMG_signin.post_message.caretPos) 
	{
		var caretPos = AMG_signin.post_message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? AddCode + ' ' : AddCode;
	} else {
		AMG_signin.post_message.value+=AddCode
	}
		
	AMG_signin.post_message.focus();
	//setfocus(AMG_signin);
}

/******************************************************************************************************************************************
   creates ubb hyperlink generator
*/

function AMJ_setlink(type)
{
	if (text) { var dtext=text; } else { var dtext=""; }
	linktext = prompt(link_text_prompt,dtext);
		var prompttext;
		if (thetype == "URL") {
			prompt_text = link_url_prompt;
			prompt_contents = "http://";
			}
		else {
			prompt_text = link_email_prompt;
			prompt_contents = "";
			}
	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != "")) {
			AddTxt = "["+thetype+"="+linkurl+"]"+linktext+"[/"+thetype+"] ";
			AddText(AddTxt,theform);

			}
		else{
			AddTxt = "["+thetype+"]"+linkurl+"[/"+thetype+"] ";
			AddText(AddTxt,theform);

		}
	}
}

/******************************************************************************************************************************************
   insert text
*/
function AMJ_insert(NewCode,theform) {
	if (theform.message.createTextRange && theform.message.caretPos) {
		var caretPos = theform.message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
	} else {
		theform.message.value+=NewCode
	}
	setfocus(theform);
	AddTxt = "";
}
