﻿//набор функций для вывода всплывающего окна "Request More Info"
//на страницах где выводится форма "Request More Info"
$( 
	function()
	{
		if( $( '.txtHighlighted' )[0] )
		{
			$( '#request-more-info' ).click();
		}
		
		if( $( '.txtInfo' )[0] )
		{
			showPopupCentered( 'request-more-info-success.aspx', 600, 520, { onLoad: OnRequestMoreInfoSuccessLoad } );;
		}
	}
)

function OnRequestMoreInfoLoad( $frame )
{
	//$( 'form', $frame[0].contentWindow.document ).prepend( $( '.txtHighlighted' )[0] );
	if( 
		( 
			$( '.txtHighlighted' )[0] 
			&& !$( '.txtHighlighted', $frame[0].contentWindow.document )[0] 
		) 
		&& !$( '.txtInfo', $frame[0].contentWindow.document )[0] 
	)
	{
		//$( 'form', $frame[0].contentWindow.document ).prepend( '<div class="txtHighlighted">123</div>' );
		//$( '.txtHighlighted', $frame[0].contentWindow.document )[0].html( $( '.txtHighlighted' )[0].html() );
		
		$( 'form', $frame[0].contentWindow.document ).prepend( '<div class="txtHighlighted">' + $( '.txtHighlighted' )[0].innerHTML + '</div>' );
		$( '.txtHighlighted' ).remove();
		//$( 'form', $frame[0].contentWindow.document ).prepend( $( '.txtHighlighted' )[0] );
		
		var inputCollection =  $( 'form input' );
		for( var i = 0; i < inputCollection.length; i++ )
		{
			if( inputCollection[i].type != 'hidden' )
			{
				var id = '#' + inputCollection[i].id;
				$( id, $frame[0].contentWindow.document ).val( $( id ).val() );
				
				$( id, $frame[0].contentWindow.document ).addClass( $( id ).attr( 'class' ) );
				$( id ).removeClass( 'errorclass' );
			}
		}
		
		$( '#comments', $frame[0].contentWindow.document ).val( $( '#comments' ).val() );
		//$( '#comments', $frame[0].contentWindow.document ).addClass( $( '#comments' ).attr( 'class' ) );
	}
	
	ResizePopupFrame( $frame );
} 

function OnRequestMoreInfoSuccessLoad( $frame )
{
	$( 'div.txtInfo', $frame[0].contentWindow.document ).html( $( '.txtInfo' )[0].innerHTML );
	
	ResizePopupFrame( $frame );
} 

function ResizePopupFrame( $frame )
{ 	
	var height = $( '#popupPage', $frame[0].contentWindow.document ).height() + 70;
	var width = $( '#popupPage', $frame[0].contentWindow.document ).width() + 60;
	
	$frame[0].height = height;
	$frame[0].width = width;
	$frame.css( 'left', window.parent.windowGeometry.getHorizontalScroll() + 
		( window.parent.windowGeometry.getViewportWidth() - width ) / 2 + 'px' );
	$frame.css( 'top', window.parent.windowGeometry.getVerticalScroll() + 
		( window.parent.windowGeometry.getViewportHeight() - height ) / 2 + 'px' );
} 

