﻿/*******************************************************************************
 * Module: CommonScript.js Version 1.0
 *********************************
 * Copyright (c) 2004, Mario Krumov, All Rights Reserved.
 *
 * You may not use the code contained in this file without my express written
 * permission.
 * You may not redistribute, sell, or offer this file for download, in any form 
 * or on any medium, without my express written permission. This includes, but 
 * is not limited to, adding it to script archives or bundling and distributing
 * it with other scripts/software
 * You agree to retain the credits and copyright notice in the source code when
 * including it in your own pages. 
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHOR OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.  
 ******************************************************************************/

/* 
	Function: 	OpenWindow
	Arguments: 	theURL, W, H,  leftWindow, topWindow
	Open a new window
*/
//var HasNewWin;

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function OpenWindow(theURL, W, H,  leftWindow, topWindow, isScroll)
{ 
	var windowW = W;
	var windowH = H;

	var windowX = leftWindow;
	var windowY = topWindow;
	if ((windowX == null) || (windowX == '')) {
		var windowX = 200;
	}
	if ((windowY == null) || (windowY == '')) {
		var windowY = 80;
	}
	s = ",width="+W+",height="+H;
	
	//if ( ! HasNewWin )
	//{
		var NewWin = window.open(theURL, "ModalChild", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+isScroll+",left="+windowX+",top="+windowY+",resizable="+isScroll+""+s, true);
		NewWin.name = "NewWindow";
		NewWin.focus();
		//HasNewWin = true;
	//}
}

function EnableNewWin()
{
	alert(HasNewWin);
	HasNewWin = false;
}
function DisableNewWin()
{
	alert(HasNewWin);
	HasNewWin = true;
}
/* 
	Function: 	ClearSEField
	Arguments: 	textFieldName, dataFieldName
	clear search engine fileds
*/
function ClearSEField( textFieldName, dataFieldName )
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}		
	var theTextField = eval("theform." + textFieldName );
	theTextField.value = "";
	var theValueField = eval("theform." + dataFieldName );
	theValueField.value="";
}


/* 
	Function: 	myFormSubmit
	Arguments: 	
	Submit the form
*/
function myFormSubmit()
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	theform.submit();
}


/* 
	Function: 	myFormReset
	Arguments: 	
	Reset the form
*/
function myFormReset()
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	
	theform.reset();
}

/* 
	Function: 	DeleteConfirm
	Arguments: 	
	return true / false
*/
function DeleteConfirm()
	{
	if ( confirm('Записът ще бъде изтрит перманентно. \r\nСигурен ли си?') ) {
		return true;
	}
	else {
		return false;
	}
}
function DeleteDocConfirm()
	{
	if ( confirm('Документа ще бъде изтрит и няма да се показва в публичната част. \r\nСигурен ли си?') ) {
		return true;
	}
	else {
		return false;
	}
}
function ActivateConfirm()
	{
	if ( confirm('Записът ще се показва в публичната част. \r\nСигурен ли си?') ) {
		return true;
	}
	else {
		return false;
	}
}
function DisableConfirm()
	{
	if ( confirm('Записът няма да се показва в публичната част. \r\nСигурен ли си?') ) {
		return true;
	}
	else {
		return false;
	}
}
function DeletePictureConfirm()
	{
	if ( confirm('Снимката ще бъде изтрита перманентно от сървъра. \r\nСигурен ли си?') ) {
		return true;
	}
	else {
		return false;
	}
}
function DeaktivateDealerConfirm( dname )
	{
	if ( confirm('Дилър ' + dname + ' ще бъде деактивиран.\r\nВсички негови обяви ще бъдат деактивирани.\r\nСигурен ли си?') ) {
		return true;
	}
	else {
		return false;
	}
}
function ActivateDealerConfirm( dname )
	{
	if ( confirm('Дилър ' + dname + ' ще бъде активиран.\r\nВсички негови обяви ще бъдат активирани.\r\nСигурен ли си?') ) {
		return true;
	}
	else {
		return false;
	}
}

/* 
	Function: 	deleteSelectedItemsFromList
	Arguments: 	sourceList
*/
function deleteSelectedItemsFromList( sourceList ) 
{
	var maxCnt = sourceList.options.length;
	for(var i = maxCnt - 1; i >= 0; i--) 
	{
		if ((sourceList.options[i] != null) && (sourceList.options[i].selected == true)) 
		{
			sourceList.options[i] = null;
		}
	}
}
/* 
	Function: 	selectList
	Arguments: 	sourceList
*/
function selectList( sourceList ) 
{
	for(var i = 0; i < sourceList.options.length; i++) 
	{
		if (sourceList.options[i] != null)
			sourceList.options[i].selected = true;
	}
return true;
}

function selectItemfromList( sourceList, item ) 
{
	for(var i = 0; i < sourceList.options.length; i++) 
	{
		if (sourceList.options[i] != null && sourceList.options[i].value == item )
			sourceList.options[i].selected = true;
			break;
	}
return true;
}
/* 
	Function: 	addToList
	Arguments: 	sourceList
*/
function addToList( destinationList, itemText, itemValue ) 
{
	var found = false;
	//var destinationList = window.document.forms['MainForm'].CategoryFirm;
	var len = destinationList.length;	
	for(var count = 0; count < len; count++) 
	{
		if (destinationList.options[count] != null) 
		{
			if ( destinationList.options[count].value == itemValue ) 
			{
				found = true;
				break;
			}
		}
	}
	
	if ( found )
		return;	
	
	destinationList.options[len] = new Option( itemText, itemText + '^' + itemValue );
}

/* 
	Function: 	GetCtrlFullName
	Arguments: 	theobject, objectid
*/
function GetCtrlFullName( searchCtrl) 
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	
	try
	{
		for (i=0;i<theform.length;i++)
		{
			if ( theform[i].name.indexOf( searchCtrl ) != -1 )
			{
				return theform[i].id;
			}
		}
	}
	catch (e)
	{
		return "";
	}
}

/* 
	Function: 	myFormSetFocus
	Arguments: 	
	Set focus on the form element
*/
function myFormSetFocus( objid )
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	var theObject = eval("theform." + objid );
	if (theObject) theObject.SetFocus();
}



/* 
	Function: 	ParseCarHouseData
	Arguments: 	
	Set focus on the form element
*/
function ParseCarHouseData( objphone, objemail, strdata )
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	var theObjPhone = eval("theform." + GetCtrlFullName(objphone) );
	var theObjEmail = eval("theform." + GetCtrlFullName(objemail) );
	if ( strdata != "-3" )
	{
		if (theObjPhone) theObjPhone.value = strdata.split("#")[1]; 
		if (theObjEmail) theObjEmail.value = strdata.split("#")[2]; 
	}
	else
	{
		theObjPhone.value = '032-969363';
		theObjEmail.value = 'info@topmycar.com';
	}	
}

/* 
	Function: 	ClearDateField
	Arguments: 	dataFieldName
	clear date fileds
*/
function ClearDateField( dataFieldName )
	{
	
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}		

	for (i=0;i<theform.length;i++)
	{
		if ( theform[i].name.indexOf( dataFieldName ) != -1 )
		{
			theform[i].value = "";
		}
	}

}