var a;
var b;

function loads()
{
	turn_font();
	left();
	table();
	view_applied();
	check_payment();
}
function left()
{
	h1 = $('#left').height();
	h2 = $('#right').height();
	if(h1<h2)
		$('#left').height(h2);
	else
		$('#right').height(h1);		
	
	h1 = $('#sub_left').height();
	h2 = $('#sub_right').height();
	if(h1<h2)
		$('#sub_left').height(h2);
	else
		$('#sub_right').height(h1);	
	
	h1 = $('#sub_left1').height();
	h2 = $('#sub_right1').height();
	if(h1>h2)
		$('#sub_right1').height(h1);
	else
		$('#sub_left1').height(h2);
		
	h1 = $('#sub_left2').height();
	h2 = $('#sub_right2').height();
	if(h1<h2)
		$('#sub_left2').height(h2);
	else
		$('#sub_right2').height(h1);		
	

}
function view(url, w, h)
{
	l = ($(window).width()-w)/2;
	t = ($(window).height()-h)/2;
	
	window.open(url, '', 'width='+w+',height='+h+',top='+t+',left='+l+',scrollbars=yes');
}
function turn_font()
{
	a = $('h1');
	for(i=0; i<a.length; i++)
	{
		$(a[i]).replaceWith(turn_h1($(a[i]).html(), '100%', '42'));	
	}
	a = $('h2');
	for(i=0; i<a.length; i++)
	{
		$(a[i]).replaceWith(turn_h2($(a[i]).html(), '100%', '30'));	
	}
	a = $('h3');
	for(i=0; i<a.length; i++)
	{
		$(a[i]).replaceWith(turn_h3($(a[i]).html(), '100%', '26'));	
	}	
	
	a = $('.tt');
	for(i=0; i<a.length; i++)
	{
		$(a[i]).replaceWith(turn_h3($(a[i]).html(), '100%', '26'));	
	}	
}

function turn_h1(val, w, h)
{
	str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+ w +'" height="'+ h +'">';
	str += '<param name="movie" value="'+base_url+'templates/hiresl/flash/h1.swf" />';
	str += '<param name="quality" value="high" />';
	str += '<param name="wmode" value="transparent" />';
	str += '<param name="FlashVars" value="color=0xfa9641&size=18&t='+ val +'" />';
	str += '<embed src="'+base_url+'templates/hiresl/flash/h1.swf" wmode="transparent" FlashVars="color=0xfa9641&size=18&t='+ val +'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+ w +'" height="'+ h +'"></embed></object>';	
	return str;
}

function turn_h2(val, w, h)
{
	str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+ w +'" height="'+ h +'">';
	str += '<param name="movie" value="'+base_url+'templates/hiresl/flash/h1.swf" />';
	str += '<param name="quality" value="high" />';
	str += '<param name="wmode" value="transparent" />';
	str += '<param name="FlashVars" value="color=0x2f3192&size=15&t='+ val +'" />';
	str += '<embed src="'+base_url+'templates/hiresl/flash/h1.swf" wmode="transparent" FlashVars="color=0x2f3192&size=15&t='+ val +'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+ w +'" height="'+ h +'"></embed></object>';	
	return str;
}

function turn_h3(val, w, h)
{
	str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+ w +'" height="'+ h +'">';
	str += '<param name="movie" value="'+base_url+'templates/hiresl/flash/h1.swf" />';
	str += '<param name="quality" value="high" />';
	str += '<param name="wmode" value="transparent" />';
	str += '<param name="FlashVars" value="color=0x000000&size=13&t='+ val +'" />';
	str += '<embed src="'+base_url+'templates/hiresl/flash/h1.swf" wmode="transparent" FlashVars="color=0x000000&size=13&t='+ val +'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+ w +'" height="'+ h +'"></embed></object>';	
	return str;
}


