﻿<!--
/* Child Page Functions */
function ReturnAndClose(value, ParentObjId){
	window.opener.document.getElementById(ParentObjId).value = value;
	self.close();
}

/* Global Functions */
function CheckCombo(source, arguments){
	if ( arguments.Value == '0' )
		arguments.IsValid = false;
	else
		arguments.IsValid = true;
}

function findPosX(obj)
{
	var curleft = 0;
	
	if (obj.offsetParent)
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	else if (obj.x)
		curleft += obj.x;
		
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	
	if (obj.offsetParent)
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	else if (obj.y)
		curtop += obj.y;
		
	return curtop;
}

function OpenChildWindow(url, name, features){
	window.open(url,name,features);
}
/* *********************************************************************** */

/* All Grids */
var _oCheckBoxDelete = document.getElementsByName('DeleteId');

function SelectAllCheckBox(Checked){
	for ( var i = 0 ; i < _oCheckBoxDelete.length ; i++ ){
		( Checked && !_oCheckBoxDelete[i].disabled ) ? _oCheckBoxDelete[i].parentNode.parentNode.className = 'GridTDActive' : _oCheckBoxDelete[i].parentNode.parentNode.className = '';
		if ( !_oCheckBoxDelete[i].disabled )
			_oCheckBoxDelete[i].checked = Checked;
	}
}

function IsChecked(){
	var flag = false;
	
	for ( var i = 0 ; i < _oCheckBoxDelete.length ; i++ )
		if ( _oCheckBoxDelete[i].checked ){
			flag = true;
			break;
		}

	if ( flag )
		return flag;
	else{
		alert('!كاربر محترم موردي انتخاب نشده');
		return flag;
	}
}

function RowOver(rowObj, IsOver){
	if (IsOver && !_oCheckBoxDelete[rowObj.rowIndex - 1].checked)
			rowObj.className = 'GridTDHover';
	else if (!IsOver && !_oCheckBoxDelete[rowObj.rowIndex - 1].checked)
			rowObj.className = '';
}

function RowOverWithoutCheckBox(rowObj, IsOver){
	if (IsOver)
		rowObj.className = 'GridTDHover';
	else
		rowObj.className = '';
}

function SingleCheck(rowObj, Checked){
	if ( Checked )
		rowObj.className = 'GridTDActive';
	else
		rowObj.className = 'GridTDHover';
}
/* *********************************************************************** */

/* Registration */
function Registration_SwapPanel(WhichPanel){
	var submit = document.getElementById('btnSubmit');
	var next = document.getElementById('btnNext');
	var back = document.getElementById('btnBack');
	var signup = document.getElementById('trSignup');
	var subscription = document.getElementById('trSubscription');

	if ( WhichPanel == 1 ) // Signup
	{
		signup.style.display = 'block';
		subscription.style.display = 'none';
		
		next.style.display = 'inline';
		back.style.display = 'none';
		submit.style.display = 'none';
	}
	else if ( WhichPanel == 2 ) // Subscription
	{
		signup.style.display = 'none';
		subscription.style.display = 'block';
		
		next.style.display = 'none';
		back.style.display = 'inline';
		submit.style.display = 'inline';
	}
}

function ShowMenu(obj, menuId){
	var oDiv = document.getElementById(menuId);
	
	oDiv.style.padding = '4px';
	oDiv.style.position = 'absolute';
	oDiv.style.display = 'block';
	oDiv.style.backgroundColor = '#E3E3E3';
	oDiv.style.border = '1px solid #867A88';
	oDiv.style.left = obj.offsetLeft;
	oDiv.style.top  = parseInt(obj.offsetTop) + 131;
	oDiv.style.zIndex = '2';
	
	menu_timer = setTimeout('HideMenu(\'' + menuId + '\')', 2500);
}

function HideMenu(menuId)
{
	var oDiv = document.getElementById(menuId);

	oDiv.style.display = 'none';

	clearTimeout(menu_timer);
}
/* *********************************************************************** */

/* Phone Book */
function GetObject(id){
	return document.getElementById(id);
}

function CheckContact(obj, btnId){
	if ( CheckSelectedItems(obj) )
		GetObject(btnId).disabled = false;
}

function CheckExisting(){
	if ( CheckExistingContactsInGroup(GetObject('lstAllContacts'), GetObject('lstGroupContacts')) ){
		alert("كاربر محترم فرد يا افراد انتخابي تكراريست");
		return false;
	}
	else
		return true;
}

function CheckSelectedItems(obj){
	return ( obj.selectedIndex == -1 ) ? false : true ;
}

function CheckExistingContactsInGroup(sourceObject, targetObject){
	var flag = false;

	if ( targetObject.options.length == 0 )
		return flag;
	else
		for ( var i = 0 ; i < sourceObject.options.length ; i++ )
		{
			if ( sourceObject.options[i].selected )
				for ( var j = 0 ; j < targetObject.options.length ; j++ )
					if ( sourceObject.options[i].text == targetObject.options[j].text )
					{
						flag = true;
						break;
					}

			if ( flag )
				break;
		}

	return flag;
}
/* *********************************************************************** */

/* Product */
function Product_Description(IsShow, LayerId, CoordinateObjectId){
	var oDiv = GetObject(LayerId);
	var oCoordinate = GetObject(CoordinateObjectId);

	if ( IsShow )
	{
		oDiv.style.display = 'block';
		oDiv.style.left = findPosX(oCoordinate);
		oDiv.style.top = findPosY(oCoordinate) + 21;
	}
	else
		oDiv.style.display = 'none';
}

function Product_SelectElement(ItemGuids, ProductGuids, ProductValues, ProductTypes){
	// Convert String To Array Object
	var ItemGuids	= ItemGuids.split(",");
	var Guids		= ProductGuids.split(",");
	var Values		= ProductValues.split(",");
	var Types		= ProductTypes.split(",");

	var	ItemGuid, Guid, Value, Type;

	for ( var i = 0 ; i < ItemGuids.length ; i++ )
	{
		ItemGuid	= ItemGuids[i];
		Guid		= Guids[i];
		Value		= Values[i];
		Type		= Types[i];

		switch ( parseInt(Type) )
		{
			case 1: // RadioButton
				obj = document.getElementsByName(Type + '$' + ItemGuid);

				for ( var j = 0 ; j < obj.length ; j++ )
					if ( obj[j].value.toLowerCase() == Guid.toLowerCase() + '$' + Value )
					{
						obj[j].checked = true;
						break;
					}

				break;
			case 2: // Checkbox
				document.getElementById(Type + '$' + ItemGuid + '$' + Guid).checked = true;
				break;
			case 3: // Textbox
				document.getElementById(Type + '$' + ItemGuid + '$' + Guid).value = Value;
				break;
			case 4: // DropDown
				document.getElementById(Type + '$' + ItemGuid.toLowerCase()).options.value = Guid.toUpperCase() + '$' + Value;
				break;
		}
	}
}

function Product_CheckTextboxValue(){
	return ( event.keyCode == 32 ) ? false : isFinite(String.fromCharCode(event.keyCode));
}

function Product_FindPrice(obj){
	alert(obj.parentNode.parentNode.rowIndex);
}

function Factor_SelectAllCheckBox(Checked){
	for ( var i = 0 ; i < _oCheckBoxDelete.length ; i++ ){
		_oCheckBoxDelete[i].checked = Checked;
	}
}
/* *********************************************************************** */

/* eVote */
function Vote_Contact(IsShow, LayerId, CoordinateObjectId){
	var oDiv = GetObject(LayerId);
	var oCoordinate = GetObject(CoordinateObjectId);
	
	if ( IsShow )
	{
		oDiv.style.display = 'block';
		oDiv.style.left = findPosX(oCoordinate);
		oDiv.style.top = findPosY(oCoordinate) - 60;
	}
	else
		oDiv.style.display = 'none';
}
/* *********************************************************************** */

/* ReportSearch */
function ReportSearch_CheckValues(ElementId1, ElementId2) {
	var Pattern = "((13)[0-9]{2})[/](0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])";
	var obj_From = document.getElementById(ElementId1);
	var obj_To = document.getElementById(ElementId2);
	
	
	var IsError = false;
	MSG = '';
	
	if ( obj_From.value == '' ) {
		MSG += '                        از تاريخ الزاميست - \n';
		IsError = true;
	}
	else if ( !obj_From.value.match(Pattern) ) {
		MSG += 'از تاريخ به صورت صحيح وارد نشده - \n';
		IsError = true;
	}

	if ( obj_To.value == '' ) {
		MSG += '                        تا تاريخ الزاميست - \n';
		IsError = true;
	}
	else if ( !obj_To.value.match(Pattern) ) {
		MSG += 'تا تاريخ به صورت صحيح وارد نشده - \n';
		IsError = true;
	}

	if ( IsError ) {
		alert(MSG);
		return false;
	}
	else
		return true;
}
/* *********************************************************************** */

/* Invitation */
function Invitation_CheckValues(ElementId1, ElementId2) {
	var Pattern = '(((00[0-9]{2}9[1-2]{2})|(09[1-9]{2}))[0-9]{7})|(00[0-9]{11,13})';
	var obj_Mobile = document.getElementById(ElementId1);
	var obj_Name = document.getElementById(ElementId2);

	var IsError = false;
	var MSG = ': موارد زير الزاميست\n\n';
	
	if ( obj_Name.value == '' ) {
		MSG += '                      نام - \n';
		IsError = true;
	}

	if ( !obj_Mobile.value.match(Pattern) ) {
		MSG += '                 موبايل - \n';
		IsError = true;
	}

	if ( IsError ) {
		alert(MSG);
		return false;
	}
	else
		return true;
}
/* *********************************************************************** */

function POP3_OpenTesterWindow(server, port, username, password){
	if ( GetObject(server).value == '' || GetObject(port).value == '' || GetObject(username).value == '' || GetObject(password).value == '' ){
		alert('\t: موارد زير الزاميست\n\n- آدرس ايميل \n- رمز عبور ايميل \n- شماره پورت \n- نام سرور');
		return false;
	}
	else
		OpenChildWindow('ChildPage/POP3AccountTest.aspx' + POP3_ConnectionInfo(server, port, username, password), 'POP3AccountTest', 'width=300,height=150,left=100,top=100');
}

function POP3_ConnectionInfo(server, port, username, password){
	return '?init=' + GetObject(server).value + '$' + GetObject(port).value + '$' + GetObject(username).value + '$' + GetObject(password).value;
}
//-->