function changeState(id, country, state)
{
	
	$.ajax({
	   type: "GET",
	   url:  base_url + "index.php/main/get_state/" + id + '/'+country + '/'+state,
	   success: function(msg){
		   $('#st').html(msg);
		   set_state('');
	   }
	});	
	
}
function StateInit(id, country, state)
{
	$.ajax({
	   type: "GET",
	   url:  base_url + "index.php/main/get_state/" + id + '/'+country+ '/'+state,
	   success: function(msg){
		   $('#st').html(msg);
	   }
	});	
}
function set_state(val)
{
	$('#state').val(val);	
}


function editor_height(val)
{
	if(val=='' || val== undefined) val = 'content';
	$("#addheight").click(function(){
								   
		height=$("#"+val+"___Frame").height()
		$("#"+val+"___Frame").height(height+100);
	});
	$("#subheight").click(function(){
		height=$("#"+val+"___Frame").height(); 
		if (height>250)
		$("#"+val+"___Frame").height(height-100);
		
	});	
}

function table()
{
	$('.preview td:even').addClass('td_right');
}


function suredo(url, str)
{
	if(str=='' || str == undefined) str = 'job';
	if(window.confirm('Do you sure that you want to delete this '+str+'?'))
	{
		location = url;	
	}
}

function view_applied()
{
	a = $('#lc').height();
	b = $('#sub_right1').height();
	
	$('.view_applied').click(function(){
		$('.hidden').css('display','none');
		$('.closed').css('display','none');
		$('.view_applied').css('display','block');
		$(this).css('display','none');
		$(this).next().css('display','block');
		$(this).parent().parent().next().children().children().slideDown('fast', function(){change_height()});
	
	});	
	$('.closed').click(function(){
		$(this).css('display','none');
		$(this).prev().css('display','block');	
		$(this).parent().parent().next().children().children().slideUp('fast', function(){change_height()});
		
	});
	
}

function change_height()
{
	
	c = $('#lc').height();
	d = c-a;
    $('#sub_right1').height(b+d);	
	$('#sub_left1').height(b+d);
}


function view_resume(url)
{
	a1 = ($(document).width()-800)/2;
	b1 = ($(document).height()-600)/2;
	window.open(url,'', 'width=800, height=600, top='+b1+',left='+a1+',scrollbars=yes,toolbar=no, menubar=no');
}

function remove_resume()
{
	$('.remove').click(function(){
		url =$(this).attr('rel');
		cd = $(this).parent().parent();	
		$.ajax({
		   type: "GET",
		   url: url,
		   success: function(msg){
				cd.remove();
		   }
		 });
		
	});
}

var t1 = 0;
var t2 = 0;
var t3 = 0;
var t4 = 0;
var t5 = 0;
var t6 = 0;
var ts = new Array(0,0,0,0,0,0,0,0,0);
function set_rotation(str, num, step, t)
{
	vNum = Math.random()
	vNum = Math.round(vNum*3)
	second = 4000 + vNum;
	if(num>0)
	{
		setInterval('movement('+str+', '+num+', '+step+', '+t+')', second);
	}
}

function movement(str, num, step, t)
{	
	ts[t]++;
	if(ts[t]>num) ts[t]=0;
	$(str).css('margin-top', -1*(ts[t]*step) + 'px');
	
	
	
}

function check_payment()
{
	$('.ct').click(function(){
		as = $(this).val();
		if(as=='credit')
		{
			$('#credit').css('display','block');
			$('#check').css('display','none');
			
		}else{
			$('#check').css('display','block');
			$('#credit').css('display','none');
			
		}
	});	
	
}

function set_price(obj, price, job)
{
	ca = parseFloat( $('#chargetotal').val(), 10);
	cb = parseFloat(price, 10);
	if($(obj).attr('checked')==true)
	{
		ca = ca + cb;
	}else{
		ca = ca-cb;
	}
	
	jc = $('.pr');
	ja = '';
	for(i=0; i<jc.length; i++)
	{
		if($(jc[i]).attr('checked')==true)
		{
			if(ja!='') ja += ',';
			ja += $(jc[i]).val();
		}
	}
	$('#chargetotal').val(ca.toFixed(2));
	$('#job').val(ja);
